Search in sources :

Example 6 with ProfileChangeOperation

use of org.eclipse.equinox.p2.operations.ProfileChangeOperation in project epp.mpc by eclipse.

the class CompositeProfileChangeOperation method computeProfileChangeRequest.

@Override
protected void computeProfileChangeRequest(MultiStatus status, IProgressMonitor monitor) {
    ProfileChangeRequest request = ProfileChangeRequest.createByProfileId(session.getProvisioningAgent(), getProfileId());
    SubMonitor progress = SubMonitor.convert(monitor, 1000 * operations.size());
    for (ProfileChangeOperation operation : operations) {
        updateRequest(request, operation, status, progress.newChild(1000));
    }
    try {
        // $NON-NLS-1$
        Field requestField = ProfileChangeOperation.class.getDeclaredField("request");
        boolean accessible = requestField.isAccessible();
        try {
            requestField.setAccessible(true);
            requestField.set(this, request);
        } finally {
            requestField.setAccessible(accessible);
        }
    } catch (Exception e) {
        status.add(new Status(IStatus.ERROR, MarketplaceClientUi.BUNDLE_ID, Messages.CompositeProfileChangeOperation_ChangeRequestError, e));
    }
}
Also used : ProfileChangeOperation(org.eclipse.equinox.p2.operations.ProfileChangeOperation) MultiStatus(org.eclipse.core.runtime.MultiStatus) Status(org.eclipse.core.runtime.Status) IStatus(org.eclipse.core.runtime.IStatus) Field(java.lang.reflect.Field) SubMonitor(org.eclipse.core.runtime.SubMonitor) IProfileChangeRequest(org.eclipse.equinox.p2.planner.IProfileChangeRequest) ProfileChangeRequest(org.eclipse.equinox.internal.p2.director.ProfileChangeRequest)

Example 7 with ProfileChangeOperation

use of org.eclipse.equinox.p2.operations.ProfileChangeOperation 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

IStatus (org.eclipse.core.runtime.IStatus)4 ProfileChangeOperation (org.eclipse.equinox.p2.operations.ProfileChangeOperation)4 InvocationTargetException (java.lang.reflect.InvocationTargetException)3 RemediationOperation (org.eclipse.equinox.p2.operations.RemediationOperation)3 URI (java.net.URI)2 ArrayList (java.util.ArrayList)2 HashSet (java.util.HashSet)2 Map (java.util.Map)2 CoreException (org.eclipse.core.runtime.CoreException)2 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)2 Status (org.eclipse.core.runtime.Status)2 SubMonitor (org.eclipse.core.runtime.SubMonitor)2 ProfileChangeRequest (org.eclipse.equinox.internal.p2.director.ProfileChangeRequest)2 IInstallableUnit (org.eclipse.equinox.p2.metadata.IInstallableUnit)2 ProvisioningJob (org.eclipse.equinox.p2.operations.ProvisioningJob)2 UninstallOperation (org.eclipse.equinox.p2.operations.UninstallOperation)2 IProfileChangeRequest (org.eclipse.equinox.p2.planner.IProfileChangeRequest)2 IWizardContainer (org.eclipse.jface.wizard.IWizardContainer)2 Field (java.lang.reflect.Field)1 URISyntaxException (java.net.URISyntaxException)1