Search in sources :

Example 1 with IMarketplaceService

use of org.eclipse.epp.mpc.core.service.IMarketplaceService in project epp.mpc by eclipse.

the class SelectionModelStateSerializerTest method setUp.

@Before
public void setUp() throws Exception {
    CatalogDescriptor catalogDescriptor = new CatalogDescriptor(new URL("http://marketplace.eclipse.org"), "Eclipse.org Marketplace");
    discoveryStrategy = new MarketplaceDiscoveryStrategy(catalogDescriptor) {

        @Override
        public IMarketplaceService createMarketplaceService() {
            DefaultMarketplaceService marketplaceService = new DefaultMarketplaceService(catalogDescriptor.getUrl());
            Map<String, String> requestMetaParameters = ServiceLocator.computeDefaultRequestMetaParameters();
            marketplaceService.setRequestMetaParameters(requestMetaParameters);
            return marketplaceService;
        }
    };
    catalog = new MarketplaceCatalog();
    catalog.getDiscoveryStrategies().add(discoveryStrategy);
    selectionModel = new SelectionModel(new InstallProfile() {

        public Set<String> getInstalledFeatures() {
            return Collections.emptySet();
        }
    });
}
Also used : MarketplaceDiscoveryStrategy(org.eclipse.epp.internal.mpc.ui.catalog.MarketplaceDiscoveryStrategy) DefaultMarketplaceService(org.eclipse.epp.internal.mpc.core.service.DefaultMarketplaceService) SelectionModel(org.eclipse.epp.internal.mpc.ui.wizards.SelectionModel) MarketplaceCatalog(org.eclipse.epp.internal.mpc.ui.catalog.MarketplaceCatalog) IMarketplaceService(org.eclipse.epp.mpc.core.service.IMarketplaceService) InstallProfile(org.eclipse.epp.internal.mpc.ui.wizards.InstallProfile) Map(java.util.Map) URL(java.net.URL) CatalogDescriptor(org.eclipse.epp.mpc.ui.CatalogDescriptor) Before(org.junit.Before)

Example 2 with IMarketplaceService

use of org.eclipse.epp.mpc.core.service.IMarketplaceService in project epp.mpc by eclipse.

the class DefaultMarketplaceService method resolveFavoriteNodes.

private ISearchResult resolveFavoriteNodes(final List<INode> nodes, IProgressMonitor monitor, boolean filterIncompatible) throws CoreException {
    IMarketplaceService resolveService = this;
    IMarketplaceService registeredService = ServiceHelper.getMarketplaceServiceLocator().getMarketplaceService(this.getBaseUrl().toString());
    if (registeredService instanceof CachingMarketplaceService) {
        CachingMarketplaceService cachingService = (CachingMarketplaceService) registeredService;
        if (cachingService.getDelegate() == this) {
            resolveService = cachingService;
        }
    }
    final List<INode> resolvedNodes = resolveService.getNodes(nodes, monitor);
    for (ListIterator<INode> i = resolvedNodes.listIterator(); i.hasNext(); ) {
        INode resolved = i.next();
        ((Node) resolved).setUserFavorite(true);
        if (filterIncompatible && !isInstallable(resolved)) {
            i.remove();
        }
    }
    if (!filterIncompatible) {
        // sort the node list so uninstallable nodes come last
        Collections.sort(resolvedNodes, new Comparator<INode>() {

            public int compare(INode n1, INode n2) {
                if (n1 == n2) {
                    return 0;
                }
                boolean n1Installable = isInstallable(n1);
                boolean n2Installable = isInstallable(n2);
                if (n1Installable == n2Installable) {
                    return 0;
                }
                if (n1Installable) {
                    // && !n2Installable
                    return -1;
                }
                // !n1Installable && n2Installable
                return 1;
            }
        });
    }
    return new ISearchResult() {

        public List<? extends INode> getNodes() {
            return resolvedNodes;
        }

        public Integer getMatchCount() {
            return resolvedNodes.size();
        }
    };
}
Also used : INode(org.eclipse.epp.mpc.core.model.INode) ISearchResult(org.eclipse.epp.mpc.core.model.ISearchResult) Node(org.eclipse.epp.internal.mpc.core.model.Node) INode(org.eclipse.epp.mpc.core.model.INode) IMarketplaceService(org.eclipse.epp.mpc.core.service.IMarketplaceService)

Example 3 with IMarketplaceService

use of org.eclipse.epp.mpc.core.service.IMarketplaceService in project epp.mpc by eclipse.

the class ServiceLocator method getMarketplaceService.

public synchronized IMarketplaceService getMarketplaceService(String baseUrl) {
    IMarketplaceService service = getService(marketplaceServiceTracker, baseUrl);
    if (service != null) {
        return service;
    }
    service = createMarketplaceService(baseUrl);
    registerService(baseUrl, IMarketplaceService.class, service);
    return service;
}
Also used : IMarketplaceService(org.eclipse.epp.mpc.core.service.IMarketplaceService)

Example 4 with IMarketplaceService

use of org.eclipse.epp.mpc.core.service.IMarketplaceService in project epp.mpc by eclipse.

the class ServiceLocator method createMarketplaceService.

protected IMarketplaceService createMarketplaceService(String baseUrl) {
    IMarketplaceService service;
    URL base;
    try {
        base = URLUtil.toURL(baseUrl);
    } catch (MalformedURLException e) {
        throw new IllegalArgumentException(e);
    }
    DefaultMarketplaceService defaultService = new DefaultMarketplaceService(base);
    Map<String, String> requestMetaParameters = computeDefaultRequestMetaParameters();
    defaultService.setRequestMetaParameters(requestMetaParameters);
    IUserFavoritesService favoritesService = getFavoritesService(baseUrl);
    // FIXME this should be a service reference!
    defaultService.setUserFavoritesService(favoritesService);
    service = new CachingMarketplaceService(defaultService);
    return service;
}
Also used : MalformedURLException(java.net.MalformedURLException) CachingMarketplaceService(org.eclipse.epp.internal.mpc.core.service.CachingMarketplaceService) DefaultMarketplaceService(org.eclipse.epp.internal.mpc.core.service.DefaultMarketplaceService) IUserFavoritesService(org.eclipse.epp.mpc.core.service.IUserFavoritesService) IMarketplaceService(org.eclipse.epp.mpc.core.service.IMarketplaceService) URL(java.net.URL)

Example 5 with IMarketplaceService

use of org.eclipse.epp.mpc.core.service.IMarketplaceService 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)

Aggregations

IMarketplaceService (org.eclipse.epp.mpc.core.service.IMarketplaceService)11 URL (java.net.URL)5 DefaultMarketplaceService (org.eclipse.epp.internal.mpc.core.service.DefaultMarketplaceService)3 INode (org.eclipse.epp.mpc.core.model.INode)3 CoreException (org.eclipse.core.runtime.CoreException)2 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)2 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)2 Node (org.eclipse.epp.internal.mpc.core.model.Node)2 MarketplaceDiscoveryStrategy (org.eclipse.epp.internal.mpc.ui.catalog.MarketplaceDiscoveryStrategy)2 ISearchResult (org.eclipse.epp.mpc.core.model.ISearchResult)2 IMarketplaceServiceLocator (org.eclipse.epp.mpc.core.service.IMarketplaceServiceLocator)2 IUserFavoritesService (org.eclipse.epp.mpc.core.service.IUserFavoritesService)2 BundleContext (org.osgi.framework.BundleContext)2 MalformedURLException (java.net.MalformedURLException)1 Map (java.util.Map)1 IStatus (org.eclipse.core.runtime.IStatus)1 Status (org.eclipse.core.runtime.Status)1 Job (org.eclipse.core.runtime.jobs.Job)1 CachingMarketplaceService (org.eclipse.epp.internal.mpc.core.service.CachingMarketplaceService)1 UserFavoritesService (org.eclipse.epp.internal.mpc.core.service.UserFavoritesService)1