Search in sources :

Example 6 with IQueryResult

use of org.eclipse.equinox.p2.query.IQueryResult in project epp.mpc by eclipse.

the class MarketplaceClientUi method computeInstalledIUsById.

public static Map<String, IInstallableUnit> computeInstalledIUsById(IProgressMonitor monitor) {
    Map<String, IInstallableUnit> iUs = new HashMap<String, IInstallableUnit>();
    BundleContext bundleContext = MarketplaceClientUi.getBundleContext();
    ServiceReference<IProvisioningAgent> serviceReference = bundleContext.getServiceReference(IProvisioningAgent.class);
    if (serviceReference != null) {
        IProvisioningAgent agent = bundleContext.getService(serviceReference);
        try {
            IProfileRegistry profileRegistry = (IProfileRegistry) agent.getService(IProfileRegistry.SERVICE_NAME);
            if (profileRegistry != null) {
                IProfile profile = profileRegistry.getProfile(ProvisioningUI.getDefaultUI().getProfileId());
                if (profile != null) {
                    IQueryResult<IInstallableUnit> result = profile.available(QueryUtil.createIUGroupQuery(), monitor);
                    for (IInstallableUnit unit : result) {
                        iUs.put(unit.getId(), unit);
                    }
                }
            }
        } finally {
            bundleContext.ungetService(serviceReference);
        }
    }
    return iUs;
}
Also used : HashMap(java.util.HashMap) IProvisioningAgent(org.eclipse.equinox.p2.core.IProvisioningAgent) IProfileRegistry(org.eclipse.equinox.p2.engine.IProfileRegistry) IInstallableUnit(org.eclipse.equinox.p2.metadata.IInstallableUnit) IProfile(org.eclipse.equinox.p2.engine.IProfile) BundleContext(org.osgi.framework.BundleContext)

Example 7 with IQueryResult

use of org.eclipse.equinox.p2.query.IQueryResult 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 8 with IQueryResult

use of org.eclipse.equinox.p2.query.IQueryResult in project tycho by eclipse.

the class MetadataSerializableImplTest method deserialize.

private Set<IInstallableUnit> deserialize(File tmpDir) throws ProvisionException {
    IMetadataRepositoryManager manager = (IMetadataRepositoryManager) agent.getService(IMetadataRepositoryManager.SERVICE_NAME);
    IMetadataRepository repository = manager.loadRepository(tmpDir.toURI(), null);
    IQueryResult<IInstallableUnit> queryResult = repository.query(QueryUtil.ALL_UNITS, null);
    Set<IInstallableUnit> result = queryResult.toSet();
    return result;
}
Also used : IMetadataRepositoryManager(org.eclipse.equinox.p2.repository.metadata.IMetadataRepositoryManager) IInstallableUnit(org.eclipse.equinox.p2.metadata.IInstallableUnit) IMetadataRepository(org.eclipse.equinox.p2.repository.metadata.IMetadataRepository)

Example 9 with IQueryResult

use of org.eclipse.equinox.p2.query.IQueryResult in project tycho by eclipse.

the class MetadataSerializableImpl method serialize.

@Override
public void serialize(OutputStream stream, Set<?> installableUnits) throws IOException {
    final List<IInstallableUnit> units = toInstallableUnits(installableUnits);
    // TODO check if we can really "reuse" LocalMetadataRepository or should we implement our own Repository
    AbstractMetadataRepository targetRepo = new AbstractMetadataRepository(agent, // $NON-NLS-1$
    "TychoTargetPlatform", // $NON-NLS-1$
    LocalMetadataRepository.class.getName(), // $NON-NLS-1$
    "0.0.1", // $NON-NLS-1$
    null, // $NON-NLS-1$
    null, // $NON-NLS-1$
    null, // $NON-NLS-1$
    null) {

        @Override
        public void initialize(RepositoryState state) {
        }

        @Override
        public Collection<IRepositoryReference> getReferences() {
            return Collections.emptyList();
        }

        @Override
        public IQueryResult<IInstallableUnit> query(IQuery<IInstallableUnit> query, IProgressMonitor monitor) {
            return query.perform(units.iterator());
        }
    };
    new MetadataRepositoryIO(agent).write(targetRepo, stream);
}
Also used : IQuery(org.eclipse.equinox.p2.query.IQuery) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) AbstractMetadataRepository(org.eclipse.equinox.p2.repository.metadata.spi.AbstractMetadataRepository) MetadataRepositoryIO(org.eclipse.equinox.internal.p2.metadata.repository.MetadataRepositoryIO) IRepositoryReference(org.eclipse.equinox.p2.repository.IRepositoryReference) IInstallableUnit(org.eclipse.equinox.p2.metadata.IInstallableUnit) LocalMetadataRepository(org.eclipse.equinox.internal.p2.metadata.repository.LocalMetadataRepository)

Example 10 with IQueryResult

use of org.eclipse.equinox.p2.query.IQueryResult in project gemoc-studio by eclipse.

the class PrepareInstallProfileJob method queryInstallableUnits.

/**
 * Perform a query to get the installable units. This causes p2 to determine
 * what features are available in each repository. We select installable
 * units by matching both the feature id and the repository; it is possible
 * though unlikely that the same feature id is available from more than one
 * of the selected repositories, and we must ensure that the user gets the
 * one that they asked for.
 */
private List<IInstallableUnit> queryInstallableUnits(SubMonitor monitor, List<IMetadataRepository> repositories) throws URISyntaxException {
    final List<IInstallableUnit> installableUnits = new ArrayList<IInstallableUnit>();
    monitor.setWorkRemaining(repositories.size());
    for (final IMetadataRepository repository : repositories) {
        checkCancelled(monitor);
        final Set<String> installableUnitIdsThisRepository = getDescriptorIds(repository);
        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, monitor.newChild(1));
        for (Iterator<IInstallableUnit> iter = result.iterator(); iter.hasNext(); ) {
            IInstallableUnit iu = iter.next();
            String id = iu.getId();
            if (installableUnitIdsThisRepository.contains(id.substring(0, id.indexOf(P2_FEATURE_GROUP_SUFFIX)))) {
                installableUnits.add(iu);
            }
        }
    }
    return installableUnits;
}
Also used : ArrayList(java.util.ArrayList) IInstallableUnit(org.eclipse.equinox.p2.metadata.IInstallableUnit) IMetadataRepository(org.eclipse.equinox.p2.repository.metadata.IMetadataRepository)

Aggregations

IInstallableUnit (org.eclipse.equinox.p2.metadata.IInstallableUnit)17 ArrayList (java.util.ArrayList)6 IMetadataRepository (org.eclipse.equinox.p2.repository.metadata.IMetadataRepository)5 HashMap (java.util.HashMap)2 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)2 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)2 ProvisionException (org.eclipse.equinox.p2.core.ProvisionException)2 IProfile (org.eclipse.equinox.p2.engine.IProfile)2 IProfileRegistry (org.eclipse.equinox.p2.engine.IProfileRegistry)2 IArtifactKey (org.eclipse.equinox.p2.metadata.IArtifactKey)2 IRequirement (org.eclipse.equinox.p2.metadata.IRequirement)2 VersionRange (org.eclipse.equinox.p2.metadata.VersionRange)2 IQuery (org.eclipse.equinox.p2.query.IQuery)2 IMetadataRepositoryManager (org.eclipse.equinox.p2.repository.metadata.IMetadataRepositoryManager)2 File (java.io.File)1 URI (java.net.URI)1 URISyntaxException (java.net.URISyntaxException)1 LinkedHashSet (java.util.LinkedHashSet)1 List (java.util.List)1 Map (java.util.Map)1