use of org.eclipse.epp.mpc.core.service.ICatalogService in project epp.mpc by eclipse.
the class UserFavoritesServiceTest method initServices.
@BeforeClass
public static void initServices() throws CoreException {
assureService();
ICatalogService catalogService = ServiceHelper.getMarketplaceServiceLocator().getCatalogService();
catalogService.listCatalogs(new NullProgressMonitor());
}
use of org.eclipse.epp.mpc.core.service.ICatalogService in project epp.mpc by eclipse.
the class AbstractMarketplaceWizardCommand method installRemoteCatalogs.
public IStatus installRemoteCatalogs() {
try {
final AtomicReference<List<? extends ICatalog>> result = new AtomicReference<List<? extends ICatalog>>();
PlatformUI.getWorkbench().getProgressService().busyCursorWhile(new IRunnableWithProgress() {
public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
try {
ICatalogService catalogService = ServiceHelper.getMarketplaceServiceLocator().getCatalogService();
final List<? extends ICatalog> catalogs = catalogService.listCatalogs(monitor);
result.set(catalogs);
} catch (CoreException e) {
if (e.getStatus().getSeverity() == IStatus.CANCEL) {
throw new InterruptedException();
}
throw new InvocationTargetException(e);
}
}
});
List<? extends ICatalog> catalogs = result.get();
for (ICatalog catalog : catalogs) {
ResourceProvider resourceProvider = MarketplaceClientUiPlugin.getInstance().getResourceProvider();
String catalogName = catalog.getName();
String requestSource = NLS.bind(Messages.MarketplaceWizardCommand_requestCatalog, catalogName, catalog.getId());
String catalogImageUrl = catalog.getImageUrl();
if (catalogImageUrl != null) {
try {
resourceProvider.retrieveResource(requestSource, catalogImageUrl);
} catch (Exception e) {
MarketplaceClientUi.log(IStatus.WARNING, Messages.MarketplaceWizardCommand_FailedRetrievingCatalogImage, catalogName, catalogImageUrl, e);
}
}
if (catalog.getBranding() != null && catalog.getBranding().getWizardIcon() != null) {
String wizardIconUrl = catalog.getBranding().getWizardIcon();
try {
resourceProvider.retrieveResource(requestSource, wizardIconUrl);
} catch (Exception e) {
MarketplaceClientUi.log(IStatus.WARNING, Messages.MarketplaceWizardCommand_FailedRetrievingCatalogWizardIcon, catalogName, wizardIconUrl, e);
}
}
CatalogDescriptor descriptor = new CatalogDescriptor(catalog);
registerOrOverrideCatalog(descriptor);
}
} catch (InterruptedException ie) {
if (ie.getMessage() == null || "".equals(ie.getMessage())) {
InterruptedException ie1 = new InterruptedException("Operation cancelled");
ie1.setStackTrace(ie.getStackTrace());
if (ie.getCause() != null) {
ie1.initCause(ie.getCause());
}
ie = ie1;
}
IStatus errorStatus = MarketplaceClientCore.computeStatus(ie, Messages.MarketplaceWizardCommand_CannotInstallRemoteLocations);
return new Status(IStatus.CANCEL, MarketplaceClientCore.BUNDLE_ID, errorStatus.getMessage(), ie);
} catch (Exception e) {
IStatus status = MarketplaceClientCore.computeStatus(e, Messages.MarketplaceWizardCommand_CannotInstallRemoteLocations);
return status;
}
return Status.OK_STATUS;
}
use of org.eclipse.epp.mpc.core.service.ICatalogService in project epp.mpc by eclipse.
the class ServiceLocator method activate.
/**
* OSGi service activation method. Activation will cause the locator to start managing individual marketplace
* services and return the same instances per base url on subsequent calls to {@link #getMarketplaceService(String)}
* .
*/
public synchronized void activate(BundleContext context, Map<?, ?> properties) {
URL baseUrl = ServiceUtil.getUrl(properties, DEFAULT_URL, null);
URL catalogUrl = ServiceUtil.getUrl(properties, CATALOG_URL, baseUrl);
if (catalogUrl != null) {
this.defaultCatalogUrl = catalogUrl;
}
// else the default value from the constructor is used
URL marketplaceUrl = ServiceUtil.getUrl(properties, DEFAULT_MARKETPLACE_URL, baseUrl);
if (marketplaceUrl != null) {
this.defaultMarketplaceUrl = marketplaceUrl;
}
// else the default value from the constructor is used
marketplaceServiceTracker = new ServiceTracker<IMarketplaceService, IMarketplaceService>(context, IMarketplaceService.class, null);
marketplaceServiceTracker.open(true);
catalogServiceTracker = new ServiceTracker<ICatalogService, ICatalogService>(context, ICatalogService.class, null);
catalogServiceTracker.open(true);
storageServiceTracker = new ServiceTracker<IMarketplaceStorageService, IMarketplaceStorageService>(context, IMarketplaceStorageService.class, new ServiceTrackerCustomizer<IMarketplaceStorageService, IMarketplaceStorageService>() {
public IMarketplaceStorageService addingService(ServiceReference<IMarketplaceStorageService> reference) {
IMarketplaceStorageService service = storageServiceTracker.addingService(reference);
Object marketplaceUrl = ServiceUtil.getOverridablePropertyValue(reference, IMarketplaceService.BASE_URL);
if (marketplaceUrl != null && service != null) {
bindToUserFavoritesServices(marketplaceUrl.toString(), reference);
}
return service;
}
public void modifiedService(ServiceReference<IMarketplaceStorageService> reference, IMarketplaceStorageService service) {
Object marketplaceUrl = ServiceUtil.getOverridablePropertyValue(reference, IMarketplaceService.BASE_URL);
if (marketplaceUrl != null) {
rebindToUserFavoritesServices(marketplaceUrl.toString(), reference, service);
} else {
unbindFromUserFavoritesServices(reference, service);
}
}
public void removedService(ServiceReference<IMarketplaceStorageService> reference, IMarketplaceStorageService service) {
unbindFromUserFavoritesServices(reference, service);
}
});
storageServiceTracker.open(true);
favoritesServiceTracker = new ServiceTracker<IUserFavoritesService, IUserFavoritesService>(context, IUserFavoritesService.class, new ServiceTrackerCustomizer<IUserFavoritesService, IUserFavoritesService>() {
public IUserFavoritesService addingService(ServiceReference<IUserFavoritesService> reference) {
return ServiceUtil.getService(reference);
}
public void modifiedService(ServiceReference<IUserFavoritesService> reference, IUserFavoritesService service) {
if (!(service instanceof UserFavoritesService)) {
return;
}
ServiceReference<?> storageServiceBinding = (ServiceReference<?>) reference.getProperty(STORAGE_SERVICE_BINDING_ID);
if (storageServiceBinding != null && service.getStorageService() == null) {
((UserFavoritesService) service).bindStorageService((IMarketplaceStorageService) ServiceUtil.getService(storageServiceBinding));
} else if (service.getStorageService() != null && getDynamicServiceInstance(reference) != null) {
((UserFavoritesService) service).setStorageService(null);
}
}
public void removedService(ServiceReference<IUserFavoritesService> reference, IUserFavoritesService service) {
// ignore
}
});
favoritesServiceTracker.open(true);
}
use of org.eclipse.epp.mpc.core.service.ICatalogService in project epp.mpc by eclipse.
the class ServiceLocator method getCatalogService.
public synchronized ICatalogService getCatalogService() {
if (catalogServiceTracker != null) {
ICatalogService registeredService = catalogServiceTracker.getService();
if (registeredService != null) {
// we don't cache this on our own, since it might become invalid
return registeredService;
}
}
if (catalogService != null) {
return catalogService;
}
ICatalogService catalogService = new DefaultCatalogService(defaultCatalogUrl);
registerService(null, ICatalogService.class, catalogService);
return catalogService;
}
use of org.eclipse.epp.mpc.core.service.ICatalogService in project epp.mpc by eclipse.
the class MarketplaceClientUiTest method testOfflineCatalogServiceErrors.
@Test
public void testOfflineCatalogServiceErrors() throws Exception {
// since NoRouteToHost and ConnectExceptions are hard to fake and happen at pretty much the same place,
// we only simulate the UnknownHostException case here (by actually using an invalid host address)
final DefaultCatalogService catalogService = (DefaultCatalogService) ServiceLocator.getInstance().getCatalogService();
catalogService.setBaseUrl(new URL(UNREACHABLE_MARKETPLACE_URL));
try {
ServiceLocator.setInstance(new ServiceLocator() {
@Override
public ICatalogService getCatalogService() {
return catalogService;
}
});
IStatus status = new MarketplaceWizardCommand().installRemoteCatalogs();
assertEquals(IStatus.ERROR, status.getSeverity());
assertTrue(status.getMessage().contains(": " + OFFLINE_HINT_TEXT));
} finally {
ServiceLocator.setInstance(new ServiceLocator());
}
}
Aggregations