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));
}
}
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());
}
}
}
}
Aggregations