From 58fc582de8d471a3759198ca79b9987f51703ab8 Mon Sep 17 00:00:00 2001 From: Pascal Rapicault Date: Fri, 17 Dec 2010 01:36:34 +0000 Subject: Bug 332655 - Setting IU properties for missing IUs in a profile dirties the profile but does not persist the propert --- .../internal/p2/director/SimplePlanner.java | 6 ++- .../eclipse/equinox/p2/tests/planner/AllTests.java | 1 + .../p2/tests/planner/NoUnecessaryIUProperty.java | 49 ++++++++++++++++++++++ 3 files changed, 54 insertions(+), 2 deletions(-) create mode 100644 bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/planner/NoUnecessaryIUProperty.java 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 a42ac71c6..e8d6be1e7 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 @@ -51,7 +51,7 @@ public class SimplePlanner implements IPlanner { private IProvisioningPlan generateProvisioningPlan(Collection fromState, Collection toState, ProfileChangeRequest changeRequest, IProvisioningPlan installerPlan, ProvisioningContext context) { IProvisioningPlan plan = engine.createPlan(changeRequest.getProfile(), context); planIUOperations(plan, fromState, toState); - planPropertyOperations(plan, changeRequest); + planPropertyOperations(plan, changeRequest, toState); if (DEBUG) { Object[] operands = new Object[0]; @@ -164,7 +164,7 @@ public class SimplePlanner implements IPlanner { return root; } - private void planPropertyOperations(IProvisioningPlan plan, ProfileChangeRequest profileChangeRequest) { + private void planPropertyOperations(IProvisioningPlan plan, ProfileChangeRequest profileChangeRequest, Collection toState) { // First deal with profile properties to remove. String[] toRemove = profileChangeRequest.getPropertiesToRemove(); @@ -181,6 +181,8 @@ public class SimplePlanner implements IPlanner { Map> allIUPropertyChanges = profileChangeRequest.getInstallableUnitProfilePropertiesToAdd(); for (Map.Entry> entry : allIUPropertyChanges.entrySet()) { IInstallableUnit iu = entry.getKey(); + if (!toState.contains(iu)) + continue; for (Map.Entry entry2 : entry.getValue().entrySet()) { plan.setInstallableUnitProfileProperty(iu, entry2.getKey(), entry2.getValue()); } diff --git a/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/planner/AllTests.java b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/planner/AllTests.java index 396423f47..9f8a69652 100644 --- a/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/planner/AllTests.java +++ b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/planner/AllTests.java @@ -93,6 +93,7 @@ public class AllTests extends TestCase { // suite.addTestSuite(NegationTesting.class); suite.addTestSuite(NonMinimalState.class); suite.addTestSuite(NonMinimalState2.class); + suite.addTestSuite(NoUnecessaryIUProperty.class); suite.addTestSuite(MultipleProvider.class); suite.addTestSuite(MultipleSingleton.class); suite.addTestSuite(NoRequirements.class); diff --git a/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/planner/NoUnecessaryIUProperty.java b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/planner/NoUnecessaryIUProperty.java new file mode 100644 index 000000000..fd8320771 --- /dev/null +++ b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/planner/NoUnecessaryIUProperty.java @@ -0,0 +1,49 @@ +/******************************************************************************* + * Copyright (c) 2010 Sonatype, Inc. 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: + * Sonatype, Inc. - initial API and implementation + *******************************************************************************/ +package org.eclipse.equinox.p2.tests.planner; + +import org.eclipse.core.runtime.NullProgressMonitor; +import org.eclipse.equinox.internal.p2.engine.ProvisioningPlan; +import org.eclipse.equinox.p2.engine.*; +import org.eclipse.equinox.p2.metadata.IInstallableUnit; +import org.eclipse.equinox.p2.planner.IPlanner; +import org.eclipse.equinox.p2.planner.IProfileChangeRequest; +import org.eclipse.equinox.p2.repository.metadata.IMetadataRepository; +import org.eclipse.equinox.p2.tests.AbstractProvisioningTest; + +public class NoUnecessaryIUProperty extends AbstractProvisioningTest { + + IProfile profile1; + IPlanner planner; + IEngine engine; + IMetadataRepository repo; + IInstallableUnit iuA, iuB; + + protected void setUp() throws Exception { + super.setUp(); + + profile1 = createProfile("TestProfile." + getName()); + planner = createPlanner(); + engine = createEngine(); + iuA = createIU("A"); + iuB = createIU("B"); + } + + //Confirm that the planner will not generate an IUProperty operand if the IU is not in the final profile. + public void testIUExtraneousPlanEntry() { + IProfileChangeRequest pcr = planner.createChangeRequest(profile1); + pcr.add(iuA); + pcr.setInstallableUnitProfileProperty(iuB, "theKey", "theValue"); // Try to set a property on an IU that does not end up in plan + IProvisioningPlan plan = planner.getProvisioningPlan(pcr, null, new NullProgressMonitor()); + assertEquals(2, ((ProvisioningPlan) plan).getOperands().length); + + } +} -- cgit v1.2.3