Search in sources :

Example 6 with AbstractDiscoveryStrategy

use of org.eclipse.equinox.internal.p2.discovery.AbstractDiscoveryStrategy in project epp.mpc by eclipse.

the class MarketplaceCatalog method calculateInstalledIUs.

private Map<String, IInstallableUnit> calculateInstalledIUs(IProgressMonitor monitor) {
    Map<String, IInstallableUnit> installedIUs = new HashMap<String, IInstallableUnit>();
    List<AbstractDiscoveryStrategy> discoveryStrategies = getDiscoveryStrategies();
    SubMonitor progress = SubMonitor.convert(monitor, discoveryStrategies.size() * 1000);
    for (AbstractDiscoveryStrategy discoveryStrategy : discoveryStrategies) {
        if (monitor.isCanceled()) {
            break;
        }
        SubMonitor childProgress = progress.newChild(1000);
        if (discoveryStrategy instanceof MarketplaceDiscoveryStrategy) {
            MarketplaceDiscoveryStrategy marketplaceDiscoveryStrategy = (MarketplaceDiscoveryStrategy) discoveryStrategy;
            Map<String, IInstallableUnit> ius = marketplaceDiscoveryStrategy.computeInstalledIUs(childProgress);
            installedIUs.putAll(ius);
        }
        childProgress.setWorkRemaining(0);
    }
    return installedIUs;
}
Also used : HashMap(java.util.HashMap) AbstractDiscoveryStrategy(org.eclipse.equinox.internal.p2.discovery.AbstractDiscoveryStrategy) SubMonitor(org.eclipse.core.runtime.SubMonitor) IInstallableUnit(org.eclipse.equinox.p2.metadata.IInstallableUnit)

Example 7 with AbstractDiscoveryStrategy

use of org.eclipse.equinox.internal.p2.discovery.AbstractDiscoveryStrategy 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)

Example 8 with AbstractDiscoveryStrategy

use of org.eclipse.equinox.internal.p2.discovery.AbstractDiscoveryStrategy in project epp.mpc by eclipse.

the class ImportFavoritesPage method findUserFavoritesService.

private IUserFavoritesService findUserFavoritesService() {
    IUserFavoritesService userFavoritesService = null;
    for (AbstractDiscoveryStrategy strategy : getCatalog().getDiscoveryStrategies()) {
        if (strategy instanceof FavoritesDiscoveryStrategy) {
            FavoritesDiscoveryStrategy favoritesStrategy = (FavoritesDiscoveryStrategy) strategy;
            userFavoritesService = favoritesStrategy.getMarketplaceService().getUserFavoritesService();
        }
    }
    return userFavoritesService;
}
Also used : FavoritesDiscoveryStrategy(org.eclipse.epp.internal.mpc.ui.catalog.FavoritesDiscoveryStrategy) AbstractDiscoveryStrategy(org.eclipse.equinox.internal.p2.discovery.AbstractDiscoveryStrategy) IUserFavoritesService(org.eclipse.epp.mpc.core.service.IUserFavoritesService)

Aggregations

AbstractDiscoveryStrategy (org.eclipse.equinox.internal.p2.discovery.AbstractDiscoveryStrategy)8 MarketplaceDiscoveryStrategy (org.eclipse.epp.internal.mpc.ui.catalog.MarketplaceDiscoveryStrategy)3 CoreException (org.eclipse.core.runtime.CoreException)2 IStatus (org.eclipse.core.runtime.IStatus)2 MultiStatus (org.eclipse.core.runtime.MultiStatus)2 Status (org.eclipse.core.runtime.Status)2 SubMonitor (org.eclipse.core.runtime.SubMonitor)2 FavoritesDiscoveryStrategy (org.eclipse.epp.internal.mpc.ui.catalog.FavoritesDiscoveryStrategy)2 MarketplaceCatalog (org.eclipse.epp.internal.mpc.ui.catalog.MarketplaceCatalog)2 CatalogCategory (org.eclipse.equinox.internal.p2.discovery.model.CatalogCategory)2 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 SubProgressMonitor (org.eclipse.core.runtime.SubProgressMonitor)1 MarketplaceCategory (org.eclipse.epp.internal.mpc.ui.catalog.MarketplaceCategory)1 INews (org.eclipse.epp.mpc.core.model.INews)1 IUserFavoritesService (org.eclipse.epp.mpc.core.service.IUserFavoritesService)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 CatalogFilter (org.eclipse.equinox.internal.p2.ui.discovery.wizards.CatalogFilter)1