diff options
author | irbull | 2011-10-17 22:46:26 +0000 |
---|---|---|
committer | irbull | 2011-10-17 22:46:26 +0000 |
commit | 60787e0502dcc0bb28da95ca2d989fe7892e765f (patch) | |
tree | 9a52090ae2a5502ee55031f40ac125cf6553cbe2 /bundles/org.eclipse.equinox.p2.operations | |
parent | e33a37cf824abdbbe2044b738f664d2527e7a79c (diff) | |
download | rt.equinox.p2-60787e0502dcc0bb28da95ca2d989fe7892e765f.tar.gz rt.equinox.p2-60787e0502dcc0bb28da95ca2d989fe7892e765f.tar.xz rt.equinox.p2-60787e0502dcc0bb28da95ca2d989fe7892e765f.zip |
Bug 261928 : Adds a Relaxed Constraint Optionv20111017-2246
This will relax the constraints when an update / install fails. This
allows a user to try again with a slighly different provisioning plan.
This is just the start of this work, but it should give us a chance to
test it out and make changes in future builds.
Diffstat (limited to 'bundles/org.eclipse.equinox.p2.operations')
4 files changed, 118 insertions, 0 deletions
diff --git a/bundles/org.eclipse.equinox.p2.operations/META-INF/MANIFEST.MF b/bundles/org.eclipse.equinox.p2.operations/META-INF/MANIFEST.MF index 5d72f5d83..0c930e7aa 100644 --- a/bundles/org.eclipse.equinox.p2.operations/META-INF/MANIFEST.MF +++ b/bundles/org.eclipse.equinox.p2.operations/META-INF/MANIFEST.MF @@ -16,6 +16,7 @@ Bundle-RequiredExecutionEnvironment: J2SE-1.5, Bundle-ActivationPolicy: lazy Import-Package: org.eclipse.equinox.internal.p2.core.helpers, org.eclipse.equinox.internal.p2.director, + org.eclipse.equinox.internal.p2.metadata.query, org.eclipse.equinox.internal.p2.repository.helpers, org.eclipse.equinox.internal.provisional.configurator, org.eclipse.equinox.internal.provisional.p2.core.eventbus, diff --git a/bundles/org.eclipse.equinox.p2.operations/src/org/eclipse/equinox/internal/p2/operations/Messages.java b/bundles/org.eclipse.equinox.p2.operations/src/org/eclipse/equinox/internal/p2/operations/Messages.java index b170e415c..918011323 100644 --- a/bundles/org.eclipse.equinox.p2.operations/src/org/eclipse/equinox/internal/p2/operations/Messages.java +++ b/bundles/org.eclipse.equinox.p2.operations/src/org/eclipse/equinox/internal/p2/operations/Messages.java @@ -66,6 +66,9 @@ public class Messages extends NLS { public static String UpdateOperation_ResolveJobName; public static String UpdateOperation_UpdateJobName; + public static String RelaxedUpdateOperation_ResolveJobName; + public static String RelaxedUpdateOperation_UpdateJobName; + public static String OperationFactory_noAgent; public static String OperationFactory_noIUFound; diff --git a/bundles/org.eclipse.equinox.p2.operations/src/org/eclipse/equinox/internal/p2/operations/messages.properties b/bundles/org.eclipse.equinox.p2.operations/src/org/eclipse/equinox/internal/p2/operations/messages.properties index 48fa2ae64..2d2253ea5 100644 --- a/bundles/org.eclipse.equinox.p2.operations/src/org/eclipse/equinox/internal/p2/operations/messages.properties +++ b/bundles/org.eclipse.equinox.p2.operations/src/org/eclipse/equinox/internal/p2/operations/messages.properties @@ -42,6 +42,9 @@ UninstallOperation_ResolveJobName=Calculating Uninstall Validity UpdateOperation_ProfileChangeRequestProgress=Computing update request UpdateOperation_ResolveJobName=Computing Update Requirements UpdateOperation_UpdateJobName=Updating Software +RelaxedUpdateOperation_ResolveJobName=Computing Update Requirements +RelaxedUpdateOperation_UpdateJobName=Updating Software + OperationFactory_noAgent=This installation has not been configured properly. No provisioning agent can be found. OperationFactory_noIUFound=No IU could be found for {0}.
\ No newline at end of file diff --git a/bundles/org.eclipse.equinox.p2.operations/src/org/eclipse/equinox/p2/operations/RelaxedUpdateInstallOperation.java b/bundles/org.eclipse.equinox.p2.operations/src/org/eclipse/equinox/p2/operations/RelaxedUpdateInstallOperation.java new file mode 100644 index 000000000..a0e20dd60 --- /dev/null +++ b/bundles/org.eclipse.equinox.p2.operations/src/org/eclipse/equinox/p2/operations/RelaxedUpdateInstallOperation.java @@ -0,0 +1,111 @@ +package org.eclipse.equinox.p2.operations; + +import java.util.*; +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.core.runtime.MultiStatus; +import org.eclipse.equinox.internal.p2.director.ProfileChangeRequest; +import org.eclipse.equinox.internal.p2.metadata.query.UpdateQuery; +import org.eclipse.equinox.internal.p2.operations.Messages; +import org.eclipse.equinox.p2.engine.*; +import org.eclipse.equinox.p2.engine.query.IUProfilePropertyQuery; +import org.eclipse.equinox.p2.metadata.*; +import org.eclipse.equinox.p2.planner.*; +import org.eclipse.equinox.p2.query.*; + +/** + * An operation that updates IUs with relaxed p2 constraints + * + * @noinstantiate This class is not intended to be instantiated by clients. + * @noreference + */ +public class RelaxedUpdateInstallOperation extends ProfileChangeOperation { + + public RelaxedUpdateInstallOperation(ProvisioningSession session) { + super(session); + } + + @Override + protected void computeProfileChangeRequest(MultiStatus status, IProgressMonitor monitor) { + IProfileRegistry profileRegistry = (IProfileRegistry) session.getProvisioningAgent().getService(IProfileRegistry.SERVICE_NAME); + IPlanner plan = (IPlanner) session.getProvisioningAgent().getService(IPlanner.SERVICE_NAME); + IProfile prof = profileRegistry.getProfile(getProfileId()); + + final String INCLUSION_RULES = "org.eclipse.equinox.p2.internal.inclusion.rules"; //$NON-NLS-1$ + final String INCLUSION_OPTIONAL = "OPTIONAL"; //$NON-NLS-1$ + final String INCLUSION_STRICT = "STRICT"; //$NON-NLS-1$ + + IQueryResult<IInstallableUnit> strictRoots = prof.query(new IUProfilePropertyQuery(INCLUSION_RULES, INCLUSION_STRICT), null); + IQueryResult<IInstallableUnit> optionalRoots = prof.query(new IUProfilePropertyQuery(INCLUSION_RULES, INCLUSION_OPTIONAL), null); + Set<IInstallableUnit> tmpRoots = new HashSet<IInstallableUnit>(strictRoots.toUnmodifiableSet()); + tmpRoots.addAll(optionalRoots.toUnmodifiableSet()); + CollectionResult<IInstallableUnit> allRoots = new CollectionResult<IInstallableUnit>(tmpRoots); + + request = (ProfileChangeRequest) plan.createChangeRequest(prof); + Collection<IRequirement> limitingRequirements = new ArrayList<IRequirement>(); + + for (Iterator<IInstallableUnit> iterator = allRoots.query(QueryUtil.ALL_UNITS, null).iterator(); iterator.hasNext();) { + IInstallableUnit currentlyInstalled = iterator.next(); + + //find all the potential updates for the currentlyInstalled iu + IQueryResult<IInstallableUnit> updatesAvailable = plan.updatesFor(currentlyInstalled, context, null); + for (Iterator<IInstallableUnit> iterator2 = updatesAvailable.iterator(); iterator2.hasNext();) { + IInstallableUnit update = iterator2.next(); + request.add(update); + request.setInstallableUnitInclusionRules(update, ProfileInclusionRules.createOptionalInclusionRule(update)); + } + if (!updatesAvailable.isEmpty()) { + //force the original IU to optional, but make sure that the solution at least includes it + request.setInstallableUnitInclusionRules(currentlyInstalled, ProfileInclusionRules.createOptionalInclusionRule(currentlyInstalled)); + limitingRequirements.add(MetadataFactory.createRequirement(IInstallableUnit.NAMESPACE_IU_ID, currentlyInstalled.getId(), new VersionRange(currentlyInstalled.getVersion(), true, Version.MAX_VERSION, true), null, false, false)); + } + } + + IProvisioningPlan updateFinderPlan = plan.getProvisioningPlan(request, context, null); + if (updateFinderPlan.getAdditions().query(QueryUtil.ALL_UNITS, null).isEmpty()) { + return; + } + + //Take into account all the removals + IProfileChangeRequest finalChangeRequest = plan.createChangeRequest(prof); + IQueryResult<IInstallableUnit> removals = updateFinderPlan.getRemovals().query(QueryUtil.ALL_UNITS, null); + for (Iterator<IInstallableUnit> iterator = removals.iterator(); iterator.hasNext();) { + IInstallableUnit iu = iterator.next(); + if (!allRoots.query(QueryUtil.createIUQuery(iu), null).isEmpty()) { + finalChangeRequest.remove(iu); + } + } + + //Take into account the additions for stricts + for (Iterator<IInstallableUnit> iterator = strictRoots.iterator(); iterator.hasNext();) { + IInstallableUnit formerRoot = iterator.next(); + IQueryResult<IInstallableUnit> update = updateFinderPlan.getAdditions().query(new UpdateQuery(formerRoot), null); + if (!update.isEmpty()) + finalChangeRequest.addAll(update.toUnmodifiableSet()); + } + + //Take into account the additions for optionals + for (Iterator<IInstallableUnit> iterator = optionalRoots.iterator(); iterator.hasNext();) { + IInstallableUnit formerRoot = iterator.next(); + IQueryResult<IInstallableUnit> update = updateFinderPlan.getAdditions().query(new UpdateQuery(formerRoot), null); + if (!update.isEmpty()) { + for (Iterator<IInstallableUnit> it = update.iterator(); it.hasNext();) { + IInstallableUnit updatedOptionalIU = it.next(); + finalChangeRequest.add(updatedOptionalIU); + finalChangeRequest.setInstallableUnitInclusionRules(updatedOptionalIU, ProfileInclusionRules.createOptionalInclusionRule(updatedOptionalIU)); + } + } + } + //return planner.getProvisioningPlan(finalChangeRequest, context, null); + } + + @Override + protected String getResolveJobName() { + return Messages.RelaxedUpdateOperation_ResolveJobName; + } + + @Override + protected String getProvisioningJobName() { + return Messages.RelaxedUpdateOperation_UpdateJobName; + } + +}
\ No newline at end of file |