use of org.eclipse.equinox.internal.p2.discovery.model.Certification in project epp.mpc by eclipse.
the class MarketplaceCatalog method performDiscovery.
protected IStatus performDiscovery(DiscoveryOperation operation, boolean refresh, IProgressMonitor monitor) {
MultiStatus status = new MultiStatus(MarketplaceClientUi.BUNDLE_ID, 0, Messages.MarketplaceCatalog_queryFailed, null);
if (getDiscoveryStrategies().isEmpty()) {
throw new IllegalStateException();
}
// reset, keeping no items but the same tags, categories and certifications
List<CatalogItem> items = new ArrayList<CatalogItem>();
List<CatalogCategory> categories = new ArrayList<CatalogCategory>(getCategories());
List<Certification> certifications = new ArrayList<Certification>(getCertifications());
List<Tag> tags = new ArrayList<Tag>(getTags());
if (!refresh) {
for (CatalogCategory catalogCategory : categories) {
catalogCategory.getItems().clear();
}
}
final int totalTicks = 100000;
final int discoveryTicks = totalTicks - (totalTicks / 10);
monitor.beginTask(Messages.MarketplaceCatalog_queryingMarketplace, totalTicks);
try {
int strategyTicks = discoveryTicks / getDiscoveryStrategies().size();
for (AbstractDiscoveryStrategy discoveryStrategy : getDiscoveryStrategies()) {
if (monitor.isCanceled()) {
status.add(Status.CANCEL_STATUS);
break;
}
if (discoveryStrategy instanceof MarketplaceDiscoveryStrategy) {
List<CatalogCategory> oldCategories = discoveryStrategy.getCategories();
List<CatalogItem> oldItems = discoveryStrategy.getItems();
List<Certification> oldCertifications = discoveryStrategy.getCertifications();
List<Tag> oldTags = discoveryStrategy.getTags();
discoveryStrategy.setCategories(categories);
discoveryStrategy.setItems(items);
discoveryStrategy.setCertifications(certifications);
discoveryStrategy.setTags(tags);
try {
MarketplaceDiscoveryStrategy marketplaceStrategy = (MarketplaceDiscoveryStrategy) discoveryStrategy;
operation.run(marketplaceStrategy, new SubProgressMonitor(monitor, strategyTicks));
} catch (CoreException e) {
IStatus error = MarketplaceClientCore.computeWellknownProblemStatus(e);
if (error == null) {
error = new Status(e.getStatus().getSeverity(), DiscoveryCore.ID_PLUGIN, NLS.bind(Messages.MarketplaceCatalog_failedWithError, discoveryStrategy.getClass().getSimpleName()), e);
}
status.add(error);
} finally {
// remove everything from strategy again, so it can't accidentally mess with the results later
discoveryStrategy.setCategories(oldCategories);
discoveryStrategy.setItems(oldItems);
discoveryStrategy.setCertifications(oldCertifications);
discoveryStrategy.setTags(oldTags);
// make sure strategy didn't misbehave
if (items.contains(null)) {
while (items.remove(null)) {
}
IStatus error = new Status(IStatus.WARNING, DiscoveryCore.ID_PLUGIN, NLS.bind(Messages.MarketplaceCatalog_addedNullEntry, discoveryStrategy.getClass().getSimpleName()));
status.add(error);
}
}
}
}
update(categories, items, certifications, tags);
} finally {
monitor.done();
}
return computeStatus(status);
}
Aggregations