use of org.eclipse.osgi.service.resolver.State in project rt.equinox.framework by eclipse.
the class StateResolverTest method testBug369880.
public void testBug369880() throws BundleException {
State state = buildEmptyState();
Dictionary[] props = new Dictionary[] { new Hashtable() };
// $NON-NLS-1$ //$NON-NLS-2$
props[0].put("org.osgi.framework.executionenvironment", "test");
state.setPlatformProperties(props);
int bundleID = 0;
Hashtable manifest = new Hashtable();
manifest.clear();
// $NON-NLS-1$
manifest.put(Constants.BUNDLE_MANIFESTVERSION, "2");
// $NON-NLS-1$
manifest.put(Constants.BUNDLE_SYMBOLICNAME, "org.eclipse.osgi");
// $NON-NLS-1$
manifest.put(Constants.BUNDLE_VERSION, "1.0.0");
manifest.put(Constants.BUNDLE_REQUIREDEXECUTIONENVIRONMENT, "test");
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.FRAGMENT_HOST, "org.eclipse.osgi; bundle-version=\"[1.0, 1.1)\"");
manifest.put(Constants.BUNDLE_REQUIREDEXECUTIONENVIRONMENT, "test");
BundleDescription b = state.getFactory().createBundleDescription(state, manifest, (String) manifest.get(Constants.BUNDLE_SYMBOLICNAME) + manifest.get(Constants.BUNDLE_VERSION), bundleID++);
state.addBundle(a);
state.resolve();
// $NON-NLS-1$
assertTrue("A is not resolved", a.isResolved());
state.addBundle(b);
state.resolve();
// $NON-NLS-1$
assertTrue("B is not resolved", b.isResolved());
BundleWiring aWiring = a.getWiring();
List aRequirements = a.getRequirements("osgi.ee");
List aRequiredWires = aWiring.getRequiredWires("osgi.ee");
assertEquals("Wrong number of osgi.ee requirements from system bundle", 1, aRequirements.size());
assertEquals("Wrong number of wires from system bundle", 1, aRequiredWires.size());
BundleWiring bWiring = b.getWiring();
List bRequirements = b.getRequirements("osgi.ee");
List bRequiredWires = bWiring.getRequiredWires("osgi.ee");
assertEquals("Wrong number of osgi.ee requirements from fragment", 1, bRequirements.size());
assertEquals("Wrong number of wires from fragment", 1, bRequiredWires.size());
}
use of org.eclipse.osgi.service.resolver.State in project rt.equinox.framework by eclipse.
the class StateResolverTest method testFragmentConstraints07.
public void testFragmentConstraints07() throws BundleException {
// same as testFragmentConstraints06 but with a cycle
int id = 0;
State state = buildEmptyState();
Hashtable manifest = new 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.0");
// $NON-NLS-1$
manifest.put(Constants.EXPORT_PACKAGE, "x");
// $NON-NLS-1$
manifest.put(Constants.IMPORT_PACKAGE, "a");
// $NON-NLS-1$
manifest.put(Constants.REQUIRE_BUNDLE, "b");
// $NON-NLS-1$
BundleDescription a = state.getFactory().createBundleDescription(state, manifest, (String) manifest.get(Constants.BUNDLE_SYMBOLICNAME) + "_" + manifest.get(Constants.BUNDLE_VERSION), id++);
manifest = new Hashtable();
// $NON-NLS-1$
manifest.put(Constants.BUNDLE_MANIFESTVERSION, "2");
// $NON-NLS-1$
manifest.put(Constants.BUNDLE_SYMBOLICNAME, "aFrag1");
// $NON-NLS-1$
manifest.put(Constants.BUNDLE_VERSION, "1.0.0");
// $NON-NLS-1$
manifest.put(Constants.FRAGMENT_HOST, "a");
// $NON-NLS-1$
manifest.put(Constants.IMPORT_PACKAGE, "b, c, d");
// $NON-NLS-1$
manifest.put(Constants.REQUIRE_BUNDLE, "c, d, e");
// $NON-NLS-1$
BundleDescription aFrag1 = state.getFactory().createBundleDescription(state, manifest, (String) manifest.get(Constants.BUNDLE_SYMBOLICNAME) + "_" + manifest.get(Constants.BUNDLE_VERSION), id++);
manifest = new Hashtable();
// $NON-NLS-1$
manifest.put(Constants.BUNDLE_MANIFESTVERSION, "2");
// $NON-NLS-1$
manifest.put(Constants.BUNDLE_SYMBOLICNAME, "aFrag2");
// $NON-NLS-1$
manifest.put(Constants.BUNDLE_VERSION, "1.0.0");
// $NON-NLS-1$
manifest.put(Constants.FRAGMENT_HOST, "a");
// $NON-NLS-1$
manifest.put(Constants.IMPORT_PACKAGE, "b, c, e");
// $NON-NLS-1$
manifest.put(Constants.REQUIRE_BUNDLE, "c, d, f");
// $NON-NLS-1$
BundleDescription aFrag2 = state.getFactory().createBundleDescription(state, manifest, (String) manifest.get(Constants.BUNDLE_SYMBOLICNAME) + "_" + manifest.get(Constants.BUNDLE_VERSION), id++);
manifest = new Hashtable();
// $NON-NLS-1$
manifest.put(Constants.BUNDLE_MANIFESTVERSION, "2");
// $NON-NLS-1$
manifest.put(Constants.BUNDLE_SYMBOLICNAME, "aFrag3");
// $NON-NLS-1$
manifest.put(Constants.BUNDLE_VERSION, "1.0.0");
// $NON-NLS-1$
manifest.put(Constants.FRAGMENT_HOST, "a");
// $NON-NLS-1$
manifest.put(Constants.IMPORT_PACKAGE, "b, c");
// $NON-NLS-1$
manifest.put(Constants.REQUIRE_BUNDLE, "c, d");
// $NON-NLS-1$
BundleDescription aFrag3 = state.getFactory().createBundleDescription(state, manifest, (String) manifest.get(Constants.BUNDLE_SYMBOLICNAME) + "_" + manifest.get(Constants.BUNDLE_VERSION), id++);
manifest = new Hashtable();
// $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.EXPORT_PACKAGE, "a, b, c");
// $NON-NLS-1$
BundleDescription b = state.getFactory().createBundleDescription(state, manifest, (String) manifest.get(Constants.BUNDLE_SYMBOLICNAME) + "_" + manifest.get(Constants.BUNDLE_VERSION), id++);
manifest = new Hashtable();
// $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.0");
// $NON-NLS-1$
manifest.put(Constants.EXPORT_PACKAGE, "c1, c2, c3");
// $NON-NLS-1$
BundleDescription c = state.getFactory().createBundleDescription(state, manifest, (String) manifest.get(Constants.BUNDLE_SYMBOLICNAME) + "_" + manifest.get(Constants.BUNDLE_VERSION), id++);
manifest = new Hashtable();
// $NON-NLS-1$
manifest.put(Constants.BUNDLE_MANIFESTVERSION, "2");
// $NON-NLS-1$
manifest.put(Constants.BUNDLE_SYMBOLICNAME, "d");
// $NON-NLS-1$
manifest.put(Constants.BUNDLE_VERSION, "1.0.0");
// $NON-NLS-1$
manifest.put(Constants.EXPORT_PACKAGE, "d1, d2, d3");
// $NON-NLS-1$
manifest.put(Constants.IMPORT_PACKAGE, "x");
// $NON-NLS-1$
manifest.put(Constants.REQUIRE_BUNDLE, "a");
// $NON-NLS-1$
BundleDescription d = state.getFactory().createBundleDescription(state, manifest, (String) manifest.get(Constants.BUNDLE_SYMBOLICNAME) + "_" + manifest.get(Constants.BUNDLE_VERSION), id++);
state.addBundle(a);
state.addBundle(aFrag1);
state.addBundle(aFrag2);
state.addBundle(aFrag3);
state.addBundle(b);
state.addBundle(c);
state.addBundle(d);
state.resolve();
// $NON-NLS-1$
assertTrue("0.1", a.isResolved());
// $NON-NLS-1$
assertFalse("0.2", aFrag1.isResolved());
// $NON-NLS-1$
assertFalse("0.3", aFrag2.isResolved());
// $NON-NLS-1$
assertTrue("0.4", aFrag3.isResolved());
// $NON-NLS-1$
assertTrue("0.5", b.isResolved());
// $NON-NLS-1$
assertTrue("0.6", c.isResolved());
// $NON-NLS-1$
assertTrue("0.7", d.isResolved());
ExportPackageDescription[] aResolvedImports = a.getResolvedImports();
ExportPackageDescription[] aSelectedExports = a.getSelectedExports();
ExportPackageDescription[] bSelectedExports = b.getSelectedExports();
ExportPackageDescription[] dResolvedImports = d.getResolvedImports();
// $NON-NLS-1$
assertEquals("1.0", 3, aResolvedImports.length);
// $NON-NLS-1$
assertEquals("1.1", 3, bSelectedExports.length);
for (int i = 0; i < aResolvedImports.length; i++) {
assertEquals(bSelectedExports[i], aResolvedImports[i]);
}
BundleDescription[] aResolvedRequires = a.getResolvedRequires();
// $NON-NLS-1$
assertEquals("1.0", 3, aResolvedRequires.length);
// $NON-NLS-1$
assertEquals("1.1", b, aResolvedRequires[0]);
// $NON-NLS-1$
assertEquals("1.2", c, aResolvedRequires[1]);
// $NON-NLS-1$
assertEquals("1.3", d, aResolvedRequires[2]);
// $NON-NLS-1$
assertEquals("2.0", 1, aSelectedExports.length);
// $NON-NLS-1$
assertEquals("2.1", 1, dResolvedImports.length);
// $NON-NLS-1$
assertEquals("2.2", aSelectedExports[0], dResolvedImports[0]);
}
use of org.eclipse.osgi.service.resolver.State in project rt.equinox.framework by eclipse.
the class StateResolverTest method testNativeCodeResolution03.
public void testNativeCodeResolution03() throws BundleException {
State state = buildEmptyState();
Dictionary[] props = new Dictionary[] { new Hashtable() };
// $NON-NLS-1$
props[0].put(Constants.FRAMEWORK_OS_NAME, "win32");
// Use different case for processor //$NON-NLS-1$
props[0].put(Constants.FRAMEWORK_PROCESSOR, "X86");
state.setPlatformProperties(props);
Hashtable manifest = new Hashtable();
long bundleID = 0;
// $NON-NLS-1$
manifest.put(Constants.BUNDLE_MANIFESTVERSION, "2");
// $NON-NLS-1$
manifest.put(Constants.BUNDLE_SYMBOLICNAME, "NativeBundle");
// $NON-NLS-1$
manifest.put(Constants.BUNDLE_VERSION, "1.0.0");
// $NON-NLS-1$
manifest.put(Constants.BUNDLE_NATIVECODE, "Bundle-NativeCode: nativefile1.txt;processor=x86;osname=Windows2000;osname=\"Windows 2003\";osname=Windows95;osname=Windows98;osname=WindowsNT;osname=WindowsXP;osname=\"Windows NT (unknown)\";osname=\"Windows Vista\"");
// $NON-NLS-1$
BundleDescription testNativeBundle = state.getFactory().createBundleDescription(state, manifest, "NativeBundle", bundleID++);
state.addBundle(testNativeBundle);
state.resolve();
// $NON-NLS-1$
assertTrue("1.0", testNativeBundle.isResolved());
}
use of org.eclipse.osgi.service.resolver.State in project rt.equinox.framework by eclipse.
the class StateResolverTest method testMultiStateAdd01.
public void testMultiStateAdd01() throws BundleException {
State state1 = buildEmptyState();
// test the selection algorithm of the resolver to pick the bundles which
// resolve the largest set of bundles
Hashtable manifest = new Hashtable();
// $NON-NLS-1$
manifest.put(Constants.BUNDLE_MANIFESTVERSION, "2");
// $NON-NLS-1$ //$NON-NLS-2$
manifest.put(Constants.BUNDLE_SYMBOLICNAME, "sdk; " + Constants.SINGLETON_DIRECTIVE + ":=true");
// $NON-NLS-1$
manifest.put(Constants.BUNDLE_VERSION, "1.0");
// $NON-NLS-1$
manifest.put(Constants.REQUIRE_BUNDLE, "platform; bundle-version=\"[1.0,2.0]\"");
// $NON-NLS-1$
BundleDescription sdk10 = state1.getFactory().createBundleDescription(state1, manifest, "sdk10", 0);
manifest = new Hashtable();
// $NON-NLS-1$
manifest.put(Constants.BUNDLE_MANIFESTVERSION, "2");
// $NON-NLS-1$ //$NON-NLS-2$
manifest.put(Constants.BUNDLE_SYMBOLICNAME, "platform; " + Constants.SINGLETON_DIRECTIVE + ":=true");
// $NON-NLS-1$
manifest.put(Constants.BUNDLE_VERSION, "1.0");
// $NON-NLS-1$
manifest.put(Constants.REQUIRE_BUNDLE, "rcp; bundle-version=\"[1.0,2.0]\"");
// $NON-NLS-1$
BundleDescription platform10 = state1.getFactory().createBundleDescription(state1, manifest, "platform10", 1);
manifest = new Hashtable();
// $NON-NLS-1$
manifest.put(Constants.BUNDLE_MANIFESTVERSION, "2");
// $NON-NLS-1$ //$NON-NLS-2$
manifest.put(Constants.BUNDLE_SYMBOLICNAME, "rcp; " + Constants.SINGLETON_DIRECTIVE + ":=true");
// $NON-NLS-1$
manifest.put(Constants.BUNDLE_VERSION, "1.0");
// $NON-NLS-1$
BundleDescription rcp10 = state1.getFactory().createBundleDescription(state1, manifest, "rcp10", 2);
manifest = new Hashtable();
// $NON-NLS-1$
manifest.put(Constants.BUNDLE_MANIFESTVERSION, "2");
// $NON-NLS-1$ //$NON-NLS-2$
manifest.put(Constants.BUNDLE_SYMBOLICNAME, "gef; " + Constants.SINGLETON_DIRECTIVE + ":=true");
// $NON-NLS-1$
manifest.put(Constants.BUNDLE_VERSION, "1.0");
// $NON-NLS-1$
manifest.put(Constants.REQUIRE_BUNDLE, "rcp; bundle-version=\"[1.0,1.0]\"");
// $NON-NLS-1$
BundleDescription gef10 = state1.getFactory().createBundleDescription(state1, manifest, "gef10", 3);
state1.addBundle(sdk10);
state1.addBundle(platform10);
state1.addBundle(rcp10);
state1.addBundle(gef10);
state1.resolve();
// $NON-NLS-1$
assertTrue("1.0", sdk10.isResolved());
// $NON-NLS-1$
assertTrue("1.1", platform10.isResolved());
// $NON-NLS-1$
assertTrue("1.2", rcp10.isResolved());
// $NON-NLS-1$
assertTrue("1.3", gef10.isResolved());
State state2 = buildEmptyState();
try {
state2.addBundle(rcp10);
// $NON-NLS-1$
fail("Expected IllegalStateException on adding to multiple states");
} catch (IllegalStateException e) {
// expected
}
}
use of org.eclipse.osgi.service.resolver.State in project rt.equinox.framework by eclipse.
the class StateResolverTest method testRemovalResolve.
public void testRemovalResolve() throws BundleException {
State state = buildInitialState();
StateDelta delta = state.resolve();
BundleDelta[] deltas = delta.getChanges();
BundleDescription b0 = state.getBundle(0);
// $NON-NLS-1$
assertNotNull("0.1", b0);
// $NON-NLS-1$
assertFullyResolved("0.2", b0);
Hashtable manifest = new Hashtable();
// $NON-NLS-1$
manifest.put(Constants.BUNDLE_SYMBOLICNAME, "org.eclipse.b1");
// $NON-NLS-1$
manifest.put(Constants.BUNDLE_VERSION, "1.0");
// $NON-NLS-1$
manifest.put(Constants.IMPORT_PACKAGE, "org.osgi.framework");
// $NON-NLS-1$
manifest.put(Constants.EXPORT_PACKAGE, "org.eclipse.p1; specification-version=1.0");
BundleDescription b1 = null;
try {
// $NON-NLS-1$
b1 = state.getFactory().createBundleDescription(manifest, "org.eclipse.b1", 1);
state.removeBundle(1);
state.addBundle(b1);
} catch (BundleException e) {
// $NON-NLS-1$
fail("Failed to create BundleDescription: " + e.getMessage());
}
manifest = new Hashtable();
// $NON-NLS-1$
manifest.put(Constants.BUNDLE_SYMBOLICNAME, "org.eclipse.b2");
// $NON-NLS-1$
manifest.put(Constants.BUNDLE_VERSION, "1.0");
// $NON-NLS-1$
manifest.put(Constants.IMPORT_PACKAGE, "org.osgi.framework,org.eclipse.p1");
// $NON-NLS-1$
manifest.put(Constants.EXPORT_PACKAGE, "org.eclipse.p2; specification-version=1.0");
BundleDescription b2 = null;
try {
// $NON-NLS-1$
b2 = state.getFactory().createBundleDescription(manifest, "org.eclipse.b2", 2);
state.removeBundle(2);
state.addBundle(b2);
} catch (BundleException e) {
// $NON-NLS-1$
fail("Failed to create BundleDescription: " + e.getMessage());
}
manifest = new Hashtable();
// $NON-NLS-1$
manifest.put(Constants.BUNDLE_SYMBOLICNAME, "org.eclipse.b3");
// $NON-NLS-1$
manifest.put(Constants.BUNDLE_VERSION, "1.0");
// $NON-NLS-1$
manifest.put(Constants.IMPORT_PACKAGE, "org.osgi.framework,org.eclipse.p2");
// $NON-NLS-1$
manifest.put(Constants.EXPORT_PACKAGE, "org.eclipse.p3; specification-version=1.0");
BundleDescription b3 = null;
try {
// $NON-NLS-1$
b3 = state.getFactory().createBundleDescription(manifest, "org.eclipse.b3", 3);
state.removeBundle(3);
state.addBundle(b3);
} catch (BundleException e) {
// $NON-NLS-1$
fail("Failed to create BundleDescription: " + e.getMessage());
}
delta = state.resolve(false);
deltas = delta.getChanges();
// $NON-NLS-1$
assertEquals("1.0", 4, deltas.length);
Map deltasMap = new HashMap();
for (int i = 0; i < deltas.length; i++) deltasMap.put(new Long(deltas[i].getBundle().getBundleId()), deltas[i]);
// $NON-NLS-1$
assertNotNull("1.1", deltasMap.get(new Long(1)));
// $NON-NLS-1$
assertNotNull("1.2", deltasMap.get(new Long(2)));
// $NON-NLS-1$
assertNotNull("1.3", deltasMap.get(new Long(3)));
// $NON-NLS-1$
assertEquals("2.1", (BundleDelta.RESOLVED | BundleDelta.ADDED), ((BundleDelta) deltasMap.get(new Long(1))).getType());
// $NON-NLS-1$
assertEquals("2.2", (BundleDelta.RESOLVED | BundleDelta.ADDED), ((BundleDelta) deltasMap.get(new Long(2))).getType());
// $NON-NLS-1$
assertEquals("2.3", (BundleDelta.RESOLVED | BundleDelta.ADDED), ((BundleDelta) deltasMap.get(new Long(3))).getType());
state.removeBundle(1);
delta = state.resolve(false);
deltas = delta.getChanges();
b2 = state.getBundle(2);
b3 = state.getBundle(3);
// $NON-NLS-1$
assertEquals("3.1", false, b2.isResolved());
// $NON-NLS-1$
assertEquals("3.2", false, b3.isResolved());
}
Aggregations