Search in sources :

Example 11 with ExportPackageDescription

use of org.eclipse.osgi.service.resolver.ExportPackageDescription 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]);
}
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 12 with ExportPackageDescription

use of org.eclipse.osgi.service.resolver.ExportPackageDescription 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 13 with ExportPackageDescription

use of org.eclipse.osgi.service.resolver.ExportPackageDescription 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 14 with ExportPackageDescription

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

the class TestDynamic_003 method testTest_003.

public void testTest_003() {
    State state = buildEmptyState();
    StateObjectFactory sof = StateObjectFactory.defaultFactory;
    bundle_1 = create_bundle_1(sof);
    bundle_2 = create_bundle_2(sof);
    bundle_3 = create_bundle_3(sof);
    // ***************************************************
    // stage a
    // expect to pass =true
    // ***************************************************
    addBundlesToState_a(state);
    // ***************************************************
    try {
        state.resolve();
    } catch (Throwable t) {
        fail("unexpected exception class=" + t.getClass().getName() + " message=" + t.getMessage());
        return;
    }
    checkBundlesResolved_a();
    checkWiring_a();
    // Dynamics
    ExportPackageDescription exp = state.linkDynamicImport(bundle_1, "r");
    assertNotNull("Package [r] is not wired when it should be ", exp);
    assertEquals("Package [r] is wired incorrectly ", exp.getExporter(), bundle_3);
}
Also used : State(org.eclipse.osgi.service.resolver.State) ExportPackageDescription(org.eclipse.osgi.service.resolver.ExportPackageDescription) StateObjectFactory(org.eclipse.osgi.service.resolver.StateObjectFactory)

Example 15 with ExportPackageDescription

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

the class TestDynamic_005 method testTest_005.

public void testTest_005() {
    State state = buildEmptyState();
    StateObjectFactory sof = StateObjectFactory.defaultFactory;
    bundle_1 = create_bundle_1(sof);
    bundle_2 = create_bundle_2(sof);
    bundle_3 = create_bundle_3(sof);
    // ***************************************************
    // stage a
    // expect to pass =true
    // ***************************************************
    addBundlesToState_a(state);
    // ***************************************************
    try {
        state.resolve();
    } catch (Throwable t) {
        fail("unexpected exception class=" + t.getClass().getName() + " message=" + t.getMessage());
        return;
    }
    checkBundlesResolved_a();
    checkWiring_a();
    // Dynamics
    ExportPackageDescription exp = state.linkDynamicImport(bundle_1, "q");
    assertNotNull("Package [q] is not wired when it should be ", exp);
    assertEquals("Package [q] is wired incorrectly ", exp.getExporter(), bundle_3);
}
Also used : State(org.eclipse.osgi.service.resolver.State) ExportPackageDescription(org.eclipse.osgi.service.resolver.ExportPackageDescription) StateObjectFactory(org.eclipse.osgi.service.resolver.StateObjectFactory)

Aggregations

ExportPackageDescription (org.eclipse.osgi.service.resolver.ExportPackageDescription)61 State (org.eclipse.osgi.service.resolver.State)22 BundleDescription (org.eclipse.osgi.service.resolver.BundleDescription)21 Hashtable (java.util.Hashtable)15 ArrayList (java.util.ArrayList)6 StateObjectFactory (org.eclipse.osgi.service.resolver.StateObjectFactory)6 VersionConstraint (org.eclipse.osgi.service.resolver.VersionConstraint)5 BundleSpecification (org.eclipse.osgi.service.resolver.BundleSpecification)4 ImportPackageSpecification (org.eclipse.osgi.service.resolver.ImportPackageSpecification)4 GenericDescription (org.eclipse.osgi.service.resolver.GenericDescription)3 ExportPackageDescriptionImpl (org.eclipse.osgi.internal.resolver.ExportPackageDescriptionImpl)2 BaseDescription (org.eclipse.osgi.service.resolver.BaseDescription)2 GenericSpecification (org.eclipse.osgi.service.resolver.GenericSpecification)2 StateWire (org.eclipse.osgi.service.resolver.StateWire)2 AccessRule (org.eclipse.tycho.classpath.ClasspathEntry.AccessRule)2 DefaultAccessRule (org.eclipse.tycho.core.osgitools.DefaultClasspathEntry.DefaultAccessRule)2 Dictionary (java.util.Dictionary)1 HashMap (java.util.HashMap)1 List (java.util.List)1 GenericDescriptionImpl (org.eclipse.osgi.internal.resolver.GenericDescriptionImpl)1