Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorprapicau2011-12-31 20:42:18 +0000
committerprapicau2011-12-31 20:42:18 +0000
commit84f87c957c51ee071101132ee112cf3f4a9bc84f (patch)
treea30f521e6231efc8ee3685a55645dd96ba594d1d
parent4174108261eddcb3cd45006d5f1f7631e4a2a2d9 (diff)
downloadrt.equinox.p2-84f87c957c51ee071101132ee112cf3f4a9bc84f.tar.gz
rt.equinox.p2-84f87c957c51ee071101132ee112cf3f4a9bc84f.tar.xz
rt.equinox.p2-84f87c957c51ee071101132ee112cf3f4a9bc84f.zip
Take into account additions and removals when looking for best solutionv20111231-2042
-rw-r--r--bundles/org.eclipse.equinox.p2.director/META-INF/MANIFEST.MF2
-rw-r--r--bundles/org.eclipse.equinox.p2.director/src/org/eclipse/equinox/p2/planner/IProfileChangeRequest.java5
-rw-r--r--bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/planner/LuckyHelper.java38
-rw-r--r--bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/planner/LuckyTest7.java68
-rw-r--r--bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/planner/LuckyTest8.java69
-rw-r--r--bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/planner/LuckyTest9.java71
6 files changed, 246 insertions, 7 deletions
diff --git a/bundles/org.eclipse.equinox.p2.director/META-INF/MANIFEST.MF b/bundles/org.eclipse.equinox.p2.director/META-INF/MANIFEST.MF
index 8ee244710..5bea11eec 100644
--- a/bundles/org.eclipse.equinox.p2.director/META-INF/MANIFEST.MF
+++ b/bundles/org.eclipse.equinox.p2.director/META-INF/MANIFEST.MF
@@ -2,7 +2,7 @@ Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: %pluginName
Bundle-SymbolicName: org.eclipse.equinox.p2.director;singleton:=true
-Bundle-Version: 2.1.100.qualifier
+Bundle-Version: 2.2.0.qualifier
Bundle-ClassPath: .
Bundle-Activator: org.eclipse.equinox.internal.p2.director.DirectorActivator
Bundle-Vendor: %providerName
diff --git a/bundles/org.eclipse.equinox.p2.director/src/org/eclipse/equinox/p2/planner/IProfileChangeRequest.java b/bundles/org.eclipse.equinox.p2.director/src/org/eclipse/equinox/p2/planner/IProfileChangeRequest.java
index ecb953e97..2cbe5f7c8 100644
--- a/bundles/org.eclipse.equinox.p2.director/src/org/eclipse/equinox/p2/planner/IProfileChangeRequest.java
+++ b/bundles/org.eclipse.equinox.p2.director/src/org/eclipse/equinox/p2/planner/IProfileChangeRequest.java
@@ -122,4 +122,9 @@ public interface IProfileChangeRequest {
*/
public abstract Collection<IInstallableUnit> getRemovals();
+ /**
+ * Get the extra requirements that have been specified through method {@link #addExtraRequirements(Collection)}
+ * @since 2.2
+ */
+ public abstract Collection<IRequirement> getExtraRequirements();
} \ No newline at end of file
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 e813a8a58..fd5304713 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
@@ -20,23 +20,43 @@ import org.eclipse.equinox.p2.planner.*;
import org.eclipse.equinox.p2.query.*;
public class LuckyHelper {
- ProfileChangeRequest computeProfileChangeRequest(IProfile profile, IPlanner planner, ProfileChangeRequest request, ProvisioningContext context, IProgressMonitor monitor) {
+ private final String INCLUSION_RULES = "org.eclipse.equinox.p2.internal.inclusion.rules"; //$NON-NLS-1$
+
+ ProfileChangeRequest computeProfileChangeRequest(IProfile profile, IPlanner planner, IProfileChangeRequest originalRequest, ProvisioningContext context, IProgressMonitor monitor) {
// IProfileRegistry profileRegistry = (IProfileRegistry) session.getProvisioningAgent().getService(IProfileRegistry.SERVICE_NAME);
IPlanner plan = planner; //(IPlanner) session.getProvisioningAgent().getService(IPlanner.SERVICE_NAME);
IProfile prof = profile; //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());
+ Set<IInstallableUnit> strictRoots = prof.query(new IUProfilePropertyQuery(INCLUSION_RULES, INCLUSION_STRICT), null).toSet();
+ Set<IInstallableUnit> optionalRoots = prof.query(new IUProfilePropertyQuery(INCLUSION_RULES, INCLUSION_OPTIONAL), null).toSet();
+
+ //Take into account the changes from the request (potential addition or removals)
+ if (originalRequest != null) {
+ strictRoots.removeAll(originalRequest.getRemovals());
+ optionalRoots.removeAll(originalRequest.getRemovals());
+ Collection<IInstallableUnit> added = originalRequest.getAdditions();
+ for (IInstallableUnit iuAdded : added) {
+ Map props = ((ProfileChangeRequest) originalRequest).getInstallableUnitProfilePropertiesToAdd();
+ Map propertyForIU = (Map) props.get(iuAdded);
+ if (propertyForIU == null || INCLUSION_STRICT.equals(propertyForIU.get(INCLUSION_RULES))) {
+ strictRoots.add(iuAdded);
+ } else if (INCLUSION_OPTIONAL.equals(propertyForIU.get(INCLUSION_RULES))) {
+ optionalRoots.add(iuAdded);
+ }
+ }
+ }
+
+ Set<IInstallableUnit> tmpRoots = new HashSet<IInstallableUnit>(strictRoots);
+ tmpRoots.addAll(optionalRoots);
+
CollectionResult<IInstallableUnit> allInitialRoots = new CollectionResult<IInstallableUnit>(tmpRoots);
ProfileChangeRequest updateFinderRequest = (ProfileChangeRequest) plan.createChangeRequest(prof);
Collection<IRequirement> limitingRequirements = new ArrayList<IRequirement>();
+ limitingRequirements.addAll(originalRequest.getExtraRequirements());
//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();) {
@@ -63,6 +83,7 @@ public class LuckyHelper {
//Take into account all the removals
IProfileChangeRequest finalChangeRequest = plan.createChangeRequest(prof);
+ finalChangeRequest.addExtraRequirements(originalRequest.getExtraRequirements());
IQueryResult<IInstallableUnit> removals = updateFinderPlan.getRemovals().query(QueryUtil.ALL_UNITS, null);
for (Iterator<IInstallableUnit> iterator = removals.iterator(); iterator.hasNext();) {
IInstallableUnit iu = iterator.next();
@@ -77,6 +98,8 @@ public class LuckyHelper {
IQueryResult<IInstallableUnit> update = updateFinderPlan.getAdditions().query(new UpdateQuery(formerRoot), null);
if (!update.isEmpty())
finalChangeRequest.addAll(update.toUnmodifiableSet());
+ else if (originalRequest.getAdditions().contains(formerRoot)) //deal with the case of the elements added by the request
+ finalChangeRequest.add(formerRoot);
}
//Take into account the additions for optionals
@@ -89,6 +112,9 @@ public class LuckyHelper {
finalChangeRequest.add(updatedOptionalIU);
finalChangeRequest.setInstallableUnitInclusionRules(updatedOptionalIU, ProfileInclusionRules.createOptionalInclusionRule(updatedOptionalIU));
}
+ } else if (originalRequest.getAdditions().contains(formerRoot)) {
+ finalChangeRequest.add(formerRoot);
+ finalChangeRequest.setInstallableUnitInclusionRules(formerRoot, ProfileInclusionRules.createOptionalInclusionRule(formerRoot));
}
}
return (ProfileChangeRequest) finalChangeRequest;
diff --git a/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/planner/LuckyTest7.java b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/planner/LuckyTest7.java
new file mode 100644
index 000000000..74cde18a4
--- /dev/null
+++ b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/planner/LuckyTest7.java
@@ -0,0 +1,68 @@
+/*******************************************************************************
+ * 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.planner.IProfileChangeRequest;
+import org.eclipse.equinox.p2.tests.*;
+
+public class LuckyTest7 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: egit \n" + "singleton: true\n" + "version: 2 \n" + "depends: platform = 2")
+ public IInstallableUnit egit2;
+
+ 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, platform2, egit2});
+ planner = createPlanner();
+ engine = createEngine();
+ assertOK(install(profile, new IInstallableUnit[] {sdk1}, true, planner, engine));
+ }
+
+ public void testInstallGit2WhichShouldUpdateSDK() {
+ IProfileChangeRequest changeRequest = new ProfileChangeRequest(profile);
+ changeRequest.add(egit2);
+ assertNotOK(planner.getProvisioningPlan(changeRequest, null, null).getStatus());
+
+ ProfileChangeRequest res = new LuckyHelper().computeProfileChangeRequest(profile, planner, changeRequest, new ProvisioningContext(getAgent()), getMonitor());
+ assertEquals(2, res.getAdditions().size());
+ assertTrue(res.getAdditions().contains(sdk2));
+ assertEquals(1, res.getRemovals().size());
+ assertTrue(res.getRemovals().contains(sdk1));
+ assertTrue(res.getAdditions().contains(egit2));
+
+ 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("STRICT", 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/LuckyTest8.java b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/planner/LuckyTest8.java
new file mode 100644
index 000000000..7a2750a7a
--- /dev/null
+++ b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/planner/LuckyTest8.java
@@ -0,0 +1,69 @@
+/*******************************************************************************
+ * 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.*;
+import org.eclipse.equinox.p2.query.QueryUtil;
+import org.eclipse.equinox.p2.tests.*;
+
+public class LuckyTest8 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: egit \n" + "singleton: true\n" + "version: 2 \n" + "depends: platform = 2")
+ public IInstallableUnit egit2;
+
+ 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, platform2, egit2});
+ planner = createPlanner();
+ engine = createEngine();
+ assertOK(install(profile, new IInstallableUnit[] {sdk1}, true, planner, engine));
+ }
+
+ public void testInstallGit2OptionallyWhichShouldUpdateSDK() {
+ IProfileChangeRequest changeRequest = new ProfileChangeRequest(profile);
+ changeRequest.add(egit2);
+ changeRequest.setInstallableUnitInclusionRules(egit2, ProfileInclusionRules.createOptionalInclusionRule(egit2));
+ assertTrue(planner.getProvisioningPlan(changeRequest, null, null).getAdditions().query(QueryUtil.createIUQuery(egit2), null).isEmpty());
+
+ ProfileChangeRequest res = new LuckyHelper().computeProfileChangeRequest(profile, planner, changeRequest, new ProvisioningContext(getAgent()), getMonitor());
+ assertEquals(2, res.getAdditions().size());
+ assertTrue(res.getAdditions().contains(sdk2));
+ assertEquals(1, res.getRemovals().size());
+ assertTrue(res.getRemovals().contains(sdk1));
+ assertTrue(res.getAdditions().contains(egit2));
+
+ 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("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/LuckyTest9.java b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/planner/LuckyTest9.java
new file mode 100644
index 000000000..e07b59f04
--- /dev/null
+++ b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/planner/LuckyTest9.java
@@ -0,0 +1,71 @@
+/*******************************************************************************
+ * 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.planner.IProfileChangeRequest;
+import org.eclipse.equinox.p2.query.QueryUtil;
+import org.eclipse.equinox.p2.tests.*;
+
+public class LuckyTest9 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: egit \n" + "singleton: true\n" + "version: 1 \n" + "depends: platform = 1")
+ public IInstallableUnit egit1;
+
+ @IUDescription(content = "package: egit \n" + "singleton: true\n" + "version: 2 \n" + "depends: platform = 2")
+ public IInstallableUnit egit2;
+
+ 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, platform2, egit1, egit2});
+ planner = createPlanner();
+ engine = createEngine();
+ assertOK(install(profile, new IInstallableUnit[] {sdk1}, true, planner, engine));
+ }
+
+ public void testRemovalIsTakenIntoAccount() {
+ IProfileChangeRequest changeRequest = new ProfileChangeRequest(profile);
+ changeRequest.remove(egit1);
+
+ ProfileChangeRequest res = new LuckyHelper().computeProfileChangeRequest(profile, planner, changeRequest, new ProvisioningContext(getAgent()), getMonitor());
+ assertEquals(1, res.getAdditions().size());
+ assertTrue(res.getAdditions().contains(sdk2));
+ assertEquals(1, res.getRemovals().size());
+ assertTrue(res.getRemovals().contains(sdk1));
+
+ assertOK(install(res, planner, engine));
+ assertProfileContains("validate new profile", profile, new IInstallableUnit[] {sdk2, platform2});
+ assertTrue(profile.query(QueryUtil.createIUQuery(egit1), null).isEmpty());
+ assertTrue(profile.query(QueryUtil.createIUQuery(egit2), null).isEmpty());
+ assertEquals("STRICT", profile.getInstallableUnitProperty(sdk2, "org.eclipse.equinox.p2.internal.inclusion.rules"));
+ }
+}

Back to the top