Search in sources :

Example 1 with ICatalogService

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());
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) ICatalogService(org.eclipse.epp.mpc.core.service.ICatalogService) BeforeClass(org.junit.BeforeClass)

Example 2 with ICatalogService

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;
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) Status(org.eclipse.core.runtime.Status) IStatus(org.eclipse.core.runtime.IStatus) ICatalogService(org.eclipse.epp.mpc.core.service.ICatalogService) AtomicReference(java.util.concurrent.atomic.AtomicReference) InvocationTargetException(java.lang.reflect.InvocationTargetException) CoreException(org.eclipse.core.runtime.CoreException) ExecutionException(org.eclipse.core.commands.ExecutionException) InvocationTargetException(java.lang.reflect.InvocationTargetException) IRunnableWithProgress(org.eclipse.jface.operation.IRunnableWithProgress) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) CoreException(org.eclipse.core.runtime.CoreException) ResourceProvider(org.eclipse.epp.internal.mpc.ui.catalog.ResourceProvider) List(java.util.List) ICatalog(org.eclipse.epp.mpc.core.model.ICatalog) CatalogDescriptor(org.eclipse.epp.mpc.ui.CatalogDescriptor)

Example 3 with ICatalogService

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);
}
Also used : ICatalogService(org.eclipse.epp.mpc.core.service.ICatalogService) ServiceTrackerCustomizer(org.osgi.util.tracker.ServiceTrackerCustomizer) IUserFavoritesService(org.eclipse.epp.mpc.core.service.IUserFavoritesService) URL(java.net.URL) ServiceReference(org.osgi.framework.ServiceReference) UserFavoritesService(org.eclipse.epp.internal.mpc.core.service.UserFavoritesService) IUserFavoritesService(org.eclipse.epp.mpc.core.service.IUserFavoritesService) IMarketplaceService(org.eclipse.epp.mpc.core.service.IMarketplaceService) IMarketplaceStorageService(org.eclipse.epp.mpc.core.service.IMarketplaceStorageService)

Example 4 with ICatalogService

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;
}
Also used : ICatalogService(org.eclipse.epp.mpc.core.service.ICatalogService) DefaultCatalogService(org.eclipse.epp.internal.mpc.core.service.DefaultCatalogService)

Example 5 with ICatalogService

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());
    }
}
Also used : ServiceLocator(org.eclipse.epp.internal.mpc.core.ServiceLocator) IStatus(org.eclipse.core.runtime.IStatus) ICatalogService(org.eclipse.epp.mpc.core.service.ICatalogService) DefaultCatalogService(org.eclipse.epp.internal.mpc.core.service.DefaultCatalogService) URL(java.net.URL) MarketplaceWizardCommand(org.eclipse.epp.internal.mpc.ui.commands.MarketplaceWizardCommand) Test(org.junit.Test)

Aggregations

ICatalogService (org.eclipse.epp.mpc.core.service.ICatalogService)5 URL (java.net.URL)2 IStatus (org.eclipse.core.runtime.IStatus)2 DefaultCatalogService (org.eclipse.epp.internal.mpc.core.service.DefaultCatalogService)2 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 List (java.util.List)1 AtomicReference (java.util.concurrent.atomic.AtomicReference)1 ExecutionException (org.eclipse.core.commands.ExecutionException)1 CoreException (org.eclipse.core.runtime.CoreException)1 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)1 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)1 Status (org.eclipse.core.runtime.Status)1 ServiceLocator (org.eclipse.epp.internal.mpc.core.ServiceLocator)1 UserFavoritesService (org.eclipse.epp.internal.mpc.core.service.UserFavoritesService)1 ResourceProvider (org.eclipse.epp.internal.mpc.ui.catalog.ResourceProvider)1 MarketplaceWizardCommand (org.eclipse.epp.internal.mpc.ui.commands.MarketplaceWizardCommand)1 ICatalog (org.eclipse.epp.mpc.core.model.ICatalog)1 IMarketplaceService (org.eclipse.epp.mpc.core.service.IMarketplaceService)1 IMarketplaceStorageService (org.eclipse.epp.mpc.core.service.IMarketplaceStorageService)1 IUserFavoritesService (org.eclipse.epp.mpc.core.service.IUserFavoritesService)1