Skip to content

Commit

Permalink
544137: NoClassDefFoundError: org/apache/http/client/fluent/Executor
Browse files Browse the repository at this point in the history
Isolate USSSDK initialization so it doesn't shut down all of MPC
- force early initialization
- handle initialization errors
- adapt UI in case of errors

Bug: 544137
Task-Url: https://bugs.eclipse.org/bugs/show_bug.cgi?id=544137
  • Loading branch information
creckord committed Feb 6, 2019
1 parent 85237f6 commit 031194d
Show file tree
Hide file tree
Showing 10 changed files with 64 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,9 @@ public IUserFavoritesService registerFavoritesService(String marketplaceBaseUrl,
IMarketplaceStorageService storageService = getStorageService(marketplaceBaseUrl);
if (storageService == null) {
storageService = registerStorageService(marketplaceBaseUrl, apiServerUrl, apiKey);
if (storageService == null) {
return null;
}
}
UserFavoritesService favoritesService = new UserFavoritesService();
favoritesService.bindStorageService(storageService);
Expand All @@ -232,19 +235,33 @@ public IUserFavoritesService registerFavoritesService(String marketplaceBaseUrl,

public IMarketplaceStorageService registerStorageService(String marketplaceBaseUrl, String apiServerUrl,
String apiKey) {
MarketplaceStorageService marketplaceStorageService = new MarketplaceStorageService();
ServiceRegistration<IMarketplaceStorageService> registration = null;
Hashtable<String, Object> config = new Hashtable<>();
config.put(IMarketplaceStorageService.STORAGE_SERVICE_URL_PROPERTY, apiServerUrl);
if (apiKey != null) {
config.put(IMarketplaceStorageService.APPLICATION_TOKEN_PROPERTY, apiKey);
}
ServiceRegistration<IMarketplaceStorageService> registration = registerService(marketplaceBaseUrl,
IMarketplaceStorageService.class, marketplaceStorageService, config);
BundleContext bundleContext = ServiceUtil.getBundleContext(registration);
if (bundleContext != null) {
marketplaceStorageService.activate(bundleContext, config);
try {
MarketplaceStorageService marketplaceStorageService = new MarketplaceStorageService();
registration = registerService(marketplaceBaseUrl,
IMarketplaceStorageService.class, marketplaceStorageService, config);
BundleContext bundleContext = ServiceUtil.getBundleContext(registration);
if (bundleContext != null) {
marketplaceStorageService.activate(bundleContext, config);
}
return marketplaceStorageService;
} catch (Exception | NoClassDefFoundError ex) {
MarketplaceClientCore.error("Userstorage API failed to initialize", ex);
unregisterService(registration);
return null;
}
}

private void unregisterService(ServiceRegistration<?> registration) {
if (registration != null) {
dynamicServiceRegistrations.remove(registration);
registration.unregister();
}
return marketplaceStorageService;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,7 @@ public void activate(BundleContext context, Map<?, ?> properties) {
if (marketplaceBaseUri != null) {
this.marketplaceBaseUri = marketplaceBaseUri.toString();
}
getStorage();//Force storage creation early to catch initialization errors
}

private IStorageService registerStorageService(URI serviceUri, String serviceName) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@ public Set<String> getLastFavoriteIds() {
@Override
public Set<String> getFavoriteIds(IProgressMonitor monitor)
throws NoServiceException, NotAuthorizedException, IllegalStateException, IOException {
// throw new IOException("simulates favorites failure");
SubMonitor progress = SubMonitor.convert(monitor, Messages.DefaultMarketplaceService_FavoritesRetrieve, 1000);
try {
String favoritesData = getFavoritesBlob().getContentsUTF();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

public class ImportFavoritesActionLink extends ActionLink {

private static final String IMPORT_ACTION_ID = "import"; //$NON-NLS-1$
public static final String IMPORT_ACTION_ID = "import"; //$NON-NLS-1$

private final MarketplacePage marketplacePage;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ public void performImport() {
}
final IUserFavoritesService userFavoritesService = findUserFavoritesService();
if (userFavoritesService == null) {
return;
throw new UnsupportedOperationException();
}
final List<INode> importNodes = new ArrayList<>();
for (MarketplaceNodeCatalogItem item : importFavorites) {
Expand Down Expand Up @@ -193,6 +193,9 @@ private IUserFavoritesService findUserFavoritesService() {
if (strategy instanceof FavoritesDiscoveryStrategy) {
FavoritesDiscoveryStrategy favoritesStrategy = (FavoritesDiscoveryStrategy) strategy;
userFavoritesService = favoritesStrategy.getMarketplaceService().getUserFavoritesService();
if (userFavoritesService != null) {
break;
}
}
}
return userFavoritesService;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -649,7 +649,7 @@ private void createMarketplaceSwitcher(Composite parent) {

final CatalogSwitcher switcher = new CatalogSwitcher(composite,
MarketplaceClientUi.useNativeBorders() ? SWT.BORDER : SWT.None,
configuration);
configuration);
switcher.addSelectionChangedListener(event -> {
CatalogDescriptor descriptor = (CatalogDescriptor) ((IStructuredSelection) event.getSelection())
.getFirstElement();
Expand Down Expand Up @@ -891,44 +891,41 @@ private void updateBranding() {
boolean hasTab = branding.hasSearchTab();
searchTabItem = updateTab(searchTabItem, ContentType.SEARCH, WIDGET_ID_TAB_SEARCH, branding.getSearchTabName(),
hasTab,
oldBranding.hasSearchTab(),
tabIndex);
if (hasTab) {
tabIndex++;
}
hasTab = hasFeaturedMarketTab(branding);
featuredMarketTabItem = updateTab(featuredMarketTabItem, ContentType.SEARCH, WIDGET_ID_TAB_FEATURED_MARKET,
branding.getFeaturedMarketTabName(), hasTab, hasFeaturedMarketTab(oldBranding), tabIndex);
featuredMarketTabItem = updateTab(featuredMarketTabItem, ContentType.FEATURED_MARKET,
WIDGET_ID_TAB_FEATURED_MARKET,
branding.getFeaturedMarketTabName(), hasTab, tabIndex);
if (hasTab) {
tabIndex++;
}
hasTab = branding.hasRecentTab();
recentTabItem = updateTab(recentTabItem, ContentType.SEARCH, WIDGET_ID_TAB_RECENT, branding.getRecentTabName(),
recentTabItem = updateTab(recentTabItem, ContentType.RECENT, WIDGET_ID_TAB_RECENT, branding.getRecentTabName(),
hasTab,
oldBranding.hasRecentTab(),
tabIndex);
if (hasTab) {
tabIndex++;
}
hasTab = branding.hasPopularTab();
popularTabItem = updateTab(popularTabItem, ContentType.SEARCH, WIDGET_ID_TAB_POPULAR,
popularTabItem = updateTab(popularTabItem, ContentType.POPULAR, WIDGET_ID_TAB_POPULAR,
branding.getPopularTabName(), hasTab,
oldBranding.hasPopularTab(),
tabIndex);
if (hasTab) {
tabIndex++;
}
hasTab = branding.hasRelatedTab();
relatedTabItem = updateTab(relatedTabItem, ContentType.SEARCH, WIDGET_ID_TAB_RELATED,
relatedTabItem = updateTab(relatedTabItem, ContentType.RELATED, WIDGET_ID_TAB_RELATED,
branding.getRelatedTabName(), hasTab,
oldBranding.hasRelatedTab(), tabIndex);
tabIndex);
if (hasTab) {
tabIndex++;
}
hasTab = hasFavoritedTab(branding);
favoritedTabItem = updateTab(favoritedTabItem, ContentType.SEARCH, WIDGET_ID_TAB_FAVORITES,
getFavoritedTabName(branding), hasTab, hasFavoritedTab(oldBranding),
tabIndex);
favoritedTabItem = updateTab(favoritedTabItem, ContentType.FAVORITES, WIDGET_ID_TAB_FAVORITES,
getFavoritedTabName(branding), hasTab, tabIndex);
if (hasTab) {
tabIndex++;
}
Expand Down Expand Up @@ -974,6 +971,10 @@ private boolean hasFavoritedTab(ICatalogBranding branding) {
if (branding.hasFavoritesTab()) {
return true;
}
return hasFavoritesService();
}

private boolean hasFavoritesService() {
CatalogDescriptor catalogDescriptor = this.configuration.getCatalogDescriptor();
if (catalogDescriptor == null) {
return false;
Expand Down Expand Up @@ -1008,16 +1009,16 @@ private boolean hasFeaturedMarketTab(ICatalogBranding branding) {
}

private CTabItem updateTab(CTabItem tabItem, ContentType contentType, String widgetId, String tabLabel,
boolean hasTab, boolean hadTab,
int tabIndex) {
boolean hasTab, int tabIndex) {
if (hasTab) {
if (!hadTab) {
if (tabItem == null || tabItem.isDisposed() || getContentType(tabItem) != contentType) {
tabItem = createCatalogTab(tabIndex, contentType, widgetId, tabLabel);
} else {
tabItem.setText(tabLabel);
}
} else if (tabItem != null && !tabItem.isDisposed()) {
tabItem.dispose();
tabItem = null;
}
return tabItem;
}
Expand Down Expand Up @@ -1144,6 +1145,10 @@ protected void initialize(WizardState initialState) {
}
}

protected ActionLink getActionLink(String actionId) {
return actions.get(actionId);
}

protected void addActionLink(int pos, ActionLink actionLink) {
doAddActionLink(pos, actionLink);
updateContentListLinks();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -472,6 +472,11 @@ private ControlListItem<?> createUserActionViewerItem(UserActionCatalogItem cata
return new UserFavoritesFindFavoritesActionItem(parent, getResources(), catalogItem,
getWizard().getCatalogPage());
case FAVORITES_UNSUPPORTED:
MarketplacePage catalogPage = getWizard().getCatalogPage();
ActionLink actionLink = catalogPage.getActionLink(ImportFavoritesActionLink.IMPORT_ACTION_ID);
if (actionLink != null) {
catalogPage.removeActionLink(actionLink);
}
return new UserFavoritesUnsupportedActionItem(parent, getResources(), catalogItem,
getWizard().getCatalogPage());
case LOGIN:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,8 @@ class Messages extends NLS {

public static String RetryErrorActionItem_errorDetailsDialogTitle;

public static String RetryErrorActionItem_failedToLoadLabel;

public static String RetryErrorActionItem_failedToLoadMessage;

public static String RetryErrorActionItem_retryActionLabel;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ private IStatus getError() {

@Override
protected String getNameLabelText() {
return Messages.UserFavoritesUnsupportedActionItem_unsupportedFavoritesLabel;
return Messages.RetryErrorActionItem_failedToLoadLabel;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,8 @@ RatingTooltip_Continue=Continue >
RatingTooltip_Dont_show_again=Don't show again
RatingTooltip_Note=Note: This will take you to the marketplace website, where you can change your vote after logging in.
RetryErrorActionItem_errorDetailsDialogTitle=Error details
RetryErrorActionItem_failedToLoadMessage=Failed to load contents: {0}
RetryErrorActionItem_failedToLoadLabel=Failed to load user favorites.
RetryErrorActionItem_failedToLoadMessage=An error occured while loading user favorites: {0}
RetryErrorActionItem_retryActionLabel=Retry
RetryErrorActionItem_retryTooltip=Try loading this tab's contents again
RetryErrorActionItem_showDetailsActionLabel=Show details
Expand Down Expand Up @@ -189,7 +190,7 @@ UserFavoritesSignInActionItem_SignInDescription=Please sign in with your eclipse
UserFavoritesSignInActionItem_subline=Meanwhile, check out some popular solutions below.
SignInUserActionItem_signInActionLabel=Sign in to view your favorites
SignInUserActionItem_retryLoginLabel=Sign in failed: {0} - Please retry.
UserFavoritesUnsupportedActionItem_Body=This marketplace does not support favorite entries.
UserFavoritesUnsupportedActionItem_Body=Sorry, this marketplace does not support personal favorite entries.
UserFavoritesUnsupportedActionItem_GoBackButtonLabel=Go back
UserFavoritesUnsupportedActionItem_Subline=Go back, or check out some popular solutions below.
UserFavoritesUnsupportedActionItem_unsupportedFavoritesLabel=Favorites are not supported on this Marketplace.
UserFavoritesUnsupportedActionItem_unsupportedFavoritesLabel=Personal favorites not supported.

0 comments on commit 031194d

Please sign in to comment.