Search in sources :

Example 1 with ProfileChangeRequest

use of org.eclipse.equinox.internal.p2.director.ProfileChangeRequest 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 2 with ProfileChangeRequest

use of org.eclipse.equinox.internal.p2.director.ProfileChangeRequest 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)2 ProfileChangeRequest (org.eclipse.equinox.internal.p2.director.ProfileChangeRequest)2 IProfileChangeRequest (org.eclipse.equinox.p2.planner.IProfileChangeRequest)2 Field (java.lang.reflect.Field)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Map (java.util.Map)1 MultiStatus (org.eclipse.core.runtime.MultiStatus)1 Status (org.eclipse.core.runtime.Status)1 SubMonitor (org.eclipse.core.runtime.SubMonitor)1 IInstallableUnit (org.eclipse.equinox.p2.metadata.IInstallableUnit)1 IRequirement (org.eclipse.equinox.p2.metadata.IRequirement)1 ProfileChangeOperation (org.eclipse.equinox.p2.operations.ProfileChangeOperation)1