diff options
author | Pascal Rapicault | 2010-02-11 15:44:28 +0000 |
---|---|---|
committer | Pascal Rapicault | 2010-02-11 15:44:28 +0000 |
commit | 6cea88679a7f7c0f44a98f299db25ad4059a0327 (patch) | |
tree | c2eb9e6c512424b7f6a86791c8cc2b6fdaef4571 /bundles/org.eclipse.equinox.p2.director/src/org/eclipse/equinox/internal/p2 | |
parent | dbcb0f62a616280180e7714169fe5e86fb743d4a (diff) | |
download | rt.equinox.p2-6cea88679a7f7c0f44a98f299db25ad4059a0327.tar.gz rt.equinox.p2-6cea88679a7f7c0f44a98f299db25ad4059a0327.tar.xz rt.equinox.p2-6cea88679a7f7c0f44a98f299db25ad4059a0327.zip |
Initial release of the planner API
Diffstat (limited to 'bundles/org.eclipse.equinox.p2.director/src/org/eclipse/equinox/internal/p2')
5 files changed, 94 insertions, 80 deletions
diff --git a/bundles/org.eclipse.equinox.p2.director/src/org/eclipse/equinox/internal/p2/director/DirectorComponent.java b/bundles/org.eclipse.equinox.p2.director/src/org/eclipse/equinox/internal/p2/director/DirectorComponent.java index 2ab6904af..08935c47a 100644 --- a/bundles/org.eclipse.equinox.p2.director/src/org/eclipse/equinox/internal/p2/director/DirectorComponent.java +++ b/bundles/org.eclipse.equinox.p2.director/src/org/eclipse/equinox/internal/p2/director/DirectorComponent.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2009 IBM Corporation and others. + * Copyright (c) 2009-2010 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -7,10 +7,12 @@ * * Contributors: * IBM Corporation - initial API and implementation + * Sonatype, Inc. - ongoing development *******************************************************************************/ package org.eclipse.equinox.internal.p2.director; -import org.eclipse.equinox.internal.provisional.p2.director.IPlanner; +import org.eclipse.equinox.p2.planner.IPlanner; + import org.eclipse.equinox.p2.core.IProvisioningAgent; import org.eclipse.equinox.p2.core.spi.IAgentServiceFactory; import org.eclipse.equinox.p2.engine.IEngine; diff --git a/bundles/org.eclipse.equinox.p2.director/src/org/eclipse/equinox/internal/p2/director/Projector.java b/bundles/org.eclipse.equinox.p2.director/src/org/eclipse/equinox/internal/p2/director/Projector.java index 69aaa00d8..54d5191d0 100644 --- a/bundles/org.eclipse.equinox.p2.director/src/org/eclipse/equinox/internal/p2/director/Projector.java +++ b/bundles/org.eclipse.equinox.p2.director/src/org/eclipse/equinox/internal/p2/director/Projector.java @@ -8,6 +8,7 @@ * Daniel Le Berre - Fix in the encoding and the optimization function * Alban Browaeys - Optimized string concatenation in bug 251357 * Jed Anderson - switch from opb files to API calls to DependencyHelper in bug 200380 + * Sonatype, Inc. - ongoing development ******************************************************************************/ package org.eclipse.equinox.internal.p2.director; @@ -140,7 +141,7 @@ public class Projector { return !lastState.query(new InstallableUnitQuery(iu), null).isEmpty(); } - public void encode(IInstallableUnit entryPointIU, IInstallableUnit[] alreadyExistingRoots, IQueryable<IInstallableUnit> installedIUs, IInstallableUnit[] newRoots, IProgressMonitor monitor) { + public void encode(IInstallableUnit entryPointIU, IInstallableUnit[] alreadyExistingRoots, IQueryable<IInstallableUnit> installedIUs, Collection<IInstallableUnit> newRoots, IProgressMonitor monitor) { alreadyInstalledIUs = Arrays.asList(alreadyExistingRoots); lastState = installedIUs; this.entryPoint = entryPointIU; @@ -181,7 +182,7 @@ public class Projector { } createConstraintsForSingleton(); - createMustHave(entryPointIU, alreadyExistingRoots, newRoots); + createMustHave(entryPointIU, alreadyExistingRoots); createOptimizationFunction(entryPointIU, newRoots); if (DEBUG) { @@ -199,7 +200,7 @@ public class Projector { } //Create an optimization function favoring the highest version of each IU - private void createOptimizationFunction(IInstallableUnit metaIu, IInstallableUnit[] newRoots) { + private void createOptimizationFunction(IInstallableUnit metaIu, Collection<IInstallableUnit> newRoots) { List<WeightedObject<? extends Object>> weightedObjects = new ArrayList<WeightedObject<? extends Object>>(); @@ -279,13 +280,8 @@ public class Projector { } } - private boolean isRoot(IInstallableUnit iu, IInstallableUnit[] newRoots) { - for (IInstallableUnit root : newRoots) { - if (root == iu) { - return true; - } - } - return false; + private boolean isRoot(IInstallableUnit iu, Collection<IInstallableUnit> newRoots) { + return newRoots.contains(iu); } private void createObjectiveFunction(List<WeightedObject<? extends Object>> weightedObjects) { @@ -305,7 +301,7 @@ public class Projector { dependencyHelper.setObjectiveFunction(array); } - private void createMustHave(IInstallableUnit iu, IInstallableUnit[] alreadyExistingRoots, IInstallableUnit[] newRoots) throws ContradictionException { + private void createMustHave(IInstallableUnit iu, IInstallableUnit[] alreadyExistingRoots) throws ContradictionException { processIU(iu, true); if (DEBUG) { Tracing.debug(iu + "=1"); //$NON-NLS-1$ diff --git a/bundles/org.eclipse.equinox.p2.director/src/org/eclipse/equinox/internal/p2/director/SimpleDirector.java b/bundles/org.eclipse.equinox.p2.director/src/org/eclipse/equinox/internal/p2/director/SimpleDirector.java index 58bce1e85..ea506ee69 100644 --- a/bundles/org.eclipse.equinox.p2.director/src/org/eclipse/equinox/internal/p2/director/SimpleDirector.java +++ b/bundles/org.eclipse.equinox.p2.director/src/org/eclipse/equinox/internal/p2/director/SimpleDirector.java @@ -1,13 +1,18 @@ /******************************************************************************* - * Copyright (c) 2007, 2009 IBM Corporation and others. All rights reserved. This + * Copyright (c) 2007, 2010 IBM Corporation and others. All rights reserved. This * program and the accompanying materials are made available under the terms of * the Eclipse Public License v1.0 which accompanies this distribution, and is * available at http://www.eclipse.org/legal/epl-v10.html * - * Contributors: IBM Corporation - initial API and implementation + * Contributors: + * IBM Corporation - initial API and implementation + * Sonatype, Inc. - ongoing development ******************************************************************************/ package org.eclipse.equinox.internal.p2.director; +import org.eclipse.equinox.p2.planner.IPlanner; + +import java.util.Collection; import org.eclipse.core.runtime.*; import org.eclipse.equinox.internal.provisional.p2.director.*; import org.eclipse.equinox.p2.engine.*; @@ -43,10 +48,10 @@ public class SimpleDirector implements IDirector { String taskName = NLS.bind(Messages.Director_Task_Installing, request.getProfile().getProperty(IProfile.PROP_INSTALL_FOLDER)); SubMonitor sub = SubMonitor.convert(monitor, taskName, PlanWork + EngineWork); try { - IInstallableUnit[] installRoots = request.getAddedInstallableUnits(); + Collection<IInstallableUnit> installRoots = request.getAdditions(); // mark the roots as such - for (int i = 0; i < installRoots.length; i++) { - request.setInstallableUnitProfileProperty(installRoots[i], IProfile.PROP_PROFILE_ROOT_IU, Boolean.toString(true)); + for (IInstallableUnit root : installRoots) { + request.setInstallableUnitProfileProperty(root, IProfile.PROP_PROFILE_ROOT_IU, Boolean.toString(true)); } IProvisioningPlan plan = planner.getProvisioningPlan(request, context, sub.newChild(PlanWork)); return PlanExecutionHelper.executePlan(plan, engine, context, sub.newChild(EngineWork)); diff --git a/bundles/org.eclipse.equinox.p2.director/src/org/eclipse/equinox/internal/p2/director/SimplePlanner.java b/bundles/org.eclipse.equinox.p2.director/src/org/eclipse/equinox/internal/p2/director/SimplePlanner.java index 7140be237..2b1454a91 100644 --- a/bundles/org.eclipse.equinox.p2.director/src/org/eclipse/equinox/internal/p2/director/SimplePlanner.java +++ b/bundles/org.eclipse.equinox.p2.director/src/org/eclipse/equinox/internal/p2/director/SimplePlanner.java @@ -7,6 +7,7 @@ * Contributors: * IBM Corporation - initial API and implementation * Genuitec - bug fixes + * Sonatype, Inc. - ongoing development ******************************************************************************/ package org.eclipse.equinox.internal.p2.director; @@ -28,6 +29,8 @@ import org.eclipse.equinox.p2.engine.query.IUProfilePropertyQuery; import org.eclipse.equinox.p2.metadata.*; import org.eclipse.equinox.p2.metadata.query.ExpressionQuery; import org.eclipse.equinox.p2.metadata.query.InstallableUnitQuery; +import org.eclipse.equinox.p2.planner.IPlanner; +import org.eclipse.equinox.p2.planner.IProfileChangeRequest; import org.eclipse.equinox.p2.query.*; import org.eclipse.equinox.p2.repository.IRepositoryManager; import org.eclipse.equinox.p2.repository.metadata.IMetadataRepository; @@ -72,14 +75,14 @@ public class SimplePlanner implements IPlanner { } private Map<IInstallableUnit, RequestStatus>[] buildDetailedErrors(ProfileChangeRequest changeRequest) { - IInstallableUnit[] added = changeRequest.getAddedInstallableUnits(); - IInstallableUnit[] removed = changeRequest.getRemovedInstallableUnits(); - Map<IInstallableUnit, RequestStatus> requestStatus = new HashMap<IInstallableUnit, RequestStatus>(added.length + removed.length); - for (int i = 0; i < added.length; i++) { - requestStatus.put(added[i], new RequestStatus(added[i], RequestStatus.ADDED, IStatus.ERROR, null)); + Collection<IInstallableUnit> requestedAdditions = changeRequest.getAdditions(); + Collection<IInstallableUnit> requestedRemovals = changeRequest.getRemovals(); + Map<IInstallableUnit, RequestStatus> requestStatus = new HashMap<IInstallableUnit, RequestStatus>(requestedAdditions.size() + requestedAdditions.size()); + for (IInstallableUnit added : requestedAdditions) { + requestStatus.put(added, new RequestStatus(added, RequestStatus.ADDED, IStatus.ERROR, null)); } - for (int i = 0; i < removed.length; i++) { - requestStatus.put(removed[i], new RequestStatus(removed[i], RequestStatus.REMOVED, IStatus.ERROR, null)); + for (IInstallableUnit removed : requestedRemovals) { + requestStatus.put(removed, new RequestStatus(removed, RequestStatus.REMOVED, IStatus.ERROR, null)); } @SuppressWarnings("unchecked") Map<IInstallableUnit, RequestStatus>[] maps = new Map[] {requestStatus, null}; @@ -87,21 +90,21 @@ public class SimplePlanner implements IPlanner { } private Map<IInstallableUnit, RequestStatus>[] computeActualChangeRequest(Collection<IInstallableUnit> toState, ProfileChangeRequest changeRequest) { - IInstallableUnit[] added = changeRequest.getAddedInstallableUnits(); - IInstallableUnit[] removed = changeRequest.getRemovedInstallableUnits(); - Map<IInstallableUnit, RequestStatus> requestStatus = new HashMap<IInstallableUnit, RequestStatus>(added.length + removed.length); - for (int i = 0; i < added.length; i++) { - if (toState.contains(added[i])) - requestStatus.put(added[i], new RequestStatus(added[i], RequestStatus.ADDED, IStatus.OK, null)); + Collection<IInstallableUnit> requestedAdditions = changeRequest.getAdditions(); + Collection<IInstallableUnit> requestedRemovals = changeRequest.getRemovals(); + Map<IInstallableUnit, RequestStatus> requestStatus = new HashMap<IInstallableUnit, RequestStatus>(requestedAdditions.size() + requestedRemovals.size()); + for (IInstallableUnit added : requestedAdditions) { + if (toState.contains(added)) + requestStatus.put(added, new RequestStatus(added, RequestStatus.ADDED, IStatus.OK, null)); else - requestStatus.put(added[i], new RequestStatus(added[i], RequestStatus.ADDED, IStatus.ERROR, null)); + requestStatus.put(added, new RequestStatus(added, RequestStatus.ADDED, IStatus.ERROR, null)); } - for (int i = 0; i < removed.length; i++) { - if (!toState.contains(removed[i])) - requestStatus.put(removed[i], new RequestStatus(removed[i], RequestStatus.REMOVED, IStatus.OK, null)); + for (IInstallableUnit removed : requestedRemovals) { + if (!toState.contains(removed)) + requestStatus.put(removed, new RequestStatus(removed, RequestStatus.REMOVED, IStatus.OK, null)); else - requestStatus.put(removed[i], new RequestStatus(removed[i], RequestStatus.REMOVED, IStatus.ERROR, null)); + requestStatus.put(removed, new RequestStatus(removed, RequestStatus.REMOVED, IStatus.ERROR, null)); } //Compute the side effect changes (e.g. things installed optionally going away) @@ -192,20 +195,20 @@ public class SimplePlanner implements IPlanner { SubMonitor sub = SubMonitor.convert(monitor, ExpandWork); sub.setTaskName(Messages.Director_Task_Resolving_Dependencies); try { - ProfileChangeRequest profileChangeRequest = FormerState.generateProfileDeltaChangeRequest(currentProfile, targetProfile); + IProfileChangeRequest profileChangeRequest = FormerState.generateProfileDeltaChangeRequest(currentProfile, targetProfile); ProvisioningContext context = new ProvisioningContext(new URI[0]); if (context.getProperty(INCLUDE_PROFILE_IUS) == null) context.setProperty(INCLUDE_PROFILE_IUS, Boolean.FALSE.toString()); context.setExtraIUs(Arrays.asList(targetProfile.available(InstallableUnitQuery.ANY, null).toArray(IInstallableUnit.class))); - return getProvisioningPlan(profileChangeRequest, context, sub.newChild(ExpandWork / 2)); + return getProvisioningPlan((ProfileChangeRequest) profileChangeRequest, context, sub.newChild(ExpandWork / 2)); } finally { sub.done(); } } - public static IInstallableUnit[] findPlannerMarkedIUs(final IProfile profile) { + public static Collection<IInstallableUnit> findPlannerMarkedIUs(final IProfile profile) { IQuery<IInstallableUnit> markerQuery = new IUProfilePropertyQuery(INCLUSION_RULES, null); - return profile.query(markerQuery, null).toArray(IInstallableUnit.class); + return profile.query(markerQuery, null).toSet(); } public static Dictionary<String, String> createSelectionContext(Map<String, String> properties) { @@ -302,8 +305,8 @@ public class SimplePlanner implements IPlanner { URI[] metadataRepositories = (context != null) ? context.getMetadataRepositories() : null; Dictionary<String, String> newSelectionContext = createSelectionContext(profileChangeRequest.getProfileProperties()); - List<IInstallableUnit> extraIUs = new ArrayList<IInstallableUnit>(Arrays.asList(profileChangeRequest.getAddedInstallableUnits())); - extraIUs.addAll(Arrays.asList(profileChangeRequest.getRemovedInstallableUnits())); + List<IInstallableUnit> extraIUs = new ArrayList<IInstallableUnit>(profileChangeRequest.getAdditions()); + extraIUs.addAll(profileChangeRequest.getRemovals()); if (context == null || context.getProperty(INCLUDE_PROFILE_IUS) == null || context.getProperty(INCLUDE_PROFILE_IUS).equalsIgnoreCase(Boolean.TRUE.toString())) { Iterator<IInstallableUnit> itor = profile.available(InstallableUnitQuery.ANY, null).iterator(); while (itor.hasNext()) @@ -317,7 +320,7 @@ public class SimplePlanner implements IPlanner { if (slice == null) return new ProvisioningPlan(slicer.getStatus(), profile, context, null); Projector projector = new Projector(slice, newSelectionContext, satisfyMetaRequirements(profileChangeRequest.getProfileProperties())); - projector.encode((IInstallableUnit) updatedPlan[0], (IInstallableUnit[]) updatedPlan[1], profile, profileChangeRequest.getAddedInstallableUnits(), sub.newChild(ExpandWork / 4)); + projector.encode((IInstallableUnit) updatedPlan[0], (IInstallableUnit[]) updatedPlan[1], profile, profileChangeRequest.getAdditions(), sub.newChild(ExpandWork / 4)); IStatus s = projector.invokeSolver(sub.newChild(ExpandWork / 4)); if (s.getSeverity() == IStatus.CANCEL) return new ProvisioningPlan(s, profile, context, null); @@ -347,14 +350,15 @@ public class SimplePlanner implements IPlanner { } } - public IProvisioningPlan getProvisioningPlan(ProfileChangeRequest profileChangeRequest, ProvisioningContext context, IProgressMonitor monitor) { - if (profileChangeRequest.getAbsolute()) - return generateAbsoluteProvisioningPlan(profileChangeRequest, context, monitor); + public IProvisioningPlan getProvisioningPlan(IProfileChangeRequest request, ProvisioningContext context, IProgressMonitor monitor) { + ProfileChangeRequest pcr = (ProfileChangeRequest) request; + if (pcr.getAbsolute()) + return generateAbsoluteProvisioningPlan(pcr, context, monitor); SubMonitor sub = SubMonitor.convert(monitor, ExpandWork); sub.setTaskName(Messages.Director_Task_Resolving_Dependencies); try { //Get the solution for the initial request - Object resolutionResult = getSolutionFor(profileChangeRequest, context, sub.newChild(ExpandWork / 2)); + Object resolutionResult = getSolutionFor(pcr, context, sub.newChild(ExpandWork / 2)); if (resolutionResult instanceof IProvisioningPlan) return (ProvisioningPlan) resolutionResult; @@ -363,12 +367,12 @@ public class SimplePlanner implements IPlanner { fullState.addAll(newState); newState = AttachmentHelper.attachFragments(newState.iterator(), ((Projector) resolutionResult).getFragmentAssociation()); - ProvisioningPlan temporaryPlan = generatePlan((Projector) resolutionResult, newState, profileChangeRequest, context); + ProvisioningPlan temporaryPlan = generatePlan((Projector) resolutionResult, newState, pcr, context); //Create a plan for installing necessary pieces to complete the installation (e.g touchpoint actions) - return createInstallerPlan(profileChangeRequest.getProfile(), profileChangeRequest, fullState, newState, temporaryPlan, context, sub.newChild(ExpandWork / 2)); + return createInstallerPlan(pcr.getProfile(), pcr, fullState, newState, temporaryPlan, context, sub.newChild(ExpandWork / 2)); } catch (OperationCanceledException e) { - return new ProvisioningPlan(Status.CANCEL_STATUS, profileChangeRequest.getProfile(), context, null); + return new ProvisioningPlan(Status.CANCEL_STATUS, pcr.getProfile(), context, null); } finally { sub.done(); } @@ -377,8 +381,8 @@ public class SimplePlanner implements IPlanner { private IProvisioningPlan generateAbsoluteProvisioningPlan(ProfileChangeRequest profileChangeRequest, ProvisioningContext context, IProgressMonitor monitor) { Set<IInstallableUnit> toState = profileChangeRequest.getProfile().query(InstallableUnitQuery.ANY, null).toSet(); HashSet<IInstallableUnit> fromState = new HashSet<IInstallableUnit>(toState); - toState.removeAll(Arrays.asList(profileChangeRequest.getRemovedInstallableUnits())); - toState.addAll(Arrays.asList(profileChangeRequest.getAddedInstallableUnits())); + toState.removeAll(profileChangeRequest.getRemovals()); + toState.addAll(profileChangeRequest.getAdditions()); List<InstallableUnitOperand> iuOperands = generateOperations(fromState, toState); PropertyOperand[] propertyOperands = generatePropertyOperations(profileChangeRequest); @@ -468,9 +472,9 @@ public class SimplePlanner implements IPlanner { IInstallableUnit previousActionsIU = getPreviousIUForMetaRequirements(agentProfile, getActionGatheringIUId(targetedProfile), sub); ProfileChangeRequest agentRequest = new ProfileChangeRequest(agentProfile); - agentRequest.addInstallableUnits(actionsIU); + agentRequest.add(actionsIU); if (previousActionsIU != null) - agentRequest.removeInstallableUnit(previousActionsIU); + agentRequest.remove(previousActionsIU); Object externalInstallerPlan = getSolutionFor(agentRequest, initialContext, sub.newChild(10)); if (externalInstallerPlan instanceof IProvisioningPlan && ((IProvisioningPlan) externalInstallerPlan).getStatus().getSeverity() == IStatus.ERROR) { MultiStatus externalInstallerStatus = new MultiStatus(DirectorActivator.PI_DIRECTOR, 0, Messages.Planner_can_not_install_preq, null); @@ -485,7 +489,7 @@ public class SimplePlanner implements IPlanner { //Deal with the case where the actions needs to be installed in the same profile than the one we are performing the initial request //The expectedState represents the result of the initialRequest where the metaRequirements have been satisfied. private ProvisioningPlan createInstallerPlanForCohostedCase(IProfile profile, ProfileChangeRequest initialRequest, ProvisioningPlan initialPlan, Collection<IInstallableUnit> unattachedState, Collection<IInstallableUnit> expectedState, ProvisioningContext initialContext, SubMonitor monitor) { - Collection<IRequirement> metaRequirements = initialRequest.getRemovedInstallableUnits().length == 0 ? areMetaRequirementsSatisfied(profile, expectedState, initialPlan) : extractMetaRequirements(expectedState, initialPlan); + Collection<IRequirement> metaRequirements = initialRequest.getRemovals().size() == 0 ? areMetaRequirementsSatisfied(profile, expectedState, initialPlan) : extractMetaRequirements(expectedState, initialPlan); if (metaRequirements == null || metaRequirements.isEmpty()) return initialPlan; @@ -510,8 +514,8 @@ public class SimplePlanner implements IPlanner { } if (previousMetaRequirementIU != null) - agentRequest.removeInstallableUnit(previousMetaRequirementIU); - agentRequest.addInstallableUnits(metaRequirementIU); + agentRequest.remove(previousMetaRequirementIU); + agentRequest.add(metaRequirementIU); ProvisioningContext agentCtx = new ProvisioningContext(new URI[0]); ArrayList<IInstallableUnit> extraIUs = new ArrayList<IInstallableUnit>(unattachedState); @@ -617,20 +621,20 @@ public class SimplePlanner implements IPlanner { private Object[] updatePlannerInfo(ProfileChangeRequest profileChangeRequest, ProvisioningContext context) { IQueryResult<IInstallableUnit> alreadyInstalled = profileChangeRequest.getProfile().query(new IUProfilePropertyQuery(INCLUSION_RULES, null), null); - IInstallableUnit[] added = profileChangeRequest.getAddedInstallableUnits(); - IInstallableUnit[] removed = profileChangeRequest.getRemovedInstallableUnits(); + Collection<IInstallableUnit> additionRequested = profileChangeRequest.getAdditions(); + Collection<IInstallableUnit> removalRequested = profileChangeRequest.getRemovals(); for (Entry<IInstallableUnit, List<String>> object : profileChangeRequest.getInstallableUnitProfilePropertiesToRemove().entrySet()) { if (object.getValue().contains(INCLUSION_RULES)) profileChangeRequest.setInstallableUnitProfileProperty(object.getKey(), INCLUSION_RULES, PlannerHelper.createStrictInclusionRule(object.getKey())); } //Remove the iu properties associated to the ius removed and the iu properties being removed as well - if (removed.length != 0) { + if (removalRequested.size() != 0) { for (Iterator<IInstallableUnit> iterator = alreadyInstalled.iterator(); iterator.hasNext();) { IInstallableUnit iu = iterator.next(); - for (int i = 0; i < removed.length; i++) { - if (iu.equals(removed[i])) { - profileChangeRequest.removeInstallableUnitProfileProperty(removed[i], INCLUSION_RULES); + for (IInstallableUnit removed : removalRequested) { + if (iu.equals(removed)) { + profileChangeRequest.removeInstallableUnitProfileProperty(removed, INCLUSION_RULES); iterator.remove(); break; } @@ -641,15 +645,15 @@ public class SimplePlanner implements IPlanner { //Process all the IUs being added Map<IInstallableUnit, Map<String, String>> iuPropertiesToAdd = profileChangeRequest.getInstallableUnitProfilePropertiesToAdd(); - for (int i = 0; i < added.length; i++) { - Map<String, String> propertiesForIU = iuPropertiesToAdd.get(added[i]); + for (IInstallableUnit added : additionRequested) { + Map<String, String> propertiesForIU = iuPropertiesToAdd.get(added); IRequirement profileRequirement = null; if (propertiesForIU != null) { - profileRequirement = createRequirement(added[i], propertiesForIU.get(INCLUSION_RULES)); + profileRequirement = createRequirement(added, propertiesForIU.get(INCLUSION_RULES)); } if (profileRequirement == null) { - profileChangeRequest.setInstallableUnitProfileProperty(added[i], INCLUSION_RULES, PlannerHelper.createStrictInclusionRule(added[i])); - profileRequirement = createStrictRequirement(added[i]); + profileChangeRequest.setInstallableUnitProfileProperty(added, INCLUSION_RULES, PlannerHelper.createStrictInclusionRule(added)); + profileRequirement = createStrictRequirement(added); } gatheredRequirements.add(profileRequirement); } @@ -771,4 +775,9 @@ public class SimplePlanner implements IPlanner { return profile.query(query, monitor); } } + + public IProfileChangeRequest createChangeRequest(IProfile profileToChange) { + // TODO Auto-generated method stub + return null; + } } diff --git a/bundles/org.eclipse.equinox.p2.director/src/org/eclipse/equinox/internal/p2/rollback/FormerState.java b/bundles/org.eclipse.equinox.p2.director/src/org/eclipse/equinox/internal/p2/rollback/FormerState.java index c0d30f031..c5bc38cf4 100644 --- a/bundles/org.eclipse.equinox.p2.director/src/org/eclipse/equinox/internal/p2/rollback/FormerState.java +++ b/bundles/org.eclipse.equinox.p2.director/src/org/eclipse/equinox/internal/p2/rollback/FormerState.java @@ -7,6 +7,7 @@ * * Contributors: * IBM Corporation - initial API and implementation + * Sonatype, Inc. - ongoing development *******************************************************************************/ package org.eclipse.equinox.internal.p2.rollback; @@ -17,10 +18,11 @@ import org.eclipse.equinox.internal.provisional.p2.director.ProfileChangeRequest import org.eclipse.equinox.p2.engine.IProfile; import org.eclipse.equinox.p2.metadata.IInstallableUnit; import org.eclipse.equinox.p2.metadata.query.InstallableUnitQuery; +import org.eclipse.equinox.p2.planner.IProfileChangeRequest; public class FormerState { - public static ProfileChangeRequest generateProfileDeltaChangeRequest(IProfile current, IProfile target) { + public static IProfileChangeRequest generateProfileDeltaChangeRequest(IProfile current, IProfile target) { ProfileChangeRequest request = new ProfileChangeRequest(current); synchronizeProfileProperties(request, current, target); @@ -30,7 +32,7 @@ public class FormerState { return request; } - private static void synchronizeAllIUProperties(ProfileChangeRequest request, IProfile current, IProfile target) { + private static void synchronizeAllIUProperties(IProfileChangeRequest request, IProfile current, IProfile target) { Set<IInstallableUnit> currentIUset = current.query(InstallableUnitQuery.ANY, null).unmodifiableSet(); Iterator<IInstallableUnit> targetIUs = target.query(InstallableUnitQuery.ANY, null).iterator(); List<IInstallableUnit> iusToAdd = new ArrayList<IInstallableUnit>(); @@ -68,22 +70,22 @@ public class FormerState { } } - private static void synchronizeMarkedIUs(ProfileChangeRequest request, IProfile current, IProfile target) { - IInstallableUnit[] currentPlannerMarkedIUs = SimplePlanner.findPlannerMarkedIUs(current); - IInstallableUnit[] targetPlannerMarkedIUs = SimplePlanner.findPlannerMarkedIUs(target); + private static void synchronizeMarkedIUs(IProfileChangeRequest request, IProfile current, IProfile target) { + Collection<IInstallableUnit> currentPlannerMarkedIUs = SimplePlanner.findPlannerMarkedIUs(current); + Collection<IInstallableUnit> targetPlannerMarkedIUs = SimplePlanner.findPlannerMarkedIUs(target); //additions - List<IInstallableUnit> markedIUsToAdd = new ArrayList<IInstallableUnit>(Arrays.asList(targetPlannerMarkedIUs)); - markedIUsToAdd.removeAll(Arrays.asList(currentPlannerMarkedIUs)); - request.addInstallableUnits(markedIUsToAdd); + Collection<IInstallableUnit> markedIUsToAdd = new HashSet<IInstallableUnit>(targetPlannerMarkedIUs); + markedIUsToAdd.removeAll(currentPlannerMarkedIUs); + request.addAll(markedIUsToAdd); // removes - List<IInstallableUnit> markedIUsToRemove = new ArrayList<IInstallableUnit>(Arrays.asList(currentPlannerMarkedIUs)); - markedIUsToRemove.removeAll(Arrays.asList(targetPlannerMarkedIUs)); - request.removeInstallableUnits(markedIUsToRemove); + Collection<IInstallableUnit> markedIUsToRemove = new HashSet<IInstallableUnit>(currentPlannerMarkedIUs); + markedIUsToRemove.removeAll(targetPlannerMarkedIUs); + request.removeAll(markedIUsToRemove); } - private static void synchronizeProfileProperties(ProfileChangeRequest request, IProfile current, IProfile target) { + private static void synchronizeProfileProperties(IProfileChangeRequest request, IProfile current, IProfile target) { Map<String, String> profilePropertiesToSet = new HashMap<String, String>(target.getProperties()); for (Entry<String, String> entry : current.getProperties().entrySet()) { String key = entry.getKey(); |