use of org.eclipse.epp.mpc.core.model.INode in project epp.mpc by eclipse.
the class MarketplaceCatalog method checkForUpdates.
protected IStatus checkForUpdates(List<MarketplaceNodeCatalogItem> updateCheckNeeded, final Map<String, IInstallableUnit> installedIUs, final IProgressMonitor monitor) {
Map<URI, List<MarketplaceNodeCatalogItem>> installedCatalogItemsByUpdateUri = new HashMap<URI, List<MarketplaceNodeCatalogItem>>();
for (MarketplaceNodeCatalogItem catalogItem : updateCheckNeeded) {
INode node = catalogItem.getData();
String updateurl = node.getUpdateurl();
try {
if (updateurl == null) {
catalogItem.setAvailable(false);
continue;
}
URI uri = new URI(updateurl);
List<MarketplaceNodeCatalogItem> catalogItemsThisSite = installedCatalogItemsByUpdateUri.get(uri);
if (catalogItemsThisSite == null) {
catalogItemsThisSite = new ArrayList<MarketplaceNodeCatalogItem>();
installedCatalogItemsByUpdateUri.put(uri, catalogItemsThisSite);
}
catalogItemsThisSite.add(catalogItem);
} catch (URISyntaxException e) {
MarketplaceClientUi.log(IStatus.WARNING, Messages.MarketplaceCatalog_InvalidRepositoryUrl, node.getName(), updateurl);
catalogItem.setAvailable(false);
}
}
if (installedCatalogItemsByUpdateUri.isEmpty()) {
return Status.OK_STATUS;
}
ConcurrentTaskManager executor = new ConcurrentTaskManager(installedCatalogItemsByUpdateUri.size(), Messages.MarketplaceCatalog_checkingForUpdates);
try {
final IProgressMonitor pm = new NullProgressMonitor() {
@Override
public boolean isCanceled() {
return super.isCanceled() || monitor.isCanceled();
}
};
for (Map.Entry<URI, List<MarketplaceNodeCatalogItem>> entry : installedCatalogItemsByUpdateUri.entrySet()) {
final URI uri = entry.getKey();
final List<MarketplaceNodeCatalogItem> catalogItemsThisSite = entry.getValue();
executor.submit(new Runnable() {
public void run() {
ProvisioningSession session = ProvisioningUI.getDefaultUI().getSession();
IMetadataRepositoryManager manager = (IMetadataRepositoryManager) session.getProvisioningAgent().getService(IMetadataRepositoryManager.SERVICE_NAME);
try {
for (MarketplaceNodeCatalogItem item : catalogItemsThisSite) {
if (Boolean.TRUE.equals(item.getAvailable())) {
item.setAvailable(null);
}
}
IMetadataRepository repository = manager.loadRepository(uri, pm);
IQuery<IInstallableUnit> query = //
QueryUtil.createMatchQuery(// $NON-NLS-1$
"id ~= /*.feature.group/ && " + // $NON-NLS-1$
"properties['org.eclipse.equinox.p2.type.group'] == true ");
IQueryResult<IInstallableUnit> result = repository.query(query, pm);
// compute highest version for all available IUs.
Map<String, Version> repositoryIuVersionById = new HashMap<String, Version>();
for (IInstallableUnit iu : result) {
String key = createRepositoryIuKey(uri.toString(), iu.getId());
Version version = iu.getVersion();
Version priorVersion = repositoryIuVersionById.put(key, version);
if (priorVersion != null && priorVersion.compareTo(version) > 0) {
repositoryIuVersionById.put(key, priorVersion);
}
}
for (MarketplaceNodeCatalogItem item : catalogItemsThisSite) {
List<MarketplaceNodeInstallableUnitItem> installableUnitItems = item.getInstallableUnitItems();
for (MarketplaceNodeInstallableUnitItem iuItem : installableUnitItems) {
String key = createRepositoryIuKey(uri.toString(), iuItem.getId());
Version availableVersion = repositoryIuVersionById.get(key);
MarketplaceCatalog.this.repositoryIuVersionById.put(key, availableVersion);
if (availableVersion != null) {
item.setAvailable(true);
}
}
}
for (MarketplaceNodeCatalogItem item : catalogItemsThisSite) {
setUpdatesAvailable(installedIUs, item);
}
} catch (ProvisionException e) {
MultiStatus errorStatus = new MultiStatus(MarketplaceClientUi.BUNDLE_ID, IStatus.WARNING, NLS.bind(Messages.MarketplaceCatalog_ErrorReadingRepository, uri), e);
for (MarketplaceNodeCatalogItem item : catalogItemsThisSite) {
item.setAvailable(false);
errorStatus.add(MarketplaceClientUi.newStatus(IStatus.INFO, item.getName()));
}
MarketplaceClientUi.getLog().log(errorStatus);
} catch (OperationCanceledException e) {
// nothing to do
}
}
});
}
try {
executor.waitUntilFinished(monitor);
} catch (CoreException e) {
MarketplaceClientUi.error(e);
return e.getStatus();
}
return Status.OK_STATUS;
} finally {
executor.shutdownNow();
}
}
use of org.eclipse.epp.mpc.core.model.INode in project epp.mpc by eclipse.
the class MarketplaceUrlHandlerTest method testNodeUrls.
@Test
public void testNodeUrls() throws Exception {
final INode[] testNode = new INode[1];
MarketplaceUrlHandler handler = new MarketplaceUrlHandler() {
@Override
protected boolean handleNode(CatalogDescriptor descriptor, String url, INode node) {
testNode[0] = node;
return true;
}
};
testNode[0] = null;
String url = "http://marketplace.eclipse.org/content/test";
assertTrue(handler.handleUri(url));
assertNotNull(testNode[0]);
assertEquals(url, testNode[0].getUrl());
testNode[0] = null;
String nodeId = "12345";
url = "http://marketplace.eclipse.org/node/" + nodeId;
assertTrue(handler.handleUri(url));
assertNotNull(testNode[0]);
assertEquals(nodeId, testNode[0].getId());
}
use of org.eclipse.epp.mpc.core.model.INode in project epp.mpc by eclipse.
the class UserFavoritesServiceTest method testToggleFavorite.
@Test
public void testToggleFavorite() throws Exception {
INode favNode = QueryHelper.nodeById("12345");
favoritesService.setFavorite(favNode, true, null);
List<INode> favorites = favoritesService.getFavorites(null);
assertNotNull(QueryHelper.findById(favorites, favNode));
favoritesService.setFavorite(favNode, false, null);
favorites = favoritesService.getFavorites(null);
assertNull(QueryHelper.findById(favorites, favNode));
}
Aggregations