Search in sources :

Example 1 with IQuery

use of org.eclipse.equinox.p2.query.IQuery in project archi by archimatetool.

the class P2Handler method getGroupInstallableUnits.

private Set<IInstallableUnit> getGroupInstallableUnits(URI uri, IProgressMonitor monitor) throws ProvisionException, OperationCanceledException {
    IMetadataRepository metadataRepo = getMetadataRepositoryManager().loadRepository(uri, monitor);
    // Works for feature and its contents
    IQuery<IInstallableUnit> query = QueryUtil.createIUGroupQuery();
    IQueryResult<IInstallableUnit> queryResult = metadataRepo.query(query, monitor);
    return queryResult.toUnmodifiableSet();
}
Also used : IInstallableUnit(org.eclipse.equinox.p2.metadata.IInstallableUnit) IMetadataRepository(org.eclipse.equinox.p2.repository.metadata.IMetadataRepository)

Example 2 with IQuery

use of org.eclipse.equinox.p2.query.IQuery in project webtools.servertools by eclipse.

the class ExtensionUpdateSite method getInstallableUnits.

// Get the list of InstallableUnits and all its requirements
protected List<IServerExtension> getInstallableUnits(IMetadataRepository repo, IQuery<IInstallableUnit> query, URI url, IProgressMonitor monitor) {
    List<IServerExtension> list = new ArrayList<IServerExtension>();
    IQueryResult<IInstallableUnit> collector = repo.query(query, monitor);
    for (IInstallableUnit iu : collector.toUnmodifiableSet()) {
        Collection<IRequirement> req = iu.getRequirements();
        if (req != null) {
            for (IRequirement requirement : req) {
                IMatchExpression<IInstallableUnit> matches = requirement.getMatches();
                query = new ExpressionMatchQuery<IInstallableUnit>(IInstallableUnit.class, matches);
                IQueryResult<IInstallableUnit> collector2 = repo.query(query, monitor);
                Iterator<IInstallableUnit> iter2 = collector2.iterator();
                while (iter2.hasNext()) {
                    IInstallableUnit iu2 = iter2.next();
                    if (!list.contains(iu2)) {
                        Extension ext = new Extension(iu2, url);
                        list.add(ext);
                    }
                }
            }
        }
    }
    return list;
}
Also used : IRequirement(org.eclipse.equinox.p2.metadata.IRequirement) IInstallableUnit(org.eclipse.equinox.p2.metadata.IInstallableUnit)

Example 3 with IQuery

use of org.eclipse.equinox.p2.query.IQuery in project webtools.servertools by eclipse.

the class ExtensionUtility method getExistingFeatures.

private static List<Extension> getExistingFeatures(IProgressMonitor monitor) throws CoreException {
    monitor.beginTask(Messages.discoverLocalConfiguration, 100);
    IProfileRegistry profileRegistry = (IProfileRegistry) getService(Activator.getDefault().getBundle().getBundleContext(), IProfileRegistry.class.getName());
    IProfile[] profiles = profileRegistry.getProfiles();
    IProfile profile = profileRegistry.getProfile(IProfileRegistry.SELF);
    if (profile == null) {
        // it happens sometime , possibility of bug in profileRegistry
        for (int i = 0; i < profiles.length; i++) {
            if (profiles[i].getProfileId().equals(IProfileRegistry.SELF)) {
                profile = profiles[i];
                break;
            }
        }
    }
    List<Extension> list = new ArrayList<Extension>();
    if (profile == null)
        return list;
    IQuery<IInstallableUnit> query = QueryUtil.createIUAnyQuery();
    // Query query = new InstallableUnitQuery("org.eclipse.wst.server.core.serverAdapter");
    // List<String> list2 = new ArrayList();
    // Query query = new ExtensionInstallableUnitQuery(list2);
    IQueryResult<IInstallableUnit> collector = profile.query(query, monitor);
    Iterator<IInstallableUnit> iter = collector.iterator();
    while (iter.hasNext()) {
        IInstallableUnit iu = iter.next();
        if (!list.contains(iu))
            list.add(new Extension(iu, null));
    }
    monitor.done();
    return list;
}
Also used : IProfileRegistry(org.eclipse.equinox.p2.engine.IProfileRegistry) IInstallableUnit(org.eclipse.equinox.p2.metadata.IInstallableUnit) IProfile(org.eclipse.equinox.p2.engine.IProfile)

Example 4 with IQuery

use of org.eclipse.equinox.p2.query.IQuery in project webtools.servertools by eclipse.

the class ExtensionUpdateSite method getExtensions.

public List<IServerExtension> getExtensions(IProgressMonitor monitor) throws CoreException, ProvisionException {
    URI url2 = null;
    IMetadataRepositoryManager manager = null;
    IProvisioningAgent agent = null;
    List<IServerExtension> list = new ArrayList<IServerExtension>();
    URI[] existingSites = null;
    try {
        /*
			 * To discovery the server adapter, there are three methods:
			 * 1. Looking at the site.xml (if it exists). This is the legacy method
			 * 2. Looking for the org.eclipse.wst.server.core.serverAdapter property in a p2
			 *    update site (that may not have a site.xml). The property is necessary to identify
			 *    the InstallableUnit as a server type. Otherwise, all the InstallableUnits will show
			 *    up regardless of whether it is a server or not
			 * 3. If the user created the p2 update site using a category.xml file (migrating old site.xml
			 *    to use category.xml)
			 */
        BundleContext bd = org.eclipse.wst.server.discovery.internal.Activator.getDefault().getBundle().getBundleContext();
        agent = ExtensionUtility.getAgent(bd);
        url2 = new URI(url);
        // Method 1: Looking at the site.xml
        UpdateSiteMetadataRepositoryFactory mrf = new UpdateSiteMetadataRepositoryFactory();
        mrf.setAgent(ExtensionUtility.getAgent(bd));
        manager = (IMetadataRepositoryManager) agent.getService(IMetadataRepositoryManager.SERVICE_NAME);
        // Sites already existing for both enabled and disabled
        URI[] existingSitesAll = manager.getKnownRepositories(IMetadataRepositoryManager.REPOSITORIES_ALL);
        URI[] existingSitesDisabled = manager.getKnownRepositories(IMetadataRepositoryManager.REPOSITORIES_DISABLED);
        int existingSitesAllLen = existingSitesAll == null ? 0 : existingSitesAll.length;
        int existingSitesDisabledLen = existingSitesDisabled == null ? 0 : existingSitesDisabled.length;
        existingSites = new URI[existingSitesAllLen + existingSitesDisabledLen];
        if (existingSitesAllLen > 0) {
            System.arraycopy(existingSitesAll, 0, existingSites, 0, existingSitesAllLen);
        }
        if (existingSitesDisabledLen > 0) {
            System.arraycopy(existingSitesDisabled, 0, existingSites, existingSitesAllLen, existingSitesDisabledLen);
        }
        // If the site.xml does not exist, the load will throw a org.eclipse.equinox.p2.core.ProvisionException
        try {
            IMetadataRepository repo = mrf.load(url2, IRepositoryManager.REPOSITORIES_ALL, monitor);
            // $NON-NLS-1$
            IQuery<IInstallableUnit> query = QueryUtil.createMatchQuery("id ~=/*org.eclipse.wst.server.core.serverAdapter/");
            list = getInstallableUnits(repo, query, url2, monitor);
        } catch (ProvisionException pe) {
            // $NON-NLS-1$
            Trace.trace(Trace.WARNING, "Error getting update site information", pe);
        }
        // specifying any server adapters there or no site.xml exists)
        if (list.isEmpty()) {
            manager.addRepository(url2);
            // Need to query for all IUs
            IQuery<IInstallableUnit> query = QueryUtil.createIUAnyQuery();
            IMetadataRepository repo = manager.loadRepository(url2, monitor);
            List<IServerExtension> list2 = getInstallableUnits(repo, query, url2, monitor);
            int size = list2.size();
            for (int i = 0; i < size; i++) {
                Extension e = (Extension) list2.get(i);
                IInstallableUnit[] iuArr = e.getIUs();
                if (iuArr != null && iuArr.length > 0) {
                    if (iuArr[0] != null) {
                        if (iuArr[0].getProperty(SERVER_ADAPTER_ID) != null) {
                            list.add(e);
                        }
                    }
                }
            }
        }
        // a provider property with org.eclipse.wst.server.core.serverAdapter
        if (list.isEmpty()) {
            manager = (IMetadataRepositoryManager) agent.getService(IMetadataRepositoryManager.SERVICE_NAME);
            manager.addRepository(url2);
            // $NON-NLS-1$
            IQuery<IInstallableUnit> query = QueryUtil.createMatchQuery("id ~=/*org.eclipse.wst.server.core.serverAdapter/");
            IMetadataRepository repo = manager.loadRepository(url2, monitor);
            list = getInstallableUnits(repo, query, url2, monitor);
        }
        return list;
    } catch (ProvisionException e) {
        // $NON-NLS-1$
        Trace.trace(Trace.WARNING, "Error getting update info", e);
        throw e;
    } catch (Exception e) {
        // $NON-NLS-1$
        Trace.trace(Trace.WARNING, "Error getting update info", e);
        return new ArrayList<IServerExtension>(0);
    } finally {
        if (url2 != null && url2.getPath().length() != 0 && manager != null) {
            if (existingSites != null && existingSites.length > 0) {
                boolean urlExists = false;
                for (URI uri : existingSites) {
                    if (uri.getPath().equals(url2.getPath())) {
                        urlExists = true;
                        break;
                    }
                }
                // If site did not exist before, remove it as it was added with load
                if (!urlExists) {
                    manager.removeRepository(url2);
                }
            }
        }
    }
}
Also used : IMetadataRepositoryManager(org.eclipse.equinox.p2.repository.metadata.IMetadataRepositoryManager) IProvisioningAgent(org.eclipse.equinox.p2.core.IProvisioningAgent) URI(java.net.URI) CoreException(org.eclipse.core.runtime.CoreException) ProvisionException(org.eclipse.equinox.p2.core.ProvisionException) ProvisionException(org.eclipse.equinox.p2.core.ProvisionException) UpdateSiteMetadataRepositoryFactory(org.eclipse.equinox.internal.p2.updatesite.metadata.UpdateSiteMetadataRepositoryFactory) IInstallableUnit(org.eclipse.equinox.p2.metadata.IInstallableUnit) IMetadataRepository(org.eclipse.equinox.p2.repository.metadata.IMetadataRepository) BundleContext(org.osgi.framework.BundleContext)

Example 5 with IQuery

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

the class AbstractProvisioningOperation 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.
 */
protected 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.createLatestQuery(QueryUtil.createIUGroupQuery());
        IQueryResult<IInstallableUnit> result = repository.query(query, monitor.newChild(1));
        for (IInstallableUnit iu : result) {
            String id = iu.getId();
            if (installableUnitIdsThisRepository.contains(id)) {
                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)11 ArrayList (java.util.ArrayList)5 IMetadataRepository (org.eclipse.equinox.p2.repository.metadata.IMetadataRepository)5 URI (java.net.URI)2 CoreException (org.eclipse.core.runtime.CoreException)2 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)2 ProvisionException (org.eclipse.equinox.p2.core.ProvisionException)2 IProfile (org.eclipse.equinox.p2.engine.IProfile)2 IQuery (org.eclipse.equinox.p2.query.IQuery)2 IMetadataRepositoryManager (org.eclipse.equinox.p2.repository.metadata.IMetadataRepositoryManager)2 URISyntaxException (java.net.URISyntaxException)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1 MultiStatus (org.eclipse.core.runtime.MultiStatus)1 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)1 OperationCanceledException (org.eclipse.core.runtime.OperationCanceledException)1 ConcurrentTaskManager (org.eclipse.epp.internal.mpc.ui.util.ConcurrentTaskManager)1 INode (org.eclipse.epp.mpc.core.model.INode)1 LocalMetadataRepository (org.eclipse.equinox.internal.p2.metadata.repository.LocalMetadataRepository)1