Search in sources :

Example 36 with State

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

the class StateResolverTest method testFragmentUses01.

public void testFragmentUses01() throws BundleException {
    long id = 0;
    State state = buildEmptyState();
    Hashtable manifest = new Hashtable();
    manifest.clear();
    // $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$
    manifest.put(Constants.REQUIRE_BUNDLE, "C2");
    // $NON-NLS-1$
    BundleDescription a1 = state.getFactory().createBundleDescription(state, manifest, (String) manifest.get(Constants.BUNDLE_SYMBOLICNAME) + manifest.get(Constants.BUNDLE_VERSION), id++);
    manifest.clear();
    // $NON-NLS-1$
    manifest.put(Constants.BUNDLE_MANIFESTVERSION, "2");
    // $NON-NLS-1$
    manifest.put(Constants.BUNDLE_SYMBOLICNAME, "A1.Frag");
    // $NON-NLS-1$
    manifest.put(Constants.BUNDLE_VERSION, "1.0.0");
    // $NON-NLS-1$
    manifest.put(Constants.FRAGMENT_HOST, "A1");
    // $NON-NLS-1$
    manifest.put(Constants.IMPORT_PACKAGE, "b; good=true");
    // $NON-NLS-1$
    BundleDescription a1frag = state.getFactory().createBundleDescription(state, manifest, (String) manifest.get(Constants.BUNDLE_SYMBOLICNAME) + manifest.get(Constants.BUNDLE_VERSION), id++);
    manifest.clear();
    // $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; good=true; uses:=c");
    // $NON-NLS-1$
    manifest.put(Constants.IMPORT_PACKAGE, "c; good=true");
    // $NON-NLS-1$
    BundleDescription b1 = state.getFactory().createBundleDescription(state, manifest, (String) manifest.get(Constants.BUNDLE_SYMBOLICNAME) + manifest.get(Constants.BUNDLE_VERSION), id++);
    manifest.clear();
    // $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; good=true");
    // $NON-NLS-1$
    BundleDescription c1 = state.getFactory().createBundleDescription(state, manifest, (String) manifest.get(Constants.BUNDLE_SYMBOLICNAME) + manifest.get(Constants.BUNDLE_VERSION), id++);
    manifest.clear();
    // $NON-NLS-1$
    manifest.put(Constants.BUNDLE_MANIFESTVERSION, "2");
    // $NON-NLS-1$
    manifest.put(Constants.BUNDLE_SYMBOLICNAME, "C2");
    // $NON-NLS-1$
    manifest.put(Constants.BUNDLE_VERSION, "1.0.0");
    // $NON-NLS-1$
    manifest.put(Constants.EXPORT_PACKAGE, "c; bad=true");
    // $NON-NLS-1$
    BundleDescription c2 = state.getFactory().createBundleDescription(state, manifest, (String) manifest.get(Constants.BUNDLE_SYMBOLICNAME) + manifest.get(Constants.BUNDLE_VERSION), id++);
    state.addBundle(a1);
    state.addBundle(a1frag);
    state.addBundle(b1);
    state.addBundle(c1);
    state.addBundle(c2);
    state.resolve();
    // $NON-NLS-1$
    assertTrue("0.1", a1.isResolved());
    // $NON-NLS-1$
    assertFalse("0.2", a1frag.isResolved());
    // $NON-NLS-1$
    assertTrue("0.3", b1.isResolved());
    // $NON-NLS-1$
    assertTrue("0.4", c1.isResolved());
    // $NON-NLS-1$
    assertTrue("0.5", c2.isResolved());
}
Also used : State(org.eclipse.osgi.service.resolver.State) Hashtable(java.util.Hashtable) BundleDescription(org.eclipse.osgi.service.resolver.BundleDescription)

Example 37 with State

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

the class StateResolverTest method testFragmentTransitiveUses.

public void testFragmentTransitiveUses() 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; uses:=d");
    // $NON-NLS-1$
    manifest.put(Constants.IMPORT_PACKAGE, "d");
    // $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, "A1.Frag");
    // $NON-NLS-1$
    manifest.put(Constants.BUNDLE_VERSION, "1.0.0");
    // $NON-NLS-1$
    manifest.put(Constants.FRAGMENT_HOST, "A1");
    // $NON-NLS-1$
    manifest.put(Constants.EXPORT_PACKAGE, "a.frag; uses:=a");
    // $NON-NLS-1$
    BundleDescription a1frag_100 = state.getFactory().createBundleDescription(state, manifest, "a1frag_100", 1);
    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; uses:=d, a.frag; uses:=a");
    // $NON-NLS-1$
    manifest.put(Constants.IMPORT_PACKAGE, "d");
    // $NON-NLS-1$
    BundleDescription a2_100 = state.getFactory().createBundleDescription(state, manifest, "a2_100", 2);
    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, a.frag");
    // $NON-NLS-1$
    BundleDescription b1_100 = state.getFactory().createBundleDescription(state, manifest, "b1_100", 3);
    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", 4);
    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.EXPORT_PACKAGE, "d; uses:=c");
    // $NON-NLS-1$
    manifest.put(Constants.IMPORT_PACKAGE, "a.frag, c");
    // $NON-NLS-1$
    BundleDescription d1_100 = state.getFactory().createBundleDescription(state, manifest, "d1_100", 5);
    state.addBundle(a1_100);
    state.addBundle(a1frag_100);
    state.addBundle(a2_100);
    state.addBundle(b1_100);
    state.addBundle(c1_100);
    state.addBundle(d1_100);
    state.resolve();
    // $NON-NLS-1$
    assertFalse("0.1", a1_100.isResolved());
    // $NON-NLS-1$
    assertTrue("0.2", a2_100.isResolved());
    // $NON-NLS-1$
    assertTrue("0.3", b1_100.isResolved());
    // $NON-NLS-1$
    assertTrue("0.4", c1_100.isResolved());
    // $NON-NLS-1$
    assertTrue("0.5", d1_100.isResolved());
    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();
    // $NON-NLS-1$
    assertTrue("2.1", a1_100.isResolved());
    // $NON-NLS-1$
    assertFalse("2.2", a2_100.isResolved());
    // $NON-NLS-1$
    assertTrue("2.3", b1_100.isResolved());
    // $NON-NLS-1$
    assertTrue("2.4", c1_100.isResolved());
    // $NON-NLS-1$
    assertTrue("2.5", d1_100.isResolved());
    b1ResolvedImports = b1_100.getResolvedImports();
    d1ResolvedImports = d1_100.getResolvedImports();
    isConsistent = isConsistent(b1ResolvedImports, d1ResolvedImports);
    // $NON-NLS-1$
    assertNull("3.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 38 with State

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

the class StateResolverTest method testSingletonsSelection5.

public void testSingletonsSelection5() throws BundleException {
    State state = buildEmptyState();
    // test the selection algorithm of the resolver to pick the bundles with the largest version
    long id = 0;
    Hashtable manifest = new Hashtable();
    // $NON-NLS-1$
    manifest.put(Constants.BUNDLE_MANIFESTVERSION, "2");
    // $NON-NLS-1$ //$NON-NLS-2$
    manifest.put(Constants.BUNDLE_SYMBOLICNAME, "base; " + Constants.SINGLETON_DIRECTIVE + ":=true");
    // $NON-NLS-1$
    manifest.put(Constants.BUNDLE_VERSION, "1.0");
    // $NON-NLS-1$
    BundleDescription base10 = state.getFactory().createBundleDescription(state, manifest, "base10", id++);
    manifest.clear();
    // $NON-NLS-1$
    manifest.put(Constants.BUNDLE_MANIFESTVERSION, "2");
    // $NON-NLS-1$ //$NON-NLS-2$
    manifest.put(Constants.BUNDLE_SYMBOLICNAME, "base; " + Constants.SINGLETON_DIRECTIVE + ":=true");
    // $NON-NLS-1$
    manifest.put(Constants.BUNDLE_VERSION, "1.1");
    // $NON-NLS-1$
    BundleDescription base11 = state.getFactory().createBundleDescription(state, manifest, "base11", id++);
    manifest.clear();
    // $NON-NLS-1$
    manifest.put(Constants.BUNDLE_MANIFESTVERSION, "2");
    // $NON-NLS-1$ //$NON-NLS-2$
    manifest.put(Constants.BUNDLE_SYMBOLICNAME, "requires; " + Constants.SINGLETON_DIRECTIVE + ":=true");
    // $NON-NLS-1$
    manifest.put(Constants.BUNDLE_VERSION, "1.0");
    // $NON-NLS-1$
    manifest.put(Constants.REQUIRE_BUNDLE, "base; bundle-version=\"[1.0,1.1)\"");
    // $NON-NLS-1$
    BundleDescription requires10 = state.getFactory().createBundleDescription(state, manifest, "requires10", id++);
    manifest.clear();
    // $NON-NLS-1$
    manifest.put(Constants.BUNDLE_MANIFESTVERSION, "2");
    // $NON-NLS-1$ //$NON-NLS-2$
    manifest.put(Constants.BUNDLE_SYMBOLICNAME, "requires; " + Constants.SINGLETON_DIRECTIVE + ":=true");
    // $NON-NLS-1$
    manifest.put(Constants.BUNDLE_VERSION, "1.1");
    // $NON-NLS-1$
    manifest.put(Constants.REQUIRE_BUNDLE, "base; bundle-version=\"[1.1,1.2)\"");
    // $NON-NLS-1$
    BundleDescription requires11 = state.getFactory().createBundleDescription(state, manifest, "requires11", id++);
    manifest.clear();
    // $NON-NLS-1$
    manifest.put(Constants.BUNDLE_MANIFESTVERSION, "2");
    // $NON-NLS-1$ //$NON-NLS-2$
    manifest.put(Constants.BUNDLE_SYMBOLICNAME, "frag; " + Constants.SINGLETON_DIRECTIVE + ":=true");
    // $NON-NLS-1$
    manifest.put(Constants.BUNDLE_VERSION, "1.0");
    // $NON-NLS-1$
    manifest.put(Constants.FRAGMENT_HOST, "requires; bundle-version=\"[1.0,1.1)\"");
    // $NON-NLS-1$
    BundleDescription frag10 = state.getFactory().createBundleDescription(state, manifest, "frag10", id++);
    manifest.clear();
    // $NON-NLS-1$
    manifest.put(Constants.BUNDLE_MANIFESTVERSION, "2");
    // $NON-NLS-1$ //$NON-NLS-2$
    manifest.put(Constants.BUNDLE_SYMBOLICNAME, "frag; " + Constants.SINGLETON_DIRECTIVE + ":=true");
    // $NON-NLS-1$
    manifest.put(Constants.BUNDLE_VERSION, "1.1");
    // $NON-NLS-1$
    manifest.put(Constants.FRAGMENT_HOST, "requires; bundle-version=\"[1.1,1.2)\"");
    // $NON-NLS-1$
    BundleDescription frag11 = state.getFactory().createBundleDescription(state, manifest, "frag11", id++);
    manifest.clear();
    // $NON-NLS-1$
    manifest.put(Constants.BUNDLE_MANIFESTVERSION, "2");
    // $NON-NLS-1$ //$NON-NLS-2$
    manifest.put(Constants.BUNDLE_SYMBOLICNAME, "fragb; " + Constants.SINGLETON_DIRECTIVE + ":=true");
    // $NON-NLS-1$
    manifest.put(Constants.BUNDLE_VERSION, "1.0");
    // $NON-NLS-1$
    manifest.put(Constants.FRAGMENT_HOST, "requires; bundle-version=\"[1.0,1.1)\"");
    // $NON-NLS-1$
    manifest.put(Constants.EXPORT_PACKAGE, "fragb; version=1.0");
    // $NON-NLS-1$
    BundleDescription fragb10 = state.getFactory().createBundleDescription(state, manifest, "frag10", id++);
    manifest.clear();
    // $NON-NLS-1$
    manifest.put(Constants.BUNDLE_MANIFESTVERSION, "2");
    // $NON-NLS-1$ //$NON-NLS-2$
    manifest.put(Constants.BUNDLE_SYMBOLICNAME, "fragb; " + Constants.SINGLETON_DIRECTIVE + ":=true");
    // $NON-NLS-1$
    manifest.put(Constants.BUNDLE_VERSION, "1.1");
    // $NON-NLS-1$
    manifest.put(Constants.FRAGMENT_HOST, "requires; bundle-version=\"[1.1,1.2)\"");
    // $NON-NLS-1$
    manifest.put(Constants.EXPORT_PACKAGE, "fragb; version=1.1");
    // $NON-NLS-1$
    BundleDescription fragb11 = state.getFactory().createBundleDescription(state, manifest, "frag11", id++);
    manifest.clear();
    // $NON-NLS-1$
    manifest.put(Constants.BUNDLE_MANIFESTVERSION, "2");
    // $NON-NLS-1$
    manifest.put(Constants.BUNDLE_SYMBOLICNAME, "import");
    // $NON-NLS-1$
    manifest.put(Constants.BUNDLE_VERSION, "1.0");
    // $NON-NLS-1$
    manifest.put(Constants.IMPORT_PACKAGE, "fragb; version=\"[1.0,1.0]\"");
    // $NON-NLS-1$
    BundleDescription import10 = state.getFactory().createBundleDescription(state, manifest, "import10", id++);
    manifest.clear();
    // $NON-NLS-1$
    manifest.put(Constants.BUNDLE_MANIFESTVERSION, "2");
    // $NON-NLS-1$
    manifest.put(Constants.BUNDLE_SYMBOLICNAME, "import");
    // $NON-NLS-1$
    manifest.put(Constants.BUNDLE_VERSION, "1.1");
    // $NON-NLS-1$
    manifest.put(Constants.IMPORT_PACKAGE, "fragb; version=\"[1.1,1.1]\"");
    // $NON-NLS-1$
    BundleDescription import11 = state.getFactory().createBundleDescription(state, manifest, "import11", id++);
    state.addBundle(base10);
    state.addBundle(base11);
    state.addBundle(requires10);
    state.addBundle(requires11);
    state.addBundle(frag10);
    state.addBundle(frag11);
    state.addBundle(fragb10);
    state.addBundle(fragb11);
    state.addBundle(import10);
    state.addBundle(import11);
    state.resolve();
    // $NON-NLS-1$
    assertTrue("1.0", base11.isResolved());
    // $NON-NLS-1$
    assertTrue("1.1", requires11.isResolved());
    // $NON-NLS-1$
    assertTrue("1.2", frag11.isResolved());
    // $NON-NLS-1$
    assertTrue("1.3", fragb11.isResolved());
    // $NON-NLS-1$
    assertTrue("1.4", import11.isResolved());
    // $NON-NLS-1$
    assertFalse("1.5", base10.isResolved());
    // $NON-NLS-1$
    assertFalse("1.6", requires10.isResolved());
    // $NON-NLS-1$
    assertFalse("1.7", frag10.isResolved());
    // $NON-NLS-1$
    assertFalse("1.8", fragb10.isResolved());
    // $NON-NLS-1$
    assertFalse("1.9", import10.isResolved());
}
Also used : State(org.eclipse.osgi.service.resolver.State) Hashtable(java.util.Hashtable) BundleDescription(org.eclipse.osgi.service.resolver.BundleDescription)

Example 39 with State

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

the class StateResolverTest method testBug320124.

public void testBug320124() throws BundleException {
    State state = buildEmptyState();
    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, "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.FRAGMENT_HOST, "a");
    // $NON-NLS-1$
    manifest.put(Constants.REQUIRE_BUNDLE, "d");
    BundleDescription b = 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, "c");
    // $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.REQUIRE_BUNDLE, "e");
    BundleDescription c = 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, "d");
    // $NON-NLS-1$
    manifest.put(Constants.BUNDLE_VERSION, "1.0.0");
    // $NON-NLS-1$
    manifest.put(Constants.EXPORT_PACKAGE, "d");
    BundleDescription d = 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, "e");
    // $NON-NLS-1$
    manifest.put(Constants.BUNDLE_VERSION, "1.0.0");
    // $NON-NLS-1$
    manifest.put(Constants.EXPORT_PACKAGE, "e");
    BundleDescription e = state.getFactory().createBundleDescription(state, manifest, (String) manifest.get(Constants.BUNDLE_SYMBOLICNAME) + manifest.get(Constants.BUNDLE_VERSION), bundleID++);
    state.addBundle(a);
    state.addBundle(b);
    state.addBundle(c);
    state.addBundle(d);
    state.addBundle(e);
    state.resolve();
    // $NON-NLS-1$
    assertTrue("A is not resolved", a.isResolved());
    // $NON-NLS-1$
    assertTrue("B is not resolved", b.isResolved());
    // $NON-NLS-1$
    assertTrue("C is not resolved", c.isResolved());
    // $NON-NLS-1$
    assertTrue("D is not resolved", d.isResolved());
    ExportPackageDescription[] visible = state.getStateHelper().getVisiblePackages(a, StateHelper.VISIBLE_INCLUDE_EE_PACKAGES | StateHelper.VISIBLE_INCLUDE_ALL_HOST_WIRES);
    assertEquals("Wrong number of visible", 2, visible.length);
}
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 40 with State

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

the class StateResolverTest method testPlatformProperties01.

public void testPlatformProperties01() 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, "org.eclipse.osgi");
    // $NON-NLS-1$
    manifest.put(Constants.BUNDLE_VERSION, "1.0");
    // $NON-NLS-1$
    BundleDescription systemBundle = state.getFactory().createBundleDescription(state, manifest, "org.eclipse.osgi", bundleID++);
    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");
    // $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++);
    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.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++);
    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.IMPORT_PACKAGE, "pkg.d, pkg.system.b");
    // $NON-NLS-1$
    manifest.put(Constants.REQUIRE_CAPABILITY, "osgi.ee; filter:=\"(&(osgi.ee=JavaSE)(version>=1.4))\"");
    // $NON-NLS-1$
    BundleDescription c = state.getFactory().createBundleDescription(state, manifest, "C", bundleID++);
    manifest.clear();
    // $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");
    // $NON-NLS-1$
    manifest.put(Constants.EXPORT_PACKAGE, "pkg.d");
    // $NON-NLS-1$
    manifest.put(Constants.IMPORT_PACKAGE, "pkg.system.b");
    // $NON-NLS-1$
    manifest.put(Constants.REQUIRE_CAPABILITY, "osgi.ee; filter:=\"(&(osgi.ee=JavaSE)(version>=1.2))\"");
    // $NON-NLS-1$
    BundleDescription d = state.getFactory().createBundleDescription(state, manifest, "D", bundleID++);
    manifest.clear();
    // $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");
    props[0].put("org.osgi.framework.system.capabilities", "osgi.ee; osgi.ee=\"JavaSE\"; version:Version=\"1.2\"");
    // $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");
    props[1].put("org.osgi.framework.system.capabilities", "osgi.ee; osgi.ee=\"JavaSE\"; version:List<Version>=\"1.2, 1.3, 1.4\"");
    state.setPlatformProperties(props);
    state.addBundle(systemBundle);
    state.addBundle(a);
    state.addBundle(b);
    state.addBundle(c);
    state.addBundle(d);
    state.addBundle(systemB);
    state.resolve();
    Collection ids = systemBundle.getCapabilities(IdentityNamespace.IDENTITY_NAMESPACE);
    assertNotNull("Null osgi.identity", ids);
    assertEquals("Wrong number of identities", 1, ids.size());
    // $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", c.isResolved());
    // $NON-NLS-1$
    assertTrue("1.4", d.isResolved());
    // $NON-NLS-1$
    assertTrue("1.5", systemB.isResolved());
    // $NON-NLS-1$
    assertTrue("2.0", a.getResolvedImports()[1].getExporter() == systemBundle);
    // $NON-NLS-1$
    assertTrue("2.1", b.getResolvedImports()[0].getExporter() == systemB);
    // $NON-NLS-1$
    assertTrue("2.2", c.getResolvedImports()[1].getExporter() == systemBundle);
    // $NON-NLS-1$
    assertTrue("2.3", d.getResolvedImports()[0].getExporter() == systemB);
    // now test the uses clause for pkg.b such that bundle 'A' will be forced to used
    // pkg.system.b 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);
    // now test the uses clause for pkg.d such that bundle 'C' will be forced to used
    // pkg.system.b from bundle 'system.b'
    // $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");
    // $NON-NLS-1$
    manifest.put(Constants.EXPORT_PACKAGE, "pkg.d; 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 d_updated = state.getFactory().createBundleDescription(state, manifest, "D", d.getBundleId());
    state.updateBundle(d_updated);
    state.resolve(new BundleDescription[] { b_updated, d_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);
    // $NON-NLS-1$
    assertTrue("2.2", c.getResolvedImports()[1].getExporter() == systemB);
}
Also used : Dictionary(java.util.Dictionary) State(org.eclipse.osgi.service.resolver.State) Hashtable(java.util.Hashtable) BundleDescription(org.eclipse.osgi.service.resolver.BundleDescription) Collection(java.util.Collection)

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