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();
}
});
}
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();
}
};
}
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;
}
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;
}
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);
}
Aggregations