Search in sources :

Example 1 with Certification

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);
}
Also used : MultiStatus(org.eclipse.core.runtime.MultiStatus) IStatus(org.eclipse.core.runtime.IStatus) Status(org.eclipse.core.runtime.Status) IStatus(org.eclipse.core.runtime.IStatus) ArrayList(java.util.ArrayList) MultiStatus(org.eclipse.core.runtime.MultiStatus) CatalogCategory(org.eclipse.equinox.internal.p2.discovery.model.CatalogCategory) Certification(org.eclipse.equinox.internal.p2.discovery.model.Certification) SubProgressMonitor(org.eclipse.core.runtime.SubProgressMonitor) CatalogItem(org.eclipse.equinox.internal.p2.discovery.model.CatalogItem) CoreException(org.eclipse.core.runtime.CoreException) AbstractDiscoveryStrategy(org.eclipse.equinox.internal.p2.discovery.AbstractDiscoveryStrategy) Tag(org.eclipse.equinox.internal.p2.discovery.model.Tag)

Aggregations

ArrayList (java.util.ArrayList)1 CoreException (org.eclipse.core.runtime.CoreException)1 IStatus (org.eclipse.core.runtime.IStatus)1 MultiStatus (org.eclipse.core.runtime.MultiStatus)1 Status (org.eclipse.core.runtime.Status)1 SubProgressMonitor (org.eclipse.core.runtime.SubProgressMonitor)1 AbstractDiscoveryStrategy (org.eclipse.equinox.internal.p2.discovery.AbstractDiscoveryStrategy)1 CatalogCategory (org.eclipse.equinox.internal.p2.discovery.model.CatalogCategory)1 CatalogItem (org.eclipse.equinox.internal.p2.discovery.model.CatalogItem)1 Certification (org.eclipse.equinox.internal.p2.discovery.model.Certification)1 Tag (org.eclipse.equinox.internal.p2.discovery.model.Tag)1