Search in sources :

Example 6 with IProfile

use of org.eclipse.equinox.p2.engine.IProfile 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 7 with IProfile

use of org.eclipse.equinox.p2.engine.IProfile in project webtools.servertools by eclipse.

the class Extension method getProvisioningPlan.

public IProvisioningPlan getProvisioningPlan(boolean explain, IProgressMonitor monitor) {
    if (plan != null)
        return plan;
    // long time = System.currentTimeMillis();
    BundleContext bundleContext = Activator.getDefault().getBundle().getBundleContext();
    IPlanner planner = (IPlanner) ExtensionUtility.getService(bundleContext, IPlanner.SERVICE_NAME);
    IProfileRegistry profileRegistry = (IProfileRegistry) ExtensionUtility.getService(bundleContext, IProfileRegistry.SERVICE_NAME);
    IProfile profile = profileRegistry.getProfile(IProfileRegistry.SELF);
    IProfile[] profiles = profileRegistry.getProfiles();
    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;
            }
        }
    }
    if (profile == null)
        return null;
    IProfileChangeRequest pcr = planner.createChangeRequest(profile);
    pcr.add(iu);
    IProvisioningAgent agent = ExtensionUtility.getAgent(bundleContext);
    if (agent == null) {
        return null;
    }
    // Get all the known repositories when installing the server adapter.
    // If these repositories are not added, it can cause install problems if
    // the server adapter relies on the list of available software install sites
    URI[] knownRepositories = null;
    IMetadataRepositoryManager manager = (IMetadataRepositoryManager) agent.getService(IMetadataRepositoryManager.SERVICE_NAME);
    if (manager != null) {
        manager.addRepository(uri);
        // Note: IRepositoryManager.REPOSITORIES_ALL will exclude the deselected update sites
        knownRepositories = manager.getKnownRepositories(IRepositoryManager.REPOSITORIES_ALL);
        // A fall back in case known repositories returns null
        if (knownRepositories == null) {
            knownRepositories = new URI[] { uri };
        }
    } else {
        knownRepositories = new URI[] { uri };
    }
    provContext = new ProvisioningContext(agent);
    // Add the new URLs to both the Metadata and Artifact repositories.
    // Note: only the IInstallableUnit that is passed into this class will be installed
    // as a server adapter. For example, if multiple update site URLs for discovery server
    // adapters are present, they will not be installed.
    provContext.setMetadataRepositories(knownRepositories);
    provContext.setArtifactRepositories(knownRepositories);
    if (!explain)
        // $NON-NLS-1$ //$NON-NLS-2$
        provContext.setProperty("org.eclipse.equinox.p2.director.explain", "false");
    // $NON-NLS-1$
    provContext.setProperty(ProvisioningContext.FOLLOW_REPOSITORY_REFERENCES, "true");
    plan = planner.getProvisioningPlan(pcr, provContext, monitor);
    // System.out.println("Time: " + (System.currentTimeMillis() - time)); // TODO
    return plan;
}
Also used : IMetadataRepositoryManager(org.eclipse.equinox.p2.repository.metadata.IMetadataRepositoryManager) IProvisioningAgent(org.eclipse.equinox.p2.core.IProvisioningAgent) IPlanner(org.eclipse.equinox.p2.planner.IPlanner) IProfileChangeRequest(org.eclipse.equinox.p2.planner.IProfileChangeRequest) URI(java.net.URI) BundleContext(org.osgi.framework.BundleContext)

Example 8 with IProfile

use of org.eclipse.equinox.p2.engine.IProfile 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 9 with IProfile

use of org.eclipse.equinox.p2.engine.IProfile in project archi by archimatetool.

the class P2Handler method getInstalledFeatures.

List<IInstallableUnit> getInstalledFeatures() throws ProvisionException {
    IProfile profile = getDefaultProfile();
    ArrayList<IInstallableUnit> list = new ArrayList<IInstallableUnit>();
    IQuery<IInstallableUnit> query = QueryUtil.createIUGroupQuery();
    IQueryResult<IInstallableUnit> queryResult = profile.query(query, null);
    for (IInstallableUnit feature : queryResult) {
        if (!isInternalFeature(feature)) {
            list.add(feature);
        }
    }
    return list;
}
Also used : ArrayList(java.util.ArrayList) IInstallableUnit(org.eclipse.equinox.p2.metadata.IInstallableUnit) IProfile(org.eclipse.equinox.p2.engine.IProfile)

Aggregations

IProfile (org.eclipse.equinox.p2.engine.IProfile)7 IProfileRegistry (org.eclipse.equinox.p2.engine.IProfileRegistry)6 IProvisioningAgent (org.eclipse.equinox.p2.core.IProvisioningAgent)5 IInstallableUnit (org.eclipse.equinox.p2.metadata.IInstallableUnit)3 BundleContext (org.osgi.framework.BundleContext)3 IStatus (org.eclipse.core.runtime.IStatus)2 File (java.io.File)1 InputStream (java.io.InputStream)1 URI (java.net.URI)1 Path (java.nio.file.Path)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 TarArchiveInputStream (org.apache.commons.compress.archivers.tar.TarArchiveInputStream)1 BZip2CompressorInputStream (org.apache.commons.compress.compressors.bzip2.BZip2CompressorInputStream)1 GzipCompressorInputStream (org.apache.commons.compress.compressors.gzip.GzipCompressorInputStream)1 XZCompressorInputStream (org.apache.commons.compress.compressors.xz.XZCompressorInputStream)1 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)1 Status (org.eclipse.core.runtime.Status)1 SubMonitor (org.eclipse.core.runtime.SubMonitor)1 IJobChangeEvent (org.eclipse.core.runtime.jobs.IJobChangeEvent)1