Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThomas Watson2007-06-20 20:10:39 +0000
committerThomas Watson2007-06-20 20:10:39 +0000
commita9b120ca8937b06e1e4b08b9b928ab44a69586ff (patch)
treebc4d8640a5e247661ec48847f8ce956cede77456
parent062e5e21ecd4e2c36f3730a2c4d2e673dcae7ff7 (diff)
downloadrt.equinox.framework-a9b120ca8937b06e1e4b08b9b928ab44a69586ff.tar.gz
rt.equinox.framework-a9b120ca8937b06e1e4b08b9b928ab44a69586ff.tar.xz
rt.equinox.framework-a9b120ca8937b06e1e4b08b9b928ab44a69586ff.zip
Bug 192722 [resolver] BundleDescription order may effect singleton selection
-rw-r--r--bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/services/resolver/StateResolverTest.java87
-rw-r--r--bundles/org.eclipse.osgi/resolver/src/org/eclipse/osgi/internal/module/ResolverImpl.java6
2 files changed, 92 insertions, 1 deletions
diff --git a/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/services/resolver/StateResolverTest.java b/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/services/resolver/StateResolverTest.java
index 7b1da6f4f..15b0daff9 100644
--- a/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/services/resolver/StateResolverTest.java
+++ b/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/services/resolver/StateResolverTest.java
@@ -1173,6 +1173,93 @@ public class StateResolverTest extends AbstractStateTest {
assertFalse("1.9", import10.isResolved());
}
+ public void testSingletonsSelection6() throws BundleException {
+ State state = buildEmptyState();
+
+ // test the selection algorithm of the resolver to pick the bundles which
+ // resolve the largest set of bundles
+ Hashtable manifest = new Hashtable();
+ manifest.put(Constants.BUNDLE_MANIFESTVERSION, "2");
+ manifest.put(Constants.BUNDLE_SYMBOLICNAME, "sdk; " + Constants.SINGLETON_DIRECTIVE + ":=true");
+ manifest.put(Constants.BUNDLE_VERSION, "1.0");
+ manifest.put(Constants.REQUIRE_BUNDLE, "platform; bundle-version=\"[1.0,2.0]\"");
+ BundleDescription sdk10 = state.getFactory().createBundleDescription(state, manifest, "sdk10", 0);
+
+ manifest = new Hashtable();
+ manifest.put(Constants.BUNDLE_MANIFESTVERSION, "2");
+ manifest.put(Constants.BUNDLE_SYMBOLICNAME, "platform; " + Constants.SINGLETON_DIRECTIVE + ":=true");
+ manifest.put(Constants.BUNDLE_VERSION, "1.0");
+ manifest.put(Constants.REQUIRE_BUNDLE, "rcp; bundle-version=\"[1.0,2.0]\"");
+ BundleDescription platform10 = state.getFactory().createBundleDescription(state, manifest, "platform10", 1);
+
+ manifest = new Hashtable();
+ manifest.put(Constants.BUNDLE_MANIFESTVERSION, "2");
+ manifest.put(Constants.BUNDLE_SYMBOLICNAME, "rcp; " + Constants.SINGLETON_DIRECTIVE + ":=true");
+ manifest.put(Constants.BUNDLE_VERSION, "1.0");
+ BundleDescription rcp10 = state.getFactory().createBundleDescription(state, manifest, "rcp10", 2);
+
+ manifest = new Hashtable();
+ manifest.put(Constants.BUNDLE_MANIFESTVERSION, "2");
+ manifest.put(Constants.BUNDLE_SYMBOLICNAME, "gef; " + Constants.SINGLETON_DIRECTIVE + ":=true");
+ manifest.put(Constants.BUNDLE_VERSION, "1.0");
+ manifest.put(Constants.REQUIRE_BUNDLE, "rcp; bundle-version=\"[1.0,1.0]\"");
+ BundleDescription gef10 = state.getFactory().createBundleDescription(state, manifest, "gef10", 3);
+
+ state.addBundle(sdk10);
+ state.addBundle(platform10);
+ state.addBundle(rcp10);
+ state.addBundle(gef10);
+ state.resolve();
+
+ assertTrue("1.0", sdk10.isResolved());
+ assertTrue("1.1", platform10.isResolved());
+ assertTrue("1.2", rcp10.isResolved());
+ assertTrue("1.3", gef10.isResolved());
+
+ manifest = new Hashtable();
+ manifest.put(Constants.BUNDLE_MANIFESTVERSION, "2");
+ manifest.put(Constants.BUNDLE_SYMBOLICNAME, "sdk; " + Constants.SINGLETON_DIRECTIVE + ":=true");
+ manifest.put(Constants.BUNDLE_VERSION, "2.0");
+ manifest.put(Constants.REQUIRE_BUNDLE, "platform; bundle-version=\"[1.0,2.0]\"");
+ BundleDescription sdk20 = state.getFactory().createBundleDescription(state, manifest, "sdk20", 4);
+
+ manifest = new Hashtable();
+ manifest.put(Constants.BUNDLE_MANIFESTVERSION, "2");
+ manifest.put(Constants.BUNDLE_SYMBOLICNAME, "platform; " + Constants.SINGLETON_DIRECTIVE + ":=true");
+ manifest.put(Constants.BUNDLE_VERSION, "2.0");
+ manifest.put(Constants.REQUIRE_BUNDLE, "rcp; bundle-version=\"[1.0,2.0]\"");
+ BundleDescription platform20 = state.getFactory().createBundleDescription(state, manifest, "platform20", 5);
+
+ manifest = new Hashtable();
+ manifest.put(Constants.BUNDLE_MANIFESTVERSION, "2");
+ manifest.put(Constants.BUNDLE_SYMBOLICNAME, "rcp; " + Constants.SINGLETON_DIRECTIVE + ":=true");
+ manifest.put(Constants.BUNDLE_VERSION, "2.0");
+ BundleDescription rcp20 = state.getFactory().createBundleDescription(state, manifest, "rcp20", 6);
+
+ state.removeBundle(sdk10);
+ state.removeBundle(platform10);
+ state.removeBundle(rcp10);
+ state.removeBundle(gef10);
+
+ // reorder the bundles to test that order of bundles does not effect resolution outcome
+ state.addBundle(sdk20);
+ state.addBundle(platform20);
+ state.addBundle(rcp20);
+ state.addBundle(sdk10);
+ state.addBundle(platform10);
+ state.addBundle(rcp10);
+ state.addBundle(gef10);
+ state.resolve(false);
+
+ assertTrue("2.0", sdk20.isResolved());
+ assertTrue("2.1", platform20.isResolved());
+ assertTrue("2.2", rcp10.isResolved());
+ assertTrue("2.3", gef10.isResolved());
+ assertFalse("2.4", sdk10.isResolved());
+ assertFalse("2.5", platform10.isResolved());
+ assertFalse("2.6", rcp20.isResolved());
+ }
+
public void testNonSingletonsSameVersion() throws BundleException {
// this is a testcase to handle how PDE build is using the state
// with multiple singleton bundles installed with the same BSN and version
diff --git a/bundles/org.eclipse.osgi/resolver/src/org/eclipse/osgi/internal/module/ResolverImpl.java b/bundles/org.eclipse.osgi/resolver/src/org/eclipse/osgi/internal/module/ResolverImpl.java
index 49d6eed17..47265f659 100644
--- a/bundles/org.eclipse.osgi/resolver/src/org/eclipse/osgi/internal/module/ResolverImpl.java
+++ b/bundles/org.eclipse.osgi/resolver/src/org/eclipse/osgi/internal/module/ResolverImpl.java
@@ -841,7 +841,11 @@ public class ResolverImpl implements org.eclipse.osgi.service.resolver.Resolver
continue; // Ignore the bundle we are selecting, non-singletons, and non-resolved
result = true;
boolean rejectedPolicy = selectionPolicy != null ? selectionPolicy.compare(sameNameDesc, bundleDesc) < 0 : sameNameDesc.getVersion().compareTo(bundleDesc.getVersion()) > 0;
- if (rejectedPolicy && sameNameBundle.getRefs() >= bundles[i].getRefs()) {
+ int sameNameRefs = sameNameBundle.getRefs();
+ int curRefs = bundles[i].getRefs();
+ // a bundle is always rejected if another bundle has more references to it;
+ // otherwise a bundle is rejected based on the selection policy (version) only if the number of references are equal
+ if ((sameNameRefs == curRefs && rejectedPolicy) || sameNameRefs > curRefs) {
// this bundle is not selected; add it to the rejected list
if (!rejectedSingletons.contains(bundles[i].getBundle()))
rejectedSingletons.add(bundles[i].getBundle());

Back to the top