Search in sources :

Example 21 with Version

use of org.eclipse.equinox.p2.metadata.Version in project webtools.servertools by eclipse.

the class ExtensionUtility method alreadyExists.

/**
 * Return true if the new feature is already installed, or a newer one is.
 *
 * @param existing
 * @param newFeature
 * @return true if the new feature is already installed, or a newer one is.
 */
private static boolean alreadyExists(List<Extension> existing, IServerExtension newFeature) {
    if (existing.contains(newFeature))
        return true;
    Version newV = newFeature.getVersion();
    Iterator<Extension> iterator = existing.iterator();
    while (iterator.hasNext()) {
        IServerExtension feature = iterator.next();
        if (feature.getId().equals(newFeature.getId())) {
            if (newV == null)
                return true;
            if (feature.getVersion().compareTo(newV) >= 0)
                return true;
        }
    }
    return false;
}
Also used : Version(org.eclipse.equinox.p2.metadata.Version)

Example 22 with Version

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

the class MarketplaceDiscoveryStrategy method installErrorReport.

public void installErrorReport(IProgressMonitor monitor, IStatus result, Set<CatalogItem> items, IInstallableUnit[] operationIUs, String resolutionDetails) throws CoreException {
    SubMonitor progress = SubMonitor.convert(monitor, Messages.MarketplaceDiscoveryStrategy_sendingErrorNotification, 100);
    try {
        Set<Node> nodes = new HashSet<Node>();
        for (CatalogItem item : items) {
            Object data = item.getData();
            if (data instanceof INode) {
                nodes.add((Node) data);
            }
        }
        Set<String> iuIdsAndVersions = new HashSet<String>();
        for (IInstallableUnit iu : operationIUs) {
            String id = iu.getId();
            String version = iu.getVersion() == null ? null : iu.getVersion().toString();
            // $NON-NLS-1$
            iuIdsAndVersions.add(id + "," + version);
        }
        marketplaceService.reportInstallError(result, nodes, iuIdsAndVersions, resolutionDetails, progress);
    } finally {
        progress.done();
    }
}
Also used : CatalogItem(org.eclipse.equinox.internal.p2.discovery.model.CatalogItem) 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) IInstallableUnit(org.eclipse.equinox.p2.metadata.IInstallableUnit) HashSet(java.util.HashSet)

Example 23 with Version

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

the class ProfileChangeOperationComputer method computeInstallableUnits.

public IInstallableUnit[] computeInstallableUnits(IProgressMonitor monitor) throws CoreException {
    try {
        SubMonitor progress = SubMonitor.convert(monitor, 100);
        // add repository urls and load meta data
        List<IMetadataRepository> repositories = addRepositories(progress.newChild(50));
        List<IInstallableUnit> installableUnits = queryInstallableUnits(progress.newChild(50), repositories);
        checkForUnavailable(installableUnits);
        pruneNonInstall(installableUnits);
        // bug 306446 we never want to downgrade the installed version
        pruneOlderVersions(installableUnits);
        return installableUnits.toArray(new IInstallableUnit[installableUnits.size()]);
    } catch (URISyntaxException e) {
        // should never happen, since we already validated URLs.
        throw new CoreException(new Status(IStatus.ERROR, MarketplaceClientUi.BUNDLE_ID, Messages.ProvisioningOperation_unexpectedErrorUrl, e));
    } finally {
        monitor.done();
    }
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) Status(org.eclipse.core.runtime.Status) CoreException(org.eclipse.core.runtime.CoreException) SubMonitor(org.eclipse.core.runtime.SubMonitor) IInstallableUnit(org.eclipse.equinox.p2.metadata.IInstallableUnit) URISyntaxException(java.net.URISyntaxException) IMetadataRepository(org.eclipse.equinox.p2.repository.metadata.IMetadataRepository)

Example 24 with Version

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

the class MarketplaceCatalog method checkForUpdates.

protected IStatus checkForUpdates(List<MarketplaceNodeCatalogItem> updateCheckNeeded, final Map<String, IInstallableUnit> installedIUs, final IProgressMonitor monitor) {
    Map<URI, List<MarketplaceNodeCatalogItem>> installedCatalogItemsByUpdateUri = new HashMap<URI, List<MarketplaceNodeCatalogItem>>();
    for (MarketplaceNodeCatalogItem catalogItem : updateCheckNeeded) {
        INode node = catalogItem.getData();
        String updateurl = node.getUpdateurl();
        try {
            if (updateurl == null) {
                catalogItem.setAvailable(false);
                continue;
            }
            URI uri = new URI(updateurl);
            List<MarketplaceNodeCatalogItem> catalogItemsThisSite = installedCatalogItemsByUpdateUri.get(uri);
            if (catalogItemsThisSite == null) {
                catalogItemsThisSite = new ArrayList<MarketplaceNodeCatalogItem>();
                installedCatalogItemsByUpdateUri.put(uri, catalogItemsThisSite);
            }
            catalogItemsThisSite.add(catalogItem);
        } catch (URISyntaxException e) {
            MarketplaceClientUi.log(IStatus.WARNING, Messages.MarketplaceCatalog_InvalidRepositoryUrl, node.getName(), updateurl);
            catalogItem.setAvailable(false);
        }
    }
    if (installedCatalogItemsByUpdateUri.isEmpty()) {
        return Status.OK_STATUS;
    }
    ConcurrentTaskManager executor = new ConcurrentTaskManager(installedCatalogItemsByUpdateUri.size(), Messages.MarketplaceCatalog_checkingForUpdates);
    try {
        final IProgressMonitor pm = new NullProgressMonitor() {

            @Override
            public boolean isCanceled() {
                return super.isCanceled() || monitor.isCanceled();
            }
        };
        for (Map.Entry<URI, List<MarketplaceNodeCatalogItem>> entry : installedCatalogItemsByUpdateUri.entrySet()) {
            final URI uri = entry.getKey();
            final List<MarketplaceNodeCatalogItem> catalogItemsThisSite = entry.getValue();
            executor.submit(new Runnable() {

                public void run() {
                    ProvisioningSession session = ProvisioningUI.getDefaultUI().getSession();
                    IMetadataRepositoryManager manager = (IMetadataRepositoryManager) session.getProvisioningAgent().getService(IMetadataRepositoryManager.SERVICE_NAME);
                    try {
                        for (MarketplaceNodeCatalogItem item : catalogItemsThisSite) {
                            if (Boolean.TRUE.equals(item.getAvailable())) {
                                item.setAvailable(null);
                            }
                        }
                        IMetadataRepository repository = manager.loadRepository(uri, pm);
                        IQuery<IInstallableUnit> query = // 
                        QueryUtil.createMatchQuery(// $NON-NLS-1$
                        "id ~= /*.feature.group/ && " + // $NON-NLS-1$
                        "properties['org.eclipse.equinox.p2.type.group'] == true ");
                        IQueryResult<IInstallableUnit> result = repository.query(query, pm);
                        // compute highest version for all available IUs.
                        Map<String, Version> repositoryIuVersionById = new HashMap<String, Version>();
                        for (IInstallableUnit iu : result) {
                            String key = createRepositoryIuKey(uri.toString(), iu.getId());
                            Version version = iu.getVersion();
                            Version priorVersion = repositoryIuVersionById.put(key, version);
                            if (priorVersion != null && priorVersion.compareTo(version) > 0) {
                                repositoryIuVersionById.put(key, priorVersion);
                            }
                        }
                        for (MarketplaceNodeCatalogItem item : catalogItemsThisSite) {
                            List<MarketplaceNodeInstallableUnitItem> installableUnitItems = item.getInstallableUnitItems();
                            for (MarketplaceNodeInstallableUnitItem iuItem : installableUnitItems) {
                                String key = createRepositoryIuKey(uri.toString(), iuItem.getId());
                                Version availableVersion = repositoryIuVersionById.get(key);
                                MarketplaceCatalog.this.repositoryIuVersionById.put(key, availableVersion);
                                if (availableVersion != null) {
                                    item.setAvailable(true);
                                }
                            }
                        }
                        for (MarketplaceNodeCatalogItem item : catalogItemsThisSite) {
                            setUpdatesAvailable(installedIUs, item);
                        }
                    } catch (ProvisionException e) {
                        MultiStatus errorStatus = new MultiStatus(MarketplaceClientUi.BUNDLE_ID, IStatus.WARNING, NLS.bind(Messages.MarketplaceCatalog_ErrorReadingRepository, uri), e);
                        for (MarketplaceNodeCatalogItem item : catalogItemsThisSite) {
                            item.setAvailable(false);
                            errorStatus.add(MarketplaceClientUi.newStatus(IStatus.INFO, item.getName()));
                        }
                        MarketplaceClientUi.getLog().log(errorStatus);
                    } catch (OperationCanceledException e) {
                    // nothing to do
                    }
                }
            });
        }
        try {
            executor.waitUntilFinished(monitor);
        } catch (CoreException e) {
            MarketplaceClientUi.error(e);
            return e.getStatus();
        }
        return Status.OK_STATUS;
    } finally {
        executor.shutdownNow();
    }
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) INode(org.eclipse.epp.mpc.core.model.INode) IMetadataRepositoryManager(org.eclipse.equinox.p2.repository.metadata.IMetadataRepositoryManager) IQuery(org.eclipse.equinox.p2.query.IQuery) HashMap(java.util.HashMap) OperationCanceledException(org.eclipse.core.runtime.OperationCanceledException) MultiStatus(org.eclipse.core.runtime.MultiStatus) URISyntaxException(java.net.URISyntaxException) URI(java.net.URI) ProvisionException(org.eclipse.equinox.p2.core.ProvisionException) Version(org.eclipse.equinox.p2.metadata.Version) ArrayList(java.util.ArrayList) List(java.util.List) IInstallableUnit(org.eclipse.equinox.p2.metadata.IInstallableUnit) ProvisioningSession(org.eclipse.equinox.p2.operations.ProvisioningSession) IQueryResult(org.eclipse.equinox.p2.query.IQueryResult) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) CoreException(org.eclipse.core.runtime.CoreException) ConcurrentTaskManager(org.eclipse.epp.internal.mpc.ui.util.ConcurrentTaskManager) IMetadataRepository(org.eclipse.equinox.p2.repository.metadata.IMetadataRepository) HashMap(java.util.HashMap) Map(java.util.Map)

Example 25 with Version

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

the class MarketplaceCatalog method setUpdatesAvailable.

private boolean setUpdatesAvailable(Map<String, IInstallableUnit> installedIUs, MarketplaceNodeCatalogItem item) {
    boolean needOnlineCheck = false;
    List<MarketplaceNodeInstallableUnitItem> installableUnitItems = item.getInstallableUnitItems();
    for (MarketplaceNodeInstallableUnitItem iuItem : installableUnitItems) {
        String key = createRepositoryIuKey(item.getSiteUrl(), iuItem.getId());
        Version availableVersion = repositoryIuVersionById.get(key);
        iuItem.setUpdateAvailable(false);
        iuItem.setAvailable(false);
        if (availableVersion != null) {
            iuItem.setAvailable(true);
            IInstallableUnit installedIu = installedIUs.get(iuItem.getId());
            if (installedIu != null && installedIu.getVersion().compareTo(availableVersion) < 0) {
                iuItem.setUpdateAvailable(true);
            }
        } else if (!repositoryIuVersionById.containsKey(key)) {
            needOnlineCheck = true;
        }
    }
    return needOnlineCheck;
}
Also used : Version(org.eclipse.equinox.p2.metadata.Version) IInstallableUnit(org.eclipse.equinox.p2.metadata.IInstallableUnit)

Aggregations

IInstallableUnit (org.eclipse.equinox.p2.metadata.IInstallableUnit)25 Version (org.eclipse.equinox.p2.metadata.Version)15 Test (org.junit.Test)15 File (java.io.File)12 InstallableUnitDescription (org.eclipse.equinox.p2.metadata.MetadataFactory.InstallableUnitDescription)12 ArrayList (java.util.ArrayList)8 IRequirement (org.eclipse.equinox.p2.metadata.IRequirement)7 VersionRange (org.eclipse.equinox.p2.metadata.VersionRange)7 IStatus (org.eclipse.core.runtime.IStatus)5 IProvidedCapability (org.eclipse.equinox.p2.metadata.IProvidedCapability)5 IArtifactDescriptor (org.eclipse.equinox.p2.repository.artifact.IArtifactDescriptor)5 IArtifactKey (org.eclipse.equinox.p2.metadata.IArtifactKey)4 LinkedHashMap (java.util.LinkedHashMap)3 Map (java.util.Map)3 CoreException (org.eclipse.core.runtime.CoreException)3 ArtifactMock (org.eclipse.tycho.p2.impl.test.ArtifactMock)3 IOException (java.io.IOException)2 URI (java.net.URI)2 URISyntaxException (java.net.URISyntaxException)2 HashMap (java.util.HashMap)2