diff options
author | Pascal Rapicault | 2011-11-14 04:42:09 +0000 |
---|---|---|
committer | Pascal Rapicault | 2011-11-14 04:42:09 +0000 |
commit | 7c00035bdbef0d6f5fd1e5664fd744c95a984a7b (patch) | |
tree | decde259de3d0b3c4571079fbd653cfab615d340 | |
parent | 61cea958bc1fbcea0bae8afe8ec1d87c6d8da711 (diff) | |
download | rt.equinox.p2-7c00035bdbef0d6f5fd1e5664fd744c95a984a7b.tar.gz rt.equinox.p2-7c00035bdbef0d6f5fd1e5664fd744c95a984a7b.tar.xz rt.equinox.p2-7c00035bdbef0d6f5fd1e5664fd744c95a984a7b.zip |
Some fix and a testv20111114-0442
7 files changed, 224 insertions, 25 deletions
diff --git a/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/planner/LuckyHelper.java b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/planner/LuckyHelper.java index 473ad4ec0..e813a8a58 100644 --- a/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/planner/LuckyHelper.java +++ b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/planner/LuckyHelper.java @@ -33,29 +33,30 @@ public class LuckyHelper { 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); + CollectionResult<IInstallableUnit> allInitialRoots = new CollectionResult<IInstallableUnit>(tmpRoots); - request = (ProfileChangeRequest) plan.createChangeRequest(prof); + ProfileChangeRequest updateFinderRequest = (ProfileChangeRequest) plan.createChangeRequest(prof); Collection<IRequirement> limitingRequirements = new ArrayList<IRequirement>(); - for (Iterator<IInstallableUnit> iterator = allRoots.query(QueryUtil.ALL_UNITS, null).iterator(); iterator.hasNext();) { + //Create a profile change request that attempts at installing updates for all the existing roots. + for (Iterator<IInstallableUnit> iterator = allInitialRoots.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)); + updateFinderRequest.add(update); + updateFinderRequest.setInstallableUnitInclusionRules(update, ProfileInclusionRules.createOptionalInclusionRule(update)); } + + //force the original IU to optional, but make sure that the solution at least includes it + updateFinderRequest.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)); } + updateFinderRequest.addExtraRequirements(limitingRequirements); - IProvisioningPlan updateFinderPlan = plan.getProvisioningPlan(request, context, null); + IProvisioningPlan updateFinderPlan = plan.getProvisioningPlan(updateFinderRequest, context, null); if (updateFinderPlan.getAdditions().query(QueryUtil.ALL_UNITS, null).isEmpty()) { return null; } @@ -65,7 +66,7 @@ public class LuckyHelper { 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()) { + if (!allInitialRoots.query(QueryUtil.createIUQuery(iu), null).isEmpty()) { finalChangeRequest.remove(iu); } } diff --git a/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/planner/LuckyTest.java b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/planner/LuckyTest.java index eb82b6842..900907564 100644 --- a/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/planner/LuckyTest.java +++ b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/planner/LuckyTest.java @@ -39,10 +39,6 @@ public class LuckyTest extends AbstractProvisioningTest { super.setUp(); IULoader.loadIUs(this); createTestMetdataRepository(new IInstallableUnit[] {sdk1, platform1, sdk2, platform2}); - System.out.println(sdk1); - System.out.println(platform1); - System.out.println(sdk2); - System.out.println(platform2); planner = createPlanner(); engine = createEngine(); assertOK(install(profile, new IInstallableUnit[] {sdk1}, true, planner, engine)); @@ -50,9 +46,8 @@ public class LuckyTest extends AbstractProvisioningTest { public void testInstallSDK2() { assertNotOK(install(profile, new IInstallableUnit[] {platform2}, true, planner, engine)); - ProfileChangeRequest request = new ProfileChangeRequest(profile); - request.add(platform2); - ProfileChangeRequest res = new LuckyHelper().computeProfileChangeRequest(profile, planner, request, new ProvisioningContext(getAgent()), getMonitor()); + + ProfileChangeRequest res = new LuckyHelper().computeProfileChangeRequest(profile, planner, null, new ProvisioningContext(getAgent()), getMonitor()); assertTrue(res.getAdditions().contains(sdk2)); assertTrue(res.getRemovals().contains(sdk1)); } diff --git a/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/planner/LuckyTest2.java b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/planner/LuckyTest2.java index a36521f90..d30a4f447 100644 --- a/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/planner/LuckyTest2.java +++ b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/planner/LuckyTest2.java @@ -49,10 +49,8 @@ public class LuckyTest2 extends AbstractProvisioningTest { public void testInstallSDK2() { assertNotOK(install(profile, new IInstallableUnit[] {platform2}, true, planner, engine)); - ProfileChangeRequest request = new ProfileChangeRequest(profile); - request.add(platform2); - ProfileChangeRequest res = new LuckyHelper().computeProfileChangeRequest(profile, planner, request, new ProvisioningContext(getAgent()), getMonitor()); + ProfileChangeRequest res = new LuckyHelper().computeProfileChangeRequest(profile, planner, null, new ProvisioningContext(getAgent()), getMonitor()); assertEquals(1, res.getAdditions().size()); assertTrue(res.getAdditions().contains(sdk2)); assertEquals(1, res.getRemovals().size()); diff --git a/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/planner/LuckyTest3.java b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/planner/LuckyTest3.java index 007c116ef..a6ea060df 100644 --- a/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/planner/LuckyTest3.java +++ b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/planner/LuckyTest3.java @@ -53,10 +53,8 @@ public class LuckyTest3 extends AbstractProvisioningTest { public void testInstallSDK2() { assertNotOK(install(profile, new IInstallableUnit[] {platform2}, true, planner, engine)); - ProfileChangeRequest request = new ProfileChangeRequest(profile); - request.add(platform2); - ProfileChangeRequest res = new LuckyHelper().computeProfileChangeRequest(profile, planner, request, new ProvisioningContext(getAgent()), getMonitor()); + ProfileChangeRequest res = new LuckyHelper().computeProfileChangeRequest(profile, planner, null, new ProvisioningContext(getAgent()), getMonitor()); assertEquals(1, res.getAdditions().size()); assertTrue(res.getAdditions().contains(sdk2)); assertEquals(1, res.getRemovals().size()); diff --git a/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/planner/LuckyTest4.java b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/planner/LuckyTest4.java new file mode 100644 index 000000000..a4b062a1c --- /dev/null +++ b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/planner/LuckyTest4.java @@ -0,0 +1,97 @@ +/******************************************************************************* + * Copyright (c) 2011 Sonatype, Inc. 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 implementation and ideas + ******************************************************************************/ +package org.eclipse.equinox.p2.tests.planner; + +import org.eclipse.equinox.internal.p2.director.ProfileChangeRequest; +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.tests.*; + +public class LuckyTest4 extends AbstractProvisioningTest { + @IUDescription(content = "package: sdk \n" + "singleton: true\n" + "version: 1 \n" + "depends: platform = 1\n") + public IInstallableUnit sdk1; + + @IUDescription(content = "package: platform \n" + "singleton: true\n" + "version: 1 \n") + public IInstallableUnit platform1; + + @IUDescription(content = "package: sdk \n" + "singleton: true\n" + "version: 2 \n" + "depends: platform = 2\n") + public IInstallableUnit sdk2; + + @IUDescription(content = "package: platform \n" + "singleton: true\n" + "version: 2 \n") + public IInstallableUnit platform2; + + @IUDescription(content = "package: egit \n" + "singleton: true\n" + "version: 1 \n") + public IInstallableUnit egit1; + + @IUDescription(content = "package: egit \n" + "singleton: true\n" + "version: 2 \n") + public IInstallableUnit egit2; + + IProfile profile; + + private IPlanner planner; + + private IEngine engine; + + @Override + protected void setUp() throws Exception { + super.setUp(); + IULoader.loadIUs(this); + profile = createProfile("TestProfile." + getName()); + createTestMetdataRepository(new IInstallableUnit[] {sdk1, platform1, sdk2, platform2, egit1, egit2}); + planner = createPlanner(); + engine = createEngine(); + + //Setup the initial state of the profile + assertOK(install(profile, new IInstallableUnit[] {sdk1}, true, planner, engine)); + assertOK(install(profile, new IInstallableUnit[] {egit1}, false, planner, engine)); + assertEquals("STRICT", profile.getInstallableUnitProperty(sdk1, "org.eclipse.equinox.p2.internal.inclusion.rules")); + assertEquals("OPTIONAL", profile.getInstallableUnitProperty(egit1, "org.eclipse.equinox.p2.internal.inclusion.rules")); + } + + //Verify that both strict and optional dependencies are updated and the properties appropriately conserved + public void testInstallSDK2() { + assertNotOK(install(profile, new IInstallableUnit[] {platform2, egit2}, true, planner, engine)); + + ProfileChangeRequest res = new LuckyHelper().computeProfileChangeRequest(profile, planner, null, new ProvisioningContext(getAgent()), getMonitor()); + assertEquals(2, res.getAdditions().size()); + assertTrue(res.getAdditions().contains(sdk2)); + assertTrue(res.getAdditions().contains(egit2)); + assertEquals(2, res.getRemovals().size()); + assertTrue(res.getRemovals().contains(sdk1)); + assertTrue(res.getRemovals().contains(egit1)); + + assertOK(install(res, planner, engine)); + assertProfileContains("validate new profile", profile, new IInstallableUnit[] {sdk2, platform2, egit2}); + assertEquals("STRICT", profile.getInstallableUnitProperty(sdk2, "org.eclipse.equinox.p2.internal.inclusion.rules")); + assertEquals(null, profile.getInstallableUnitProperty(platform2, "org.eclipse.equinox.p2.internal.inclusion.rules")); + assertEquals("OPTIONAL", profile.getInstallableUnitProperty(egit2, "org.eclipse.equinox.p2.internal.inclusion.rules")); + } + + //Check that + public void updateWithInterference() { + assertNotOK(install(profile, new IInstallableUnit[] {platform2, egit2}, true, planner, engine)); + + ProfileChangeRequest res = new LuckyHelper().computeProfileChangeRequest(profile, planner, null, new ProvisioningContext(getAgent()), getMonitor()); + assertEquals(2, res.getAdditions().size()); + assertTrue(res.getAdditions().contains(sdk2)); + assertTrue(res.getAdditions().contains(egit2)); + assertEquals(2, res.getRemovals().size()); + assertTrue(res.getRemovals().contains(sdk1)); + assertTrue(res.getRemovals().contains(egit1)); + + assertOK(install(res, planner, engine)); + assertProfileContains("validate new profile", profile, new IInstallableUnit[] {sdk2, platform2, egit2}); + assertEquals("STRICT", profile.getInstallableUnitProperty(sdk2, "org.eclipse.equinox.p2.internal.inclusion.rules")); + assertEquals(null, profile.getInstallableUnitProperty(platform2, "org.eclipse.equinox.p2.internal.inclusion.rules")); + assertEquals("OPTIONAL", profile.getInstallableUnitProperty(egit2, "org.eclipse.equinox.p2.internal.inclusion.rules")); + + } +} diff --git a/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/planner/LuckyTest5.java b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/planner/LuckyTest5.java new file mode 100644 index 000000000..9ad1d8b5d --- /dev/null +++ b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/planner/LuckyTest5.java @@ -0,0 +1,51 @@ +/******************************************************************************* + * Copyright (c) 2011 Sonatype, Inc. 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 implementation and ideas + ******************************************************************************/ +package org.eclipse.equinox.p2.tests.planner; + +import org.eclipse.equinox.internal.p2.director.ProfileChangeRequest; +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.tests.*; + +public class LuckyTest5 extends AbstractProvisioningTest { + @IUDescription(content = "package: sdk \n" + "singleton: true\n" + "version: 1 \n" + "depends: platform = 1") + public IInstallableUnit sdk1; + + @IUDescription(content = "package: platform \n" + "singleton: true\n" + "version: 1 \n") + public IInstallableUnit platform1; + + @IUDescription(content = "package: platform \n" + "singleton: true\n" + "version: 2 \n") + public IInstallableUnit platform2; + + IProfile profile = createProfile("TestProfile." + getName()); + + private IPlanner planner; + + private IEngine engine; + + @Override + protected void setUp() throws Exception { + super.setUp(); + IULoader.loadIUs(this); + createTestMetdataRepository(new IInstallableUnit[] {sdk1, platform1, platform2}); + planner = createPlanner(); + engine = createEngine(); + assertOK(install(profile, new IInstallableUnit[] {sdk1}, true, planner, engine)); + } + + //Verify that no plan is provided when the update is not possible + public void testInstallSDK2() { + assertNotOK(install(profile, new IInstallableUnit[] {platform2}, true, planner, engine)); + ProfileChangeRequest res = new LuckyHelper().computeProfileChangeRequest(profile, planner, null, new ProvisioningContext(getAgent()), getMonitor()); + assertNull(res); + } + +} diff --git a/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/planner/LuckyTest6.java b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/planner/LuckyTest6.java new file mode 100644 index 000000000..fb6f6ff68 --- /dev/null +++ b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/planner/LuckyTest6.java @@ -0,0 +1,59 @@ +/******************************************************************************* + * Copyright (c) 2011 Sonatype, Inc. 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 implementation and ideas + ******************************************************************************/ +package org.eclipse.equinox.p2.tests.planner; + +import org.eclipse.equinox.internal.p2.director.ProfileChangeRequest; +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.tests.*; + +public class LuckyTest6 extends AbstractProvisioningTest { + @IUDescription(content = "package: sdk \n" + "singleton: true\n" + "version: 1 \n" + "depends: platform = 1") + public IInstallableUnit sdk1; + + @IUDescription(content = "package: platform \n" + "singleton: true\n" + "version: 1 \n") + public IInstallableUnit platform1; + + @IUDescription(content = "package: sdk \n" + "singleton: true\n" + "version: 2 \n" + "depends: platform = 2") + public IInstallableUnit sdk2; + + @IUDescription(content = "package: platform \n" + "singleton: true\n" + "version: 2 \n") + public IInstallableUnit platform2; + + @IUDescription(content = "package: sdk \n" + "singleton: true\n" + "version: 3 \n" + "depends: platform = 2") + public IInstallableUnit sdk3; + + IProfile profile = createProfile("TestProfile." + getName()); + + private IPlanner planner; + + private IEngine engine; + + @Override + protected void setUp() throws Exception { + super.setUp(); + IULoader.loadIUs(this); + createTestMetdataRepository(new IInstallableUnit[] {sdk1, platform1, sdk2, sdk3, platform2}); + planner = createPlanner(); + engine = createEngine(); + assertOK(install(profile, new IInstallableUnit[] {sdk1}, true, planner, engine)); + } + + //Test that the highest version is installed + public void testInstallSDK3() { + assertNotOK(install(profile, new IInstallableUnit[] {platform2}, true, planner, engine)); + + ProfileChangeRequest res = new LuckyHelper().computeProfileChangeRequest(profile, planner, null, new ProvisioningContext(getAgent()), getMonitor()); + assertTrue(res.getAdditions().contains(sdk3)); + assertTrue(res.getRemovals().contains(sdk1)); + } + +} |