Search in sources :

Example 1 with SearchResult

use of org.eclipse.epp.internal.mpc.core.model.SearchResult in project epp.mpc by eclipse.

the class MarketplaceCatalogTest method setupCatalog.

protected void setupCatalog() throws MalformedURLException {
    final SearchResult discoveryResult = new SearchResult();
    discoveryResult.setNodes(discoveryNodes);
    CatalogDescriptor catalogDescriptor = new CatalogDescriptor();
    catalogDescriptor.setUrl(new URL("http://marketplace.eclipse.org"));
    MarketplaceDiscoveryStrategy discoveryStrategy = new MarketplaceDiscoveryStrategy(catalogDescriptor) {

        final MarketplaceCategory category = new MarketplaceCategory();

        {
            category.setId("<root>");
        }

        @Override
        public void performDiscovery(IProgressMonitor monitor) throws CoreException {
            if (!categories.contains(category)) {
                categories.add(category);
            }
            handleSearchResult(category, discoveryResult, new NullProgressMonitor());
        }

        @Override
        protected synchronized Map<String, IInstallableUnit> computeInstalledIUs(IProgressMonitor monitor) {
            Map<String, IInstallableUnit> installedIus = new HashMap<String, IInstallableUnit>();
            for (INode node : installedNodes) {
                IIus ius = node.getIus();
                if (ius != null) {
                    for (IIu iu : ius.getIuElements()) {
                        String featureId = iu.getId() + ".feature.group";
                        InstallableUnit installableUnit = new InstallableUnit();
                        installableUnit.setId(featureId);
                        installedIus.put(featureId, installableUnit);
                    }
                }
            }
            return installedIus;
        }

        @Override
        protected MarketplaceCategory findMarketplaceCategory(IProgressMonitor monitor) throws CoreException {
            return category;
        }
    };
    catalog = new MarketplaceCatalog() {

        @Override
        protected IStatus checkForUpdates(List<MarketplaceNodeCatalogItem> updateCheckNeeded, final Map<String, IInstallableUnit> installedIUs, final IProgressMonitor monitor) {
            for (MarketplaceNodeCatalogItem item : updateCheckNeeded) {
                checkedForUpdate.add(item.getData());
                List<MarketplaceNodeInstallableUnitItem> installableUnitItems = item.getInstallableUnitItems();
                boolean hasUpdate = updateAvailable.contains(item.getData());
                for (MarketplaceNodeInstallableUnitItem iuItem : installableUnitItems) {
                    iuItem.setUpdateAvailable(hasUpdate);
                }
            }
            return Status.OK_STATUS;
        }
    };
    catalog.getDiscoveryStrategies().add(discoveryStrategy);
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) INode(org.eclipse.epp.mpc.core.model.INode) IStatus(org.eclipse.core.runtime.IStatus) HashMap(java.util.HashMap) MarketplaceDiscoveryStrategy(org.eclipse.epp.internal.mpc.ui.catalog.MarketplaceDiscoveryStrategy) SearchResult(org.eclipse.epp.internal.mpc.core.model.SearchResult) MarketplaceCategory(org.eclipse.epp.internal.mpc.ui.catalog.MarketplaceCategory) IInstallableUnit(org.eclipse.equinox.p2.metadata.IInstallableUnit) InstallableUnit(org.eclipse.equinox.internal.p2.metadata.InstallableUnit) URL(java.net.URL) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) IIu(org.eclipse.epp.mpc.core.model.IIu) MarketplaceNodeInstallableUnitItem(org.eclipse.epp.internal.mpc.ui.catalog.MarketplaceNodeInstallableUnitItem) IInstallableUnit(org.eclipse.equinox.p2.metadata.IInstallableUnit) ArrayList(java.util.ArrayList) List(java.util.List) MarketplaceCatalog(org.eclipse.epp.internal.mpc.ui.catalog.MarketplaceCatalog) IIus(org.eclipse.epp.mpc.core.model.IIus) MarketplaceNodeCatalogItem(org.eclipse.epp.internal.mpc.ui.catalog.MarketplaceNodeCatalogItem) CatalogDescriptor(org.eclipse.epp.mpc.ui.CatalogDescriptor)

Example 2 with SearchResult

use of org.eclipse.epp.internal.mpc.core.model.SearchResult in project epp.mpc by eclipse.

the class MarketplaceDiscoveryStrategy method performNodeQuery.

public void performNodeQuery(IProgressMonitor monitor, Set<? extends INode> nodes) throws CoreException {
    SubMonitor progress = SubMonitor.convert(monitor, Messages.MarketplaceDiscoveryStrategy_searchingMarketplace, 1001);
    try {
        MarketplaceCategory catalogCategory = findMarketplaceCategory(progress.newChild(1));
        catalogCategory.setContents(Contents.QUERY);
        SearchResult result = new SearchResult();
        result.setNodes(new ArrayList<Node>());
        if (!monitor.isCanceled()) {
            if (!nodes.isEmpty()) {
                List<INode> resolvedNodes = marketplaceService.getNodes(nodes, progress.newChild(500));
                for (INode node : resolvedNodes) {
                    result.getNodes().add((Node) node);
                }
            } else {
                progress.setWorkRemaining(500);
            }
            result.setMatchCount(result.getNodes().size());
            handleSearchResult(catalogCategory, result, progress.newChild(500));
        }
    } finally {
        monitor.done();
    }
}
Also used : INode(org.eclipse.epp.mpc.core.model.INode) Node(org.eclipse.epp.internal.mpc.core.model.Node) INode(org.eclipse.epp.mpc.core.model.INode) SubMonitor(org.eclipse.core.runtime.SubMonitor) ISearchResult(org.eclipse.epp.mpc.core.model.ISearchResult) SearchResult(org.eclipse.epp.internal.mpc.core.model.SearchResult)

Example 3 with SearchResult

use of org.eclipse.epp.internal.mpc.core.model.SearchResult in project epp.mpc by eclipse.

the class MarketplaceDiscoveryStrategy method installed.

public void installed(IProgressMonitor monitor) throws CoreException {
    SubMonitor progress = SubMonitor.convert(monitor, Messages.MarketplaceDiscoveryStrategy_findingInstalled, 1000);
    try {
        MarketplaceCategory catalogCategory = findMarketplaceCategory(progress.newChild(1));
        catalogCategory.setContents(Contents.INSTALLED);
        SearchResult result = computeInstalled(progress.newChild(500));
        if (!monitor.isCanceled()) {
            handleSearchResult(catalogCategory, result, progress.newChild(500));
        }
    } finally {
        monitor.done();
    }
}
Also used : SubMonitor(org.eclipse.core.runtime.SubMonitor) ISearchResult(org.eclipse.epp.mpc.core.model.ISearchResult) SearchResult(org.eclipse.epp.internal.mpc.core.model.SearchResult)

Example 4 with SearchResult

use of org.eclipse.epp.internal.mpc.core.model.SearchResult in project epp.mpc by eclipse.

the class MarketplaceDiscoveryStrategy method related.

public void related(IProgressMonitor monitor) throws CoreException {
    SubMonitor progress = SubMonitor.convert(monitor, Messages.MarketplaceDiscoveryStrategy_searchingMarketplace, 801);
    try {
        MarketplaceCategory catalogCategory = findMarketplaceCategory(progress.newChild(1));
        catalogCategory.setContents(Contents.RELATED);
        SearchResult installed = computeInstalled(progress.newChild(200));
        if (!monitor.isCanceled()) {
            ISearchResult result = marketplaceService.related(installed.getNodes(), progress.newChild(300));
            handleSearchResult(catalogCategory, result, progress.newChild(300));
            maybeAddCatalogItem(catalogCategory);
        }
    } finally {
        monitor.done();
    }
}
Also used : ISearchResult(org.eclipse.epp.mpc.core.model.ISearchResult) SubMonitor(org.eclipse.core.runtime.SubMonitor) ISearchResult(org.eclipse.epp.mpc.core.model.ISearchResult) SearchResult(org.eclipse.epp.internal.mpc.core.model.SearchResult)

Example 5 with SearchResult

use of org.eclipse.epp.internal.mpc.core.model.SearchResult in project epp.mpc by eclipse.

the class MarketplaceDiscoveryStrategy method computeInstalled.

protected SearchResult computeInstalled(IProgressMonitor monitor) throws CoreException {
    SearchResult result = new SearchResult();
    result.setNodes(new ArrayList<Node>());
    SubMonitor progress = SubMonitor.convert(monitor, Messages.MarketplaceDiscoveryStrategy_ComputingInstalled, 1000);
    Map<String, IInstallableUnit> installedIUs = computeInstalledIUs(progress.newChild(500));
    if (!monitor.isCanceled()) {
        Set<INode> catalogNodes = marketplaceInfo.computeInstalledNodes(catalogDescriptor.getUrl(), installedIUs);
        if (!catalogNodes.isEmpty()) {
            List<INode> resolvedNodes = marketplaceService.getNodes(catalogNodes, progress.newChild(490));
            SubMonitor nodeProgress = SubMonitor.convert(progress.newChild(10), resolvedNodes.size());
            for (INode node : resolvedNodes) {
                // compute real installed state based on optional/required state
                if (marketplaceInfo.computeInstalled(installedIUs.keySet(), node)) {
                    result.getNodes().add((Node) node);
                }
                nodeProgress.worked(1);
            }
        } else {
            monitor.worked(500);
        }
    }
    return result;
}
Also used : INode(org.eclipse.epp.mpc.core.model.INode) Node(org.eclipse.epp.internal.mpc.core.model.Node) INode(org.eclipse.epp.mpc.core.model.INode) SubMonitor(org.eclipse.core.runtime.SubMonitor) ISearchResult(org.eclipse.epp.mpc.core.model.ISearchResult) SearchResult(org.eclipse.epp.internal.mpc.core.model.SearchResult) IInstallableUnit(org.eclipse.equinox.p2.metadata.IInstallableUnit)

Aggregations

SearchResult (org.eclipse.epp.internal.mpc.core.model.SearchResult)8 ISearchResult (org.eclipse.epp.mpc.core.model.ISearchResult)7 INode (org.eclipse.epp.mpc.core.model.INode)5 SubMonitor (org.eclipse.core.runtime.SubMonitor)4 Node (org.eclipse.epp.internal.mpc.core.model.Node)4 CoreException (org.eclipse.core.runtime.CoreException)2 CatalogDescriptor (org.eclipse.epp.mpc.ui.CatalogDescriptor)2 IInstallableUnit (org.eclipse.equinox.p2.metadata.IInstallableUnit)2 FileNotFoundException (java.io.FileNotFoundException)1 URL (java.net.URL)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 List (java.util.List)1 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)1 IStatus (org.eclipse.core.runtime.IStatus)1 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)1 Category (org.eclipse.epp.internal.mpc.core.model.Category)1 Marketplace (org.eclipse.epp.internal.mpc.core.model.Marketplace)1 Search (org.eclipse.epp.internal.mpc.core.model.Search)1 MarketplaceCatalog (org.eclipse.epp.internal.mpc.ui.catalog.MarketplaceCatalog)1