Search in sources :

Example 11 with State

use of org.eclipse.osgi.service.resolver.State in project rt.equinox.framework by eclipse.

the class StateResolverTest method testSingletonsSameVersion.

public void testSingletonsSameVersion() 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
    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.0");
    // $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.0");
    // $NON-NLS-1$
    BundleDescription testFrag101 = state.getFactory().createBundleDescription(state, manifest, "test.frag101", 3);
    state.addBundle(testHost100);
    state.addBundle(testFrag100);
    state.resolve();
    state.addBundle(testHost101);
    state.addBundle(testFrag101);
    state.resolve();
    // $NON-NLS-1$
    assertTrue("1.0", testHost100.isResolved());
    // $NON-NLS-1$
    assertFalse("1.1", testHost101.isResolved());
    // $NON-NLS-1$
    assertTrue("1.2", testFrag100.isResolved());
    // $NON-NLS-1$
    assertFalse("1.3", testFrag101.isResolved());
}
Also used : State(org.eclipse.osgi.service.resolver.State) Hashtable(java.util.Hashtable) BundleDescription(org.eclipse.osgi.service.resolver.BundleDescription)

Example 12 with State

use of org.eclipse.osgi.service.resolver.State in project rt.equinox.framework by eclipse.

the class StateResolverTest method testMultiStateAdd02.

public void testMultiStateAdd02() 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());
    // remove the rcp10 bundle.  The bundle will be removal pending
    // this should still throw an exception until the removal is no longer pending
    state1.removeBundle(rcp10);
    State state2 = buildEmptyState();
    try {
        state2.addBundle(rcp10);
        // $NON-NLS-1$
        fail("Expected IllegalStateException on adding to multiple states");
    } catch (IllegalStateException e) {
    // expected
    }
}
Also used : State(org.eclipse.osgi.service.resolver.State) Hashtable(java.util.Hashtable) BundleDescription(org.eclipse.osgi.service.resolver.BundleDescription)

Example 13 with State

use of org.eclipse.osgi.service.resolver.State in project rt.equinox.framework by eclipse.

the class StateResolverTest method testNativeCodeResolution06.

public void testNativeCodeResolution06() throws BundleException {
    State state = buildEmptyState();
    Dictionary[] props = new Dictionary[] { new Hashtable(), new Hashtable(), new Hashtable() };
    // empty props[0]
    // $NON-NLS-1$ //$NON-NLS-2$
    props[1].put("osgi.ws", "win32");
    // $NON-NLS-1$ //$NON-NLS-2$
    props[1].put("osgi.os", "win32");
    // $NON-NLS-1$ //$NON-NLS-2$
    props[1].put("osgi.arch", "x86_64");
    // $NON-NLS-1$ //$NON-NLS-2$
    props[2].put("osgi.ws", "win32");
    // $NON-NLS-1$ //$NON-NLS-2$
    props[2].put("osgi.os", "win32");
    // $NON-NLS-1$ //$NON-NLS-2$
    props[2].put("osgi.arch", "x86");
    state.setPlatformProperties(props);
    Hashtable manifest = new Hashtable();
    long bundleID = 0;
    manifest.clear();
    // $NON-NLS-1$
    manifest.put(Constants.BUNDLE_MANIFESTVERSION, "2");
    // $NON-NLS-1$
    manifest.put(Constants.BUNDLE_SYMBOLICNAME, "NativeBundle1");
    // $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=win32");
    // $NON-NLS-1$
    BundleDescription testNativeBundle1 = state.getFactory().createBundleDescription(state, manifest, "NativeBundle", bundleID++);
    state.addBundle(testNativeBundle1);
    state.resolve();
    // $NON-NLS-1$
    assertTrue("1.0", testNativeBundle1.isResolved());
}
Also used : Dictionary(java.util.Dictionary) State(org.eclipse.osgi.service.resolver.State) Hashtable(java.util.Hashtable) BundleDescription(org.eclipse.osgi.service.resolver.BundleDescription)

Example 14 with State

use of org.eclipse.osgi.service.resolver.State in project rt.equinox.framework by eclipse.

the class StateResolverTest method testRemovalPending.

public void testRemovalPending() throws BundleException {
    State state = buildEmptyState();
    Hashtable wManifest = new Hashtable();
    // $NON-NLS-1$
    wManifest.put(Constants.BUNDLE_MANIFESTVERSION, "2");
    // $NON-NLS-1$
    wManifest.put(Constants.BUNDLE_SYMBOLICNAME, "W");
    // $NON-NLS-1$
    wManifest.put(Constants.BUNDLE_VERSION, "1.0.0");
    // $NON-NLS-1$
    wManifest.put(Constants.EXPORT_PACKAGE, "a; b; version=1.0");
    // $NON-NLS-1$
    wManifest.put(Constants.IMPORT_PACKAGE, "a, b");
    // $NON-NLS-1$
    BundleDescription w1_100 = state.getFactory().createBundleDescription(state, wManifest, "w1_100", 0);
    Hashtable manifest = new Hashtable();
    // $NON-NLS-1$
    manifest.put(Constants.BUNDLE_MANIFESTVERSION, "2");
    // $NON-NLS-1$
    manifest.put(Constants.BUNDLE_SYMBOLICNAME, "X");
    // $NON-NLS-1$
    manifest.put(Constants.BUNDLE_VERSION, "1.0.0");
    // $NON-NLS-1$
    manifest.put(Constants.IMPORT_PACKAGE, "a");
    // $NON-NLS-1$
    BundleDescription x1_100 = state.getFactory().createBundleDescription(state, manifest, "x1_100", 1);
    manifest = new Hashtable();
    // $NON-NLS-1$
    manifest.put(Constants.BUNDLE_MANIFESTVERSION, "2");
    // $NON-NLS-1$
    manifest.put(Constants.BUNDLE_SYMBOLICNAME, "Y");
    // $NON-NLS-1$
    manifest.put(Constants.BUNDLE_VERSION, "1.0.0");
    // $NON-NLS-1$
    manifest.put(Constants.IMPORT_PACKAGE, "a");
    // $NON-NLS-1$
    BundleDescription y1_100 = state.getFactory().createBundleDescription(state, manifest, "y1_100", 2);
    state.addBundle(w1_100);
    state.addBundle(x1_100);
    state.addBundle(y1_100);
    state.resolve();
    // $NON-NLS-1$
    assertTrue("0.1", w1_100.isResolved());
    // $NON-NLS-1$
    assertTrue("0.2", x1_100.isResolved());
    // $NON-NLS-1$
    assertTrue("0.3", y1_100.isResolved());
    // $NON-NLS-1$
    BundleDescription w1_100_prime = state.getFactory().createBundleDescription(state, wManifest, "w1_100", 0);
    state.updateBundle(w1_100_prime);
    state.resolve(new BundleDescription[0]);
    // $NON-NLS-1$
    assertTrue("1.1", w1_100_prime.isResolved());
    // $NON-NLS-1$
    assertTrue("1.2", x1_100.isResolved());
    // $NON-NLS-1$
    assertTrue("1.3", y1_100.isResolved());
    ExportPackageDescription[] exports_w1_100 = w1_100.getSelectedExports();
    ExportPackageDescription[] imports_w1_100_prime = w1_100_prime.getResolvedImports();
    ExportPackageDescription[] isConsistent = isConsistent(exports_w1_100, imports_w1_100_prime);
    // $NON-NLS-1$
    assertNull("2.1 Packages are not consistent: " + isConsistent, isConsistent);
    state.resolve(new BundleDescription[] { w1_100 });
    // $NON-NLS-1$
    assertTrue("3.1", w1_100_prime.isResolved());
    // $NON-NLS-1$
    assertTrue("3.2", x1_100.isResolved());
    // $NON-NLS-1$
    assertTrue("3.3", y1_100.isResolved());
    ExportPackageDescription[] exports_w1_100_prime = w1_100_prime.getSelectedExports();
    imports_w1_100_prime = w1_100_prime.getResolvedImports();
    isConsistent = isConsistent(exports_w1_100_prime, imports_w1_100_prime);
    // $NON-NLS-1$
    assertNull("4.1 Packages are not consistent: " + isConsistent, isConsistent);
}
Also used : State(org.eclipse.osgi.service.resolver.State) Hashtable(java.util.Hashtable) BundleDescription(org.eclipse.osgi.service.resolver.BundleDescription) ExportPackageDescription(org.eclipse.osgi.service.resolver.ExportPackageDescription)

Example 15 with State

use of org.eclipse.osgi.service.resolver.State in project rt.equinox.framework by eclipse.

the class StateResolverTest method testTransitiveUses.

public void testTransitiveUses() 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, "A1");
    // $NON-NLS-1$
    manifest.put(Constants.BUNDLE_VERSION, "1.0.0");
    // $NON-NLS-1$
    manifest.put(Constants.EXPORT_PACKAGE, "a");
    // $NON-NLS-1$
    BundleDescription a1_100 = state.getFactory().createBundleDescription(state, manifest, "a1_100", 0);
    manifest = new Hashtable();
    // $NON-NLS-1$
    manifest.put(Constants.BUNDLE_MANIFESTVERSION, "2");
    // $NON-NLS-1$
    manifest.put(Constants.BUNDLE_SYMBOLICNAME, "A2");
    // $NON-NLS-1$
    manifest.put(Constants.BUNDLE_VERSION, "1.0.0");
    // $NON-NLS-1$
    manifest.put(Constants.EXPORT_PACKAGE, "a");
    // $NON-NLS-1$
    BundleDescription a2_100 = state.getFactory().createBundleDescription(state, manifest, "a2_100", 1);
    manifest = new Hashtable();
    // $NON-NLS-1$
    manifest.put(Constants.BUNDLE_MANIFESTVERSION, "2");
    // $NON-NLS-1$
    manifest.put(Constants.BUNDLE_SYMBOLICNAME, "B1");
    // $NON-NLS-1$
    manifest.put(Constants.BUNDLE_VERSION, "1.0.0");
    // $NON-NLS-1$
    manifest.put(Constants.EXPORT_PACKAGE, "b; uses:=a");
    // $NON-NLS-1$
    manifest.put(Constants.IMPORT_PACKAGE, "a;bundle-symbolic-name=A2");
    // $NON-NLS-1$
    BundleDescription b1_100 = state.getFactory().createBundleDescription(state, manifest, "b1_100", 2);
    manifest = new Hashtable();
    // $NON-NLS-1$
    manifest.put(Constants.BUNDLE_MANIFESTVERSION, "2");
    // $NON-NLS-1$
    manifest.put(Constants.BUNDLE_SYMBOLICNAME, "C1");
    // $NON-NLS-1$
    manifest.put(Constants.BUNDLE_VERSION, "1.0.0");
    // $NON-NLS-1$
    manifest.put(Constants.EXPORT_PACKAGE, "c; uses:=b");
    // $NON-NLS-1$
    manifest.put(Constants.IMPORT_PACKAGE, "b");
    // $NON-NLS-1$
    BundleDescription c1_100 = state.getFactory().createBundleDescription(state, manifest, "c1_100", 3);
    manifest = new Hashtable();
    // $NON-NLS-1$
    manifest.put(Constants.BUNDLE_MANIFESTVERSION, "2");
    // $NON-NLS-1$
    manifest.put(Constants.BUNDLE_SYMBOLICNAME, "D1");
    // $NON-NLS-1$
    manifest.put(Constants.BUNDLE_VERSION, "1.0.0");
    // $NON-NLS-1$
    manifest.put(Constants.IMPORT_PACKAGE, "a, c");
    // $NON-NLS-1$
    BundleDescription d1_100 = state.getFactory().createBundleDescription(state, manifest, "d1_100", 4);
    state.addBundle(a1_100);
    state.addBundle(a2_100);
    state.addBundle(b1_100);
    state.addBundle(c1_100);
    state.addBundle(d1_100);
    state.resolve();
    ExportPackageDescription[] b1ResolvedImports = b1_100.getResolvedImports();
    ExportPackageDescription[] d1ResolvedImports = d1_100.getResolvedImports();
    ExportPackageDescription[] isConsistent = isConsistent(b1ResolvedImports, d1ResolvedImports);
    // $NON-NLS-1$
    assertNull("1.1 Packages are not consistent: " + isConsistent, isConsistent);
    manifest = new Hashtable();
    // $NON-NLS-1$
    manifest.put(Constants.BUNDLE_MANIFESTVERSION, "2");
    // $NON-NLS-1$
    manifest.put(Constants.BUNDLE_SYMBOLICNAME, "B1");
    // $NON-NLS-1$
    manifest.put(Constants.BUNDLE_VERSION, "1.0.0");
    // $NON-NLS-1$
    manifest.put(Constants.EXPORT_PACKAGE, "b; uses:=a");
    // $NON-NLS-1$
    manifest.put(Constants.IMPORT_PACKAGE, "a;bundle-symbolic-name=A1");
    // $NON-NLS-1$
    b1_100 = state.getFactory().createBundleDescription(state, manifest, "b1_100", 2);
    state.updateBundle(b1_100);
    state.resolve();
    b1ResolvedImports = b1_100.getResolvedImports();
    d1ResolvedImports = d1_100.getResolvedImports();
    isConsistent = isConsistent(b1ResolvedImports, d1ResolvedImports);
    // $NON-NLS-1$
    assertNull("1.2 Packages are not consistent: " + isConsistent, isConsistent);
}
Also used : State(org.eclipse.osgi.service.resolver.State) Hashtable(java.util.Hashtable) BundleDescription(org.eclipse.osgi.service.resolver.BundleDescription) ExportPackageDescription(org.eclipse.osgi.service.resolver.ExportPackageDescription)

Aggregations

State (org.eclipse.osgi.service.resolver.State)119 BundleDescription (org.eclipse.osgi.service.resolver.BundleDescription)87 Hashtable (java.util.Hashtable)70 Dictionary (java.util.Dictionary)28 StateObjectFactory (org.eclipse.osgi.service.resolver.StateObjectFactory)27 ExportPackageDescription (org.eclipse.osgi.service.resolver.ExportPackageDescription)22 StateDelta (org.eclipse.osgi.service.resolver.StateDelta)11 BundleDelta (org.eclipse.osgi.service.resolver.BundleDelta)10 ArrayList (java.util.ArrayList)7 List (java.util.List)7 File (java.io.File)6 HashMap (java.util.HashMap)6 Map (java.util.Map)5 CaseInsensitiveDictionaryMap (org.eclipse.osgi.framework.util.CaseInsensitiveDictionaryMap)5 Version (org.osgi.framework.Version)5 BundleWiring (org.osgi.framework.wiring.BundleWiring)4 PerformanceTestRunner (org.eclipse.core.tests.harness.PerformanceTestRunner)3 BundleException (org.osgi.framework.BundleException)3 BundleContext (org.osgi.framework.BundleContext)2 Collection (java.util.Collection)1