use of org.eclipse.osgi.service.resolver.State in project rt.equinox.framework by eclipse.
the class StateResolverTest method testSingletons.
public void testSingletons() throws BundleException {
State state = buildEmptyState();
Hashtable manifest = new Hashtable();
// $NON-NLS-1$
manifest.put(Constants.BUNDLE_MANIFESTVERSION, "2");
// $NON-NLS-1$
manifest.put(Constants.BUNDLE_SYMBOLICNAME, "test.host; singleton:=true");
// $NON-NLS-1$
manifest.put(Constants.BUNDLE_VERSION, "1.0.0");
// $NON-NLS-1$
BundleDescription testHost100 = state.getFactory().createBundleDescription(state, manifest, "test.host100", 0);
manifest = new Hashtable();
// $NON-NLS-1$
manifest.put(Constants.BUNDLE_MANIFESTVERSION, "2");
// $NON-NLS-1$
manifest.put(Constants.BUNDLE_SYMBOLICNAME, "test.host; singleton:=true");
// $NON-NLS-1$
manifest.put(Constants.BUNDLE_VERSION, "1.0.1");
// $NON-NLS-1$
BundleDescription testHost101 = state.getFactory().createBundleDescription(state, manifest, "test.host101", 1);
manifest = new Hashtable();
// $NON-NLS-1$
manifest.put(Constants.BUNDLE_MANIFESTVERSION, "2");
// $NON-NLS-1$
manifest.put(Constants.BUNDLE_SYMBOLICNAME, "test.frag; singleton:=true");
// $NON-NLS-1$
manifest.put(Constants.FRAGMENT_HOST, "test.host; bundle-version=\"[1.0.0,2.0.0)\"");
// $NON-NLS-1$
manifest.put(Constants.BUNDLE_VERSION, "1.0.0");
// $NON-NLS-1$
BundleDescription testFrag100 = state.getFactory().createBundleDescription(state, manifest, "test.frag100", 2);
manifest = new Hashtable();
// $NON-NLS-1$
manifest.put(Constants.BUNDLE_MANIFESTVERSION, "2");
// $NON-NLS-1$
manifest.put(Constants.BUNDLE_SYMBOLICNAME, "test.frag; singleton:=true");
// $NON-NLS-1$
manifest.put(Constants.FRAGMENT_HOST, "test.host; bundle-version=\"[1.0.0,2.0.0)\"");
// $NON-NLS-1$
manifest.put(Constants.BUNDLE_VERSION, "1.0.1");
// $NON-NLS-1$
BundleDescription testFrag101 = state.getFactory().createBundleDescription(state, manifest, "test.frag101", 3);
manifest = new Hashtable();
// $NON-NLS-1$
manifest.put(Constants.BUNDLE_MANIFESTVERSION, "2");
// $NON-NLS-1$
manifest.put(Constants.BUNDLE_SYMBOLICNAME, "test.dependent; singleton:=true");
// $NON-NLS-1$
manifest.put(Constants.REQUIRE_BUNDLE, "test.host; bundle-version=\"[1.0.1,2.0.0)\"");
// $NON-NLS-1$
manifest.put(Constants.BUNDLE_VERSION, "1.0.0");
// $NON-NLS-1$
BundleDescription testDependent = state.getFactory().createBundleDescription(state, manifest, "test.frag101", 4);
state.addBundle(testHost100);
state.addBundle(testFrag100);
state.addBundle(testHost101);
state.addBundle(testFrag101);
state.addBundle(testDependent);
state.resolve();
// $NON-NLS-1$
assertFalse("1.0", testHost100.isResolved());
// $NON-NLS-1$
assertTrue("1.1", testHost101.isResolved());
// $NON-NLS-1$
assertFalse("1.2", testFrag100.isResolved());
// $NON-NLS-1$
assertTrue("1.3", testFrag101.isResolved());
// $NON-NLS-1$
assertTrue("1.4", testDependent.isResolved());
}
use of org.eclipse.osgi.service.resolver.State in project rt.equinox.framework by eclipse.
the class StateResolverTest method testLinkageChange.
// temporarily disabled
public void testLinkageChange() throws BundleException {
State state = buildEmptyState();
// don't add b1 for now
// $NON-NLS-1$
String B1_LOCATION = "org.eclipse.b1";
// $NON-NLS-1$ //$NON-NLS-2$
final String B1_MANIFEST = "Bundle-SymbolicName: org.eclipse.b1\n" + "Bundle-Version: 1.0\n";
BundleDescription b1 = state.getFactory().createBundleDescription(parseManifest(B1_MANIFEST), B1_LOCATION, (long) (Math.random() * Long.MAX_VALUE));
// b2 requires b1 optionally, so should resolve
// $NON-NLS-1$
String B2_LOCATION = "org.eclipse.b2";
// $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
final String B2_MANIFEST = "Bundle-SymbolicName: org.eclipse.b2\n" + "Bundle-Version: 2.0\n" + "Require-Bundle: org.eclipse.b1;optional=true";
BundleDescription b2 = state.getFactory().createBundleDescription(parseManifest(B2_MANIFEST), B2_LOCATION, (long) (Math.random() * Long.MAX_VALUE));
// b3 requires b1, so should not resolve
// $NON-NLS-1$
String B3_LOCATION = "org.eclipse.b3";
// $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
final String B3_MANIFEST = "Bundle-SymbolicName: org.eclipse.b3\n" + "Bundle-Version: 2.0\n" + "Require-Bundle: org.eclipse.b1";
BundleDescription b3 = state.getFactory().createBundleDescription(parseManifest(B3_MANIFEST), B3_LOCATION, (long) (Math.random() * Long.MAX_VALUE));
// add b2 and b3
state.addBundle(b2);
state.addBundle(b3);
StateDelta delta = state.resolve();
// ensure we didn't add b1 yet
// $NON-NLS-1$
assertFullyUnresolved("0.1", b1);
BundleDelta[] changes = delta.getChanges();
// $NON-NLS-1$
assertEquals("1.0", 2, changes.length);
BundleDelta[] additions = delta.getChanges(BundleDelta.ADDED, false);
// $NON-NLS-1$
assertEquals("2.0", 2, additions.length);
BundleDelta[] resolutions = delta.getChanges(BundleDelta.RESOLVED, false);
// $NON-NLS-1$
assertEquals("3.0", 1, resolutions.length);
// $NON-NLS-1$
assertEquals("3.1", b2, resolutions[0].getBundle());
BundleDelta[] addtionsNotResolved = delta.getChanges(BundleDelta.ADDED, true);
// $NON-NLS-1$
assertEquals("4.0", 1, addtionsNotResolved.length);
// $NON-NLS-1$
assertEquals("4.1", b3, addtionsNotResolved[0].getBundle());
state.addBundle(b1);
delta = state.resolve();
changes = delta.getChanges();
// $NON-NLS-1$
assertEquals("5.0", 2, changes.length);
additions = delta.getChanges(BundleDelta.ADDED, false);
// $NON-NLS-1$
assertEquals("6.0", 1, additions.length);
// $NON-NLS-1$
assertEquals("6.1", b1, additions[0].getBundle());
resolutions = delta.getChanges(BundleDelta.RESOLVED, false);
// $NON-NLS-1$
assertEquals("7.0", 2, resolutions.length);
BundleDelta[] existingResolved = delta.getChanges(BundleDelta.RESOLVED, true);
// $NON-NLS-1$
assertEquals("8.0", 1, existingResolved.length);
// $NON-NLS-1$
assertEquals("8.1", b3, existingResolved[0].getBundle());
// TODO linkage changed types are no longer valid
// BundleDelta[] optionalLinkageChanged = delta.getChanges(BundleDelta.OPTIONAL_LINKAGE_CHANGED, true);
// assertEquals("9.0", 1, optionalLinkageChanged.length);
// assertEquals("9.1", b2, optionalLinkageChanged[0].getBundle());
delta = state.resolve(new BundleDescription[] { b2 });
changes = delta.getChanges();
// $NON-NLS-1$
assertEquals("9.0", 1, changes.length);
resolutions = delta.getChanges(BundleDelta.RESOLVED, true);
// $NON-NLS-1$
assertEquals("9.1", 1, resolutions.length);
// $NON-NLS-1$
assertEquals("9.2", b2, resolutions[0].getBundle());
// $NON-NLS-1$
assertFullyResolved("10.1", b1);
// $NON-NLS-1$
assertFullyResolved("10.2", b2);
// $NON-NLS-1$
assertFullyResolved("10.3", b3);
}
use of org.eclipse.osgi.service.resolver.State in project rt.equinox.framework by eclipse.
the class StateResolverTest method testPlatformProperties02.
public void testPlatformProperties02() throws BundleException {
// same as 01 except use alias system.bundle to another name "test.system.bundle"
State state = buildEmptyState();
int bundleID = 0;
// test the selection algorithm of the resolver to pick the bundles which
// resolve the largest set of bundles; with fragments using Import-Package
Hashtable manifest = new Hashtable();
// $NON-NLS-1$
manifest.put(Constants.BUNDLE_MANIFESTVERSION, "2");
// $NON-NLS-1$
manifest.put(Constants.BUNDLE_SYMBOLICNAME, "test.system.bundle");
// $NON-NLS-1$
manifest.put(Constants.BUNDLE_VERSION, "1.0");
// $NON-NLS-1$
BundleDescription systemBundle = state.getFactory().createBundleDescription(state, manifest, "test.system.bundle", bundleID++);
// $NON-NLS-1$
manifest.put(Constants.BUNDLE_MANIFESTVERSION, "2");
// $NON-NLS-1$
manifest.put(Constants.BUNDLE_SYMBOLICNAME, "A");
// $NON-NLS-1$
manifest.put(Constants.BUNDLE_VERSION, "1.0");
// $NON-NLS-1$
manifest.put(Constants.IMPORT_PACKAGE, "pkg.b, pkg.system.b");
// $NON-NLS-1$
manifest.put(Constants.BUNDLE_REQUIREDEXECUTIONENVIRONMENT, "J2SE-1.4");
// $NON-NLS-1$
BundleDescription a = state.getFactory().createBundleDescription(state, manifest, "A", bundleID++);
// $NON-NLS-1$
manifest.put(Constants.BUNDLE_MANIFESTVERSION, "2");
// $NON-NLS-1$
manifest.put(Constants.BUNDLE_SYMBOLICNAME, "B");
// $NON-NLS-1$
manifest.put(Constants.BUNDLE_VERSION, "1.0");
// $NON-NLS-1$
manifest.put(Constants.EXPORT_PACKAGE, "pkg.b");
// $NON-NLS-1$
manifest.put(Constants.IMPORT_PACKAGE, "pkg.system.b");
// $NON-NLS-1$
manifest.put(Constants.BUNDLE_REQUIREDEXECUTIONENVIRONMENT, "J2SE-1.2");
// $NON-NLS-1$
BundleDescription b = state.getFactory().createBundleDescription(state, manifest, "B", bundleID++);
// $NON-NLS-1$
manifest.put(Constants.BUNDLE_MANIFESTVERSION, "2");
// $NON-NLS-1$
manifest.put(Constants.BUNDLE_SYMBOLICNAME, "system.b");
// $NON-NLS-1$
manifest.put(Constants.BUNDLE_VERSION, "1.0");
// $NON-NLS-1$
manifest.put(Constants.EXPORT_PACKAGE, "pkg.system.b");
// $NON-NLS-1$
manifest.put(Constants.BUNDLE_REQUIREDEXECUTIONENVIRONMENT, "J2SE-1.2");
// $NON-NLS-1$
BundleDescription systemB = state.getFactory().createBundleDescription(state, manifest, "system.b", bundleID++);
Dictionary[] props = new Dictionary[] { new Hashtable(), new Hashtable() };
// $NON-NLS-1$ //$NON-NLS-2$
props[0].put("org.osgi.framework.system.packages", "pkg.system.a, pkg.system.c");
// $NON-NLS-1$ //$NON-NLS-2$
props[0].put("org.osgi.framework.executionenvironment", "J2SE-1.2");
// set the system.bundle to another system bundle (other than org.eclipse.osgi) //$NON-NLS-1$ //$NON-NLS-2$
props[0].put("osgi.system.bundle", "test.system.bundle");
// $NON-NLS-1$ //$NON-NLS-2$
props[1].put("org.osgi.framework.system.packages", "pkg.system.a, pkg.system.b, pkg.system.c");
// $NON-NLS-1$ //$NON-NLS-2$
props[1].put("org.osgi.framework.executionenvironment", "J2SE-1.4");
state.setPlatformProperties(props);
state.addBundle(systemBundle);
state.addBundle(a);
state.addBundle(b);
state.addBundle(systemB);
state.resolve();
// $NON-NLS-1$
assertTrue("1.0", systemBundle.isResolved());
// $NON-NLS-1$
assertTrue("1.1", a.isResolved());
// $NON-NLS-1$
assertTrue("1.2", b.isResolved());
// $NON-NLS-1$
assertTrue("1.3", systemB.isResolved());
// $NON-NLS-1$
assertTrue("2.0", a.getResolvedImports()[1].getExporter() == systemBundle);
// $NON-NLS-1$
assertTrue("2.1", b.getResolvedImports()[0].getExporter() == systemB);
// now test the uses clause for pkg.b such that bundle 'A' will be forced to used
// pkg.system from bundle 'system.b'
// $NON-NLS-1$
manifest.put(Constants.BUNDLE_MANIFESTVERSION, "2");
// $NON-NLS-1$
manifest.put(Constants.BUNDLE_SYMBOLICNAME, "B");
// $NON-NLS-1$
manifest.put(Constants.BUNDLE_VERSION, "1.0");
// $NON-NLS-1$
manifest.put(Constants.EXPORT_PACKAGE, "pkg.b; uses:=\"pkg.system.b\"");
// $NON-NLS-1$
manifest.put(Constants.IMPORT_PACKAGE, "pkg.system.b");
// $NON-NLS-1$
manifest.put(Constants.BUNDLE_REQUIREDEXECUTIONENVIRONMENT, "J2SE-1.2");
// $NON-NLS-1$
BundleDescription b_updated = state.getFactory().createBundleDescription(state, manifest, "B", b.getBundleId());
state.updateBundle(b_updated);
state.resolve(new BundleDescription[] { b_updated });
// $NON-NLS-1$
assertTrue("3.0", systemBundle.isResolved());
// $NON-NLS-1$
assertTrue("3.1", a.isResolved());
// $NON-NLS-1$
assertTrue("3.2", b_updated.isResolved());
// $NON-NLS-1$
assertTrue("3.3", systemB.isResolved());
// $NON-NLS-1$
assertTrue("2.0", a.getResolvedImports()[1].getExporter() == systemB);
// $NON-NLS-1$
assertTrue("2.1", b_updated.getResolvedImports()[0].getExporter() == systemB);
}
use of org.eclipse.osgi.service.resolver.State in project rt.equinox.framework by eclipse.
the class StateResolverTest method createBug266935State.
private State createBug266935State() throws BundleException {
State state = buildEmptyState();
int bundleID = 0;
// test the selection algorithm of the resolver to pick the bundles which
// resolve the largest set of bundles; with fragments
Hashtable manifest = new Hashtable();
manifest.clear();
// $NON-NLS-1$
manifest.put(Constants.BUNDLE_MANIFESTVERSION, "2");
// $NON-NLS-1$
manifest.put(Constants.BUNDLE_SYMBOLICNAME, "a");
// $NON-NLS-1$
manifest.put(Constants.BUNDLE_VERSION, "1.0.0");
BundleDescription a = state.getFactory().createBundleDescription(state, manifest, (String) manifest.get(Constants.BUNDLE_SYMBOLICNAME) + manifest.get(Constants.BUNDLE_VERSION), bundleID++);
manifest.clear();
// $NON-NLS-1$
manifest.put(Constants.BUNDLE_MANIFESTVERSION, "2");
// $NON-NLS-1$
manifest.put(Constants.BUNDLE_SYMBOLICNAME, "b");
// $NON-NLS-1$
manifest.put(Constants.BUNDLE_VERSION, "1.0.0");
// $NON-NLS-1$
manifest.put(Constants.REQUIRE_BUNDLE, "a");
BundleDescription b = state.getFactory().createBundleDescription(state, manifest, (String) manifest.get(Constants.BUNDLE_SYMBOLICNAME) + manifest.get(Constants.BUNDLE_VERSION), bundleID++);
state.addBundle(a);
state.addBundle(b);
state.resolve();
// $NON-NLS-1$
assertTrue("A is not resolved", a.isResolved());
// $NON-NLS-1$
assertTrue("B is not resolved", b.isResolved());
return state;
}
use of org.eclipse.osgi.service.resolver.State in project rt.equinox.framework by eclipse.
the class StateResolverTest method testFragmentsBug188199.
public void testFragmentsBug188199() throws BundleException {
State state = buildEmptyState();
int bundleID = 0;
// test the selection algorithm of the resolver to pick the bundles which
// resolve the largest set of bundles; with fragments using Import-Package
Hashtable manifest = new Hashtable();
// $NON-NLS-1$
manifest.put(Constants.BUNDLE_MANIFESTVERSION, "2");
// $NON-NLS-1$
manifest.put(Constants.BUNDLE_SYMBOLICNAME, "A");
// $NON-NLS-1$
manifest.put(Constants.BUNDLE_VERSION, "1.0");
// $NON-NLS-1$
manifest.put(Constants.EXPORT_PACKAGE, "a");
// $NON-NLS-1$
manifest.put(Constants.IMPORT_PACKAGE, "c");
// $NON-NLS-1$
BundleDescription a = state.getFactory().createBundleDescription(state, manifest, "A", bundleID++);
manifest.clear();
// $NON-NLS-1$
manifest.put(Constants.BUNDLE_MANIFESTVERSION, "2");
// $NON-NLS-1$
manifest.put(Constants.BUNDLE_SYMBOLICNAME, "AFrag");
// $NON-NLS-1$
manifest.put(Constants.BUNDLE_VERSION, "1.0");
// $NON-NLS-1$
manifest.put(Constants.FRAGMENT_HOST, "A");
// $NON-NLS-1$
manifest.put(Constants.EXPORT_PACKAGE, "a.frag");
// $NON-NLS-1$
BundleDescription aFrag = state.getFactory().createBundleDescription(state, manifest, "A", bundleID++);
manifest.clear();
// $NON-NLS-1$
manifest.put(Constants.BUNDLE_MANIFESTVERSION, "2");
// $NON-NLS-1$
manifest.put(Constants.BUNDLE_SYMBOLICNAME, "B");
// $NON-NLS-1$
manifest.put(Constants.BUNDLE_VERSION, "1.0");
// $NON-NLS-1$
manifest.put(Constants.IMPORT_PACKAGE, "a, a.frag");
// $NON-NLS-1$
BundleDescription b = state.getFactory().createBundleDescription(state, manifest, "B", bundleID++);
manifest.clear();
// $NON-NLS-1$
manifest.put(Constants.BUNDLE_MANIFESTVERSION, "2");
// $NON-NLS-1$
manifest.put(Constants.BUNDLE_SYMBOLICNAME, "C");
// $NON-NLS-1$
manifest.put(Constants.BUNDLE_VERSION, "1.0");
// $NON-NLS-1$
manifest.put(Constants.EXPORT_PACKAGE, "c");
// $NON-NLS-1$
BundleDescription c = state.getFactory().createBundleDescription(state, manifest, "C", bundleID++);
state.addBundle(a);
state.addBundle(aFrag);
state.addBundle(b);
state.addBundle(c);
state.resolve();
// $NON-NLS-1$
assertTrue("0.1", a.isResolved());
// $NON-NLS-1$
assertTrue("0.2", aFrag.isResolved());
// $NON-NLS-1$
assertTrue("0.3", b.isResolved());
// $NON-NLS-1$
assertTrue("0.4", c.isResolved());
state.removeBundle(c);
state.resolve(false);
// $NON-NLS-1$
assertFalse("1.1", a.isResolved());
// $NON-NLS-1$
assertFalse("1.2", aFrag.isResolved());
// $NON-NLS-1$
assertFalse("1.3", b.isResolved());
state.addBundle(c);
state.resolve();
// $NON-NLS-1$
assertTrue("2.1", a.isResolved());
// $NON-NLS-1$
assertTrue("2.2", aFrag.isResolved());
// $NON-NLS-1$
assertTrue("2.3", b.isResolved());
// $NON-NLS-1$
assertTrue("2.4", c.isResolved());
ExportPackageDescription[] aExports = a.getSelectedExports();
ExportPackageDescription[] bImports = b.getResolvedImports();
// $NON-NLS-1$
assertTrue("3.1", aExports.length == 2);
// $NON-NLS-1$
assertTrue("3.2", bImports.length == 2);
// $NON-NLS-1$
assertTrue("3.3", aExports[0] == bImports[0]);
// $NON-NLS-1$
assertTrue("3.4", aExports[1] == bImports[1]);
}
Aggregations