Search in sources :

Example 1 with IIu

use of org.eclipse.epp.mpc.core.model.IIu 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 IIu

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

the class MarketplaceInfo method map.

public synchronized void map(URL marketUrl, INode node) {
    String itemKey = computeItemKey(marketUrl, node);
    if (node.getIus() != null && !node.getIus().getIuElements().isEmpty()) {
        List<String> ius = new ArrayList<String>();
        Set<String> uniqueIus = new HashSet<String>();
        List<IIu> iuElements = node.getIus().getIuElements();
        for (IIu iIu : iuElements) {
            if (uniqueIus.add(iIu.getId())) {
                ius.add(iIu.getId());
            }
        }
        nodeKeyToIU.put(itemKey, ius);
        for (String iu : ius) {
            List<String> catalogNodes = iuToNodeKey.get(iu);
            if (catalogNodes != null) {
                if (!catalogNodes.contains(itemKey)) {
                    catalogNodes.add(itemKey);
                }
            } else {
                catalogNodes = new ArrayList<String>(1);
                catalogNodes.add(itemKey);
                iuToNodeKey.put(iu, catalogNodes);
            }
        }
    } else {
        List<String> ius = nodeKeyToIU.remove(itemKey);
        if (ius != null) {
            for (String iu : ius) {
                List<String> catalogNodes = iuToNodeKey.get(iu);
                if (catalogNodes != null) {
                    catalogNodes.remove(itemKey);
                    if (catalogNodes.isEmpty()) {
                        iuToNodeKey.remove(iu);
                    }
                }
            }
        }
    }
}
Also used : IIu(org.eclipse.epp.mpc.core.model.IIu) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet)

Example 3 with IIu

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

the class MarketplaceInfo method computeInstalled.

/**
 * Compute if the given node is installed. The given node must be fully realized, including its
 * {@link Node#getIus() ius}.
 */
public boolean computeInstalled(Set<String> installedFeatures, INode node) {
    if (node.getIus() != null && !node.getIus().getIuElements().isEmpty()) {
        boolean all = true;
        Set<String> ius = new HashSet<String>();
        for (IIu iu : node.getIus().getIuElements()) {
            if (!iu.isOptional()) {
                ius.add(iu.getId());
            }
        }
        if (ius.isEmpty()) {
            all = false;
            for (IIu iu : node.getIus().getIuElements()) {
                ius.add(iu.getId());
            }
        }
        return computeInstalled(installedFeatures, ius, all);
    }
    return false;
}
Also used : IIu(org.eclipse.epp.mpc.core.model.IIu) HashSet(java.util.HashSet)

Example 4 with IIu

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

the class SolutionCompatibilityFilterTest method testCompatibleInstallableNode.

public void testCompatibleInstallableNode() throws CoreException {
    assumeTrue("Skipping test - this solution and Eclipse/OS are incompatible", compatible);
    assumeTrue("Skipping test - this solution is not installable", solution.installable());
    INode node = queryNode();
    String updateurl = node.getUpdateurl();
    assertThat("Node {1} has no update url", updateurl, not(isEmptyOrNullString()), node);
    IIus ius = node.getIus();
    assertNotNull("Node {1} is missing <ius> element", ius, node);
    List<IIu> iuElements = ius.getIuElements();
    assertNotNull(iuElements);
    assertThat("Node {1} has no IUs", iuElements, not(empty()), node);
    if (version != null) {
        assertEquals("Node {2} has wrong version", version, node.getVersion(), node);
    }
    if (site != null) {
        assertEquals("Node {2} has wrong update site", site, node.getUpdateurl(), node);
    }
    if (features != null) {
        Set<String> allIUs = new HashSet<String>();
        for (IIu iu : iuElements) {
            allIUs.add(iu.getId());
        }
        assertThat("Node {1} is missing some features", allIUs, hasItems(features), node);
        assertThat("Node {1} has some unexpected features", allIUs, hasSize(features.length), node);
    }
}
Also used : INode(org.eclipse.epp.mpc.core.model.INode) IIu(org.eclipse.epp.mpc.core.model.IIu) IIus(org.eclipse.epp.mpc.core.model.IIus) HashSet(java.util.HashSet)

Example 5 with IIu

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

the class MarketplaceDiscoveryStrategy method handleSearchResult.

protected void handleSearchResult(MarketplaceCategory catalogCategory, ISearchResult result, final IProgressMonitor monitor) {
    List<CatalogItem> items = getItems();
    if (items != null && !result.getNodes().isEmpty()) {
        int nodeWork = 1000;
        int favoritesWork = catalogCategory.getContents() == Contents.USER_FAVORITES ? 0 : 1000;
        SubMonitor progress = SubMonitor.convert(monitor, Messages.MarketplaceDiscoveryStrategy_loadingResources, result.getNodes().size() * nodeWork + favoritesWork);
        try {
            boolean userFavoritesSupported = false;
            if (catalogCategory.getContents() == Contents.USER_FAVORITES) {
                userFavoritesSupported = true;
            } else if (hasUserFavoritesService()) {
                try {
                    applyShellProvider();
                    marketplaceService.userFavorites(result.getNodes(), progress.newChild(favoritesWork));
                    userFavoritesSupported = true;
                } catch (NotAuthorizedException e1) {
                // user is not logged in. we just ignore this.
                } catch (UnsupportedOperationException e1) {
                // ignore
                } catch (Exception e1) {
                    // something went wrong. log and proceed.
                    MarketplaceClientCore.error(Messages.MarketplaceDiscoveryStrategy_FavoritesRetrieveError, e1);
                }
            }
            for (final INode node : result.getNodes()) {
                String id = node.getId();
                try {
                    final MarketplaceNodeCatalogItem catalogItem = new MarketplaceNodeCatalogItem();
                    catalogItem.setMarketplaceUrl(catalogDescriptor.getUrl());
                    catalogItem.setId(id);
                    catalogItem.setName(getCatalogItemName(node));
                    catalogItem.setCategoryId(catalogCategory.getId());
                    ICategories categories = node.getCategories();
                    if (categories != null) {
                        for (ICategory category : categories.getCategory()) {
                            catalogItem.addTag(new Tag(ICategory.class, category.getId(), category.getName()));
                        }
                    }
                    catalogItem.setData(node);
                    catalogItem.setSource(source);
                    catalogItem.setLicense(node.getLicense());
                    catalogItem.setUserFavorite(userFavoritesSupported ? node.getUserFavorite() : null);
                    IIus ius = node.getIus();
                    if (ius != null) {
                        List<MarketplaceNodeInstallableUnitItem> installableUnitItems = new ArrayList<MarketplaceNodeInstallableUnitItem>();
                        for (IIu iu : ius.getIuElements()) {
                            MarketplaceNodeInstallableUnitItem iuItem = new MarketplaceNodeInstallableUnitItem();
                            iuItem.init(iu);
                            installableUnitItems.add(iuItem);
                        }
                        catalogItem.setInstallableUnitItems(installableUnitItems);
                    }
                    if (node.getShortdescription() == null && node.getBody() != null) {
                        // bug 306653 <!--break--> marks the end of the short description.
                        String descriptionText = node.getBody();
                        Matcher matcher = BREAK_PATTERN.matcher(node.getBody());
                        if (matcher.find()) {
                            int start = matcher.start();
                            if (start > 0) {
                                String shortDescriptionText = descriptionText.substring(0, start).trim();
                                if (shortDescriptionText.length() > 0) {
                                    descriptionText = shortDescriptionText;
                                }
                            }
                        }
                        catalogItem.setDescription(descriptionText);
                    } else {
                        catalogItem.setDescription(node.getShortdescription());
                    }
                    catalogItem.setProvider(node.getCompanyname());
                    String updateurl = node.getUpdateurl();
                    if (updateurl != null) {
                        try {
                            // trim is important!
                            updateurl = updateurl.trim();
                            URLUtil.toURL(updateurl);
                            catalogItem.setSiteUrl(updateurl);
                        } catch (MalformedURLException e) {
                        // don't use malformed URLs
                        }
                    }
                    if (catalogItem.getInstallableUnits() == null || catalogItem.getInstallableUnits().isEmpty() || catalogItem.getSiteUrl() == null) {
                        catalogItem.setAvailable(false);
                    }
                    if (node.getImage() != null) {
                        if (!source.getResourceProvider().containsResource(node.getImage())) {
                            cacheResource(source.getResourceProvider(), catalogItem, node.getImage());
                        }
                        createIcon(catalogItem, node);
                    }
                    if (node.getBody() != null || node.getScreenshot() != null) {
                        final Overview overview = new Overview();
                        overview.setItem(catalogItem);
                        overview.setSummary(node.getBody());
                        overview.setUrl(node.getUrl());
                        catalogItem.setOverview(overview);
                        if (node.getScreenshot() != null) {
                            if (!source.getResourceProvider().containsResource(node.getScreenshot())) {
                                cacheResource(source.getResourceProvider(), catalogItem, node.getScreenshot());
                            }
                            overview.setScreenshot(node.getScreenshot());
                        }
                    }
                    items.add(catalogItem);
                    marketplaceInfo.map(catalogItem.getMarketplaceUrl(), node);
                    marketplaceInfo.computeInstalled(computeInstalledFeatures(progress.newChild(nodeWork)), catalogItem);
                } catch (RuntimeException ex) {
                    MarketplaceClientUi.error(NLS.bind(Messages.MarketplaceDiscoveryStrategy_ParseError, // $NON-NLS-1$
                    node == null ? "null" : id), ex);
                }
            }
        } finally {
            progress.done();
        }
        if (result.getMatchCount() != null) {
            catalogCategory.setMatchCount(result.getMatchCount());
            if (result.getMatchCount() > result.getNodes().size()) {
                // add an item here to indicate that the search matched more items than were returned by the server
                addCatalogItem(catalogCategory);
            }
        }
    }
}
Also used : INode(org.eclipse.epp.mpc.core.model.INode) MalformedURLException(java.net.MalformedURLException) Matcher(java.util.regex.Matcher) ICategory(org.eclipse.epp.mpc.core.model.ICategory) SubMonitor(org.eclipse.core.runtime.SubMonitor) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) ArrayList(java.util.ArrayList) Overview(org.eclipse.equinox.internal.p2.discovery.model.Overview) NotAuthorizedException(org.eclipse.epp.internal.mpc.core.service.AbstractDataStorageService.NotAuthorizedException) URISyntaxException(java.net.URISyntaxException) CoreException(org.eclipse.core.runtime.CoreException) NotAuthorizedException(org.eclipse.epp.internal.mpc.core.service.AbstractDataStorageService.NotAuthorizedException) NoSuchElementException(java.util.NoSuchElementException) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException) CatalogItem(org.eclipse.equinox.internal.p2.discovery.model.CatalogItem) IIu(org.eclipse.epp.mpc.core.model.IIu) ICategories(org.eclipse.epp.mpc.core.model.ICategories) Tag(org.eclipse.equinox.internal.p2.discovery.model.Tag) IIus(org.eclipse.epp.mpc.core.model.IIus)

Aggregations

IIu (org.eclipse.epp.mpc.core.model.IIu)6 ArrayList (java.util.ArrayList)4 HashSet (java.util.HashSet)3 IIus (org.eclipse.epp.mpc.core.model.IIus)3 INode (org.eclipse.epp.mpc.core.model.INode)3 IOException (java.io.IOException)1 MalformedURLException (java.net.MalformedURLException)1 URISyntaxException (java.net.URISyntaxException)1 URL (java.net.URL)1 HashMap (java.util.HashMap)1 List (java.util.List)1 NoSuchElementException (java.util.NoSuchElementException)1 CopyOnWriteArrayList (java.util.concurrent.CopyOnWriteArrayList)1 Matcher (java.util.regex.Matcher)1 CoreException (org.eclipse.core.runtime.CoreException)1 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)1 IStatus (org.eclipse.core.runtime.IStatus)1 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)1 SubMonitor (org.eclipse.core.runtime.SubMonitor)1 SearchResult (org.eclipse.epp.internal.mpc.core.model.SearchResult)1