Search in sources :

Example 66 with IInstallableUnit

use of org.eclipse.equinox.p2.metadata.IInstallableUnit in project tycho by eclipse.

the class ProjectorResolutionStrategy method fixSWT.

/*
     * workaround for SWT bug 361901: bundles generally require org.eclipse.swt, but this is an
     * empty shell and only native fragments of org.eclipse.swt provide classes to compile against.
     * There is no dependency from the host to the fragments, so we need to add the matching SWT
     * fragment manually.
     */
void fixSWT(Collection<IInstallableUnit> availableIUs, Collection<IInstallableUnit> resolutionResult, Map<String, String> newSelectionContext, IProgressMonitor monitor) {
    IInstallableUnit swtHost = findSWTHostIU(resolutionResult);
    if (swtHost == null) {
        return;
    } else if (swtHost.getVersion().compareTo(Version.createOSGi(3, 104, 0)) >= 0) {
        // bug 361901 was fixed in Mars
        return;
    }
    // 380934 one of rootIUs can be SWT or an SWT fragment
    for (IInstallableUnit iu : data.getRootIUs()) {
        if ("org.eclipse.swt".equals(iu.getId())) {
            return;
        }
        for (IProvidedCapability provided : iu.getProvidedCapabilities()) {
            if ("osgi.fragment".equals(provided.getNamespace()) && "org.eclipse.swt".equals(provided.getName())) {
                return;
            }
        }
    }
    IInstallableUnit swtFragment = null;
    all_ius: for (Iterator<IInstallableUnit> iter = new QueryableCollection(availableIUs).query(QueryUtil.ALL_UNITS, monitor).iterator(); iter.hasNext(); ) {
        IInstallableUnit iu = iter.next();
        if (iu.getId().startsWith("org.eclipse.swt") && isApplicable(newSelectionContext, iu.getFilter()) && providesJavaPackages(iu)) {
            for (IProvidedCapability provided : iu.getProvidedCapabilities()) {
                if ("osgi.fragment".equals(provided.getNamespace()) && "org.eclipse.swt".equals(provided.getName())) {
                    if (swtFragment == null || swtFragment.getVersion().compareTo(iu.getVersion()) < 0) {
                        swtFragment = iu;
                    }
                    continue all_ius;
                }
            }
        }
    }
    if (swtFragment == null) {
        throw new RuntimeException("Could not determine SWT implementation fragment bundle for environment " + newSelectionContext);
    }
    resolutionResult.add(swtFragment);
}
Also used : IProvidedCapability(org.eclipse.equinox.p2.metadata.IProvidedCapability) Iterator(java.util.Iterator) QueryableCollection(org.eclipse.tycho.repository.p2base.metadata.QueryableCollection) IInstallableUnit(org.eclipse.equinox.p2.metadata.IInstallableUnit)

Example 67 with IInstallableUnit

use of org.eclipse.equinox.p2.metadata.IInstallableUnit 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 68 with IInstallableUnit

use of org.eclipse.equinox.p2.metadata.IInstallableUnit in project epp.mpc by eclipse.

the class MarketplaceWizard method computeNewInstallCatalogItems.

private Set<CatalogItem> computeNewInstallCatalogItems() {
    Set<CatalogItem> items = new HashSet<CatalogItem>();
    Map<CatalogItem, Collection<String>> iusByCatalogItem = new HashMap<CatalogItem, Collection<String>>();
    for (CatalogItemEntry entry : getSelectionModel().getCatalogItemEntries()) {
        List<FeatureEntry> features = entry.getChildren();
        Collection<String> featureIds = new ArrayList<String>(features.size());
        for (FeatureEntry feature : features) {
            if (feature.computeChangeOperation() == Operation.INSTALL) {
                featureIds.add(feature.getFeatureDescriptor().getId());
            }
        }
        if (!featureIds.isEmpty()) {
            iusByCatalogItem.put(entry.getItem(), featureIds);
        }
    }
    for (IInstallableUnit unit : operationIUs) {
        for (Entry<CatalogItem, Collection<String>> entry : iusByCatalogItem.entrySet()) {
            if (entry.getValue().contains(unit.getId())) {
                items.add(entry.getKey());
            }
        }
    }
    return items;
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) CatalogItem(org.eclipse.equinox.internal.p2.discovery.model.CatalogItem) FeatureEntry(org.eclipse.epp.internal.mpc.ui.wizards.SelectionModel.FeatureEntry) CatalogItemEntry(org.eclipse.epp.internal.mpc.ui.wizards.SelectionModel.CatalogItemEntry) Collection(java.util.Collection) IInstallableUnit(org.eclipse.equinox.p2.metadata.IInstallableUnit) HashSet(java.util.HashSet)

Example 69 with IInstallableUnit

use of org.eclipse.equinox.p2.metadata.IInstallableUnit 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)

Example 70 with IInstallableUnit

use of org.eclipse.equinox.p2.metadata.IInstallableUnit in project epp.mpc by eclipse.

the class ProfileChangeOperationComputer method pruneOlderVersions.

/**
 * Remove ius from the given list where the current profile already contains a newer version of that iu.
 *
 * @param installableUnits
 * @throws CoreException
 */
private void pruneOlderVersions(List<IInstallableUnit> installableUnits) throws CoreException {
    if (!installableUnits.isEmpty()) {
        Map<String, IInstallableUnit> iUsById = MarketplaceClientUi.computeInstalledIUsById(new NullProgressMonitor());
        Iterator<IInstallableUnit> it = installableUnits.iterator();
        while (it.hasNext()) {
            IInstallableUnit iu = it.next();
            IInstallableUnit installedIu = iUsById.get(iu.getId());
            if (installedIu != null) {
                Version installedVersion = installedIu.getVersion();
                Version installableVersion = iu.getVersion();
                if (installedVersion.compareTo(installableVersion) >= 0) {
                    it.remove();
                }
            }
        }
        if (installableUnits.isEmpty()) {
            throw new CoreException(new Status(IStatus.INFO, MarketplaceClientUi.BUNDLE_ID, Messages.ProvisioningOperation_nothingToUpdate));
        }
    }
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) Status(org.eclipse.core.runtime.Status) NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) CoreException(org.eclipse.core.runtime.CoreException) Version(org.eclipse.equinox.p2.metadata.Version) IInstallableUnit(org.eclipse.equinox.p2.metadata.IInstallableUnit)

Aggregations

IInstallableUnit (org.eclipse.equinox.p2.metadata.IInstallableUnit)153 Test (org.junit.Test)58 ArrayList (java.util.ArrayList)44 File (java.io.File)38 IRequirement (org.eclipse.equinox.p2.metadata.IRequirement)25 HashSet (java.util.HashSet)18 IStatus (org.eclipse.core.runtime.IStatus)18 InstallableUnitDescription (org.eclipse.equinox.p2.metadata.MetadataFactory.InstallableUnitDescription)16 IMetadataRepository (org.eclipse.equinox.p2.repository.metadata.IMetadataRepository)15 HashMap (java.util.HashMap)13 LinkedHashSet (java.util.LinkedHashSet)11 CoreException (org.eclipse.core.runtime.CoreException)11 ProvisionException (org.eclipse.equinox.p2.core.ProvisionException)11 ResourceUtil.resourceFile (org.eclipse.tycho.p2.tools.test.util.ResourceUtil.resourceFile)11 URI (java.net.URI)10 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)9 SubMonitor (org.eclipse.core.runtime.SubMonitor)9 ArtifactMock (org.eclipse.tycho.p2.impl.test.ArtifactMock)9 Status (org.eclipse.core.runtime.Status)8 IRequiredCapability (org.eclipse.equinox.internal.p2.metadata.IRequiredCapability)8