Search in sources :

Example 1 with IProfileChangeRequest

use of org.eclipse.equinox.p2.planner.IProfileChangeRequest 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 2 with IProfileChangeRequest

use of org.eclipse.equinox.p2.planner.IProfileChangeRequest in project epp.mpc by eclipse.

the class CompositeProfileChangeOperation method updateRequest.

private void updateRequest(ProfileChangeRequest request, ProfileChangeOperation operation, MultiStatus status, IProgressMonitor monitor) {
    // TODO we do too much here - this already does the plan resolution, which is expensive...
    IStatus result = operation.resolveModal(monitor);
    status.merge(result);
    if (status.getSeverity() != IStatus.ERROR) {
        IProfileChangeRequest operationChangeRequest = operation.getProfileChangeRequest();
        Collection<IInstallableUnit> additions = operationChangeRequest.getAdditions();
        Collection<IInstallableUnit> removals = operationChangeRequest.getRemovals();
        Collection<IRequirement> extraRequirements = operationChangeRequest.getExtraRequirements();
        request.removeAll(removals);
        request.addAll(additions);
        if (extraRequirements != null) {
            request.addExtraRequirements(extraRequirements);
        }
        if (operationChangeRequest instanceof ProfileChangeRequest) {
            ProfileChangeRequest internalRequest = (ProfileChangeRequest) operationChangeRequest;
            Map<IInstallableUnit, List<String>> installableUnitProfilePropertiesToRemove = internalRequest.getInstallableUnitProfilePropertiesToRemove();
            for (Entry<IInstallableUnit, List<String>> entry : installableUnitProfilePropertiesToRemove.entrySet()) {
                List<String> properties = entry.getValue();
                if (properties != null && !properties.isEmpty()) {
                    IInstallableUnit iu = entry.getKey();
                    for (String property : properties) {
                        request.removeInstallableUnitProfileProperty(iu, property);
                    }
                }
            }
            Map<IInstallableUnit, Map<String, String>> installableUnitProfilePropertiesToAdd = internalRequest.getInstallableUnitProfilePropertiesToAdd();
            for (Entry<IInstallableUnit, Map<String, String>> entry : installableUnitProfilePropertiesToAdd.entrySet()) {
                Map<String, String> properties = entry.getValue();
                if (properties != null && !properties.isEmpty()) {
                    IInstallableUnit iu = entry.getKey();
                    for (Entry<String, String> property : properties.entrySet()) {
                        request.setInstallableUnitProfileProperty(iu, property.getKey(), property.getValue());
                    }
                }
            }
            String[] propertiesToRemove = internalRequest.getPropertiesToRemove();
            for (String property : propertiesToRemove) {
                request.removeProfileProperty(property);
            }
            Map<String, String> propertiesToAdd = internalRequest.getPropertiesToAdd();
            for (Entry<String, String> property : propertiesToAdd.entrySet()) {
                request.setProfileProperty(property.getKey(), property.getValue());
            }
        }
    }
}
Also used : IRequirement(org.eclipse.equinox.p2.metadata.IRequirement) IStatus(org.eclipse.core.runtime.IStatus) IProfileChangeRequest(org.eclipse.equinox.p2.planner.IProfileChangeRequest) IProfileChangeRequest(org.eclipse.equinox.p2.planner.IProfileChangeRequest) ProfileChangeRequest(org.eclipse.equinox.internal.p2.director.ProfileChangeRequest) IInstallableUnit(org.eclipse.equinox.p2.metadata.IInstallableUnit) ArrayList(java.util.ArrayList) List(java.util.List) Map(java.util.Map)

Aggregations

IProfileChangeRequest (org.eclipse.equinox.p2.planner.IProfileChangeRequest)2 URI (java.net.URI)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Map (java.util.Map)1 IStatus (org.eclipse.core.runtime.IStatus)1 ProfileChangeRequest (org.eclipse.equinox.internal.p2.director.ProfileChangeRequest)1 IProvisioningAgent (org.eclipse.equinox.p2.core.IProvisioningAgent)1 IInstallableUnit (org.eclipse.equinox.p2.metadata.IInstallableUnit)1 IRequirement (org.eclipse.equinox.p2.metadata.IRequirement)1 IPlanner (org.eclipse.equinox.p2.planner.IPlanner)1 IMetadataRepositoryManager (org.eclipse.equinox.p2.repository.metadata.IMetadataRepositoryManager)1 BundleContext (org.osgi.framework.BundleContext)1