Search in sources :

Example 51 with ExportPackageDescription

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

the class TestDynamic_002 method checkWiringState_1.

// end of method
public void checkWiringState_1() {
    ExportPackageDescription[] exports = bundle_1.getResolvedImports();
    assertNotNull("export array is unexpectedly null", exports);
    assertTrue("export array is unexpectedly empty", exports.length > 0);
    for (int i = 0; i < exports.length; i++) {
        ExportPackageDescription exp = exports[i];
        String exportPackageName = exp.getName();
        assertNotNull("package name is null", exportPackageName);
        if (exportPackageName.equals("p")) {
            assertNotNull("Package [p] is not wired when it should be ", exp.getExporter());
            assertEquals("Package [p] is wired incorrectly ", exp.getExporter(), bundle_2);
        } else if (exportPackageName.equals("q")) {
            assertNotNull("Package [q] is not wired when it should be ", exp.getExporter());
            assertEquals("Package [q] is wired incorrectly ", exp.getExporter(), bundle_2);
        }
    }
// end for
}
Also used : ExportPackageDescription(org.eclipse.osgi.service.resolver.ExportPackageDescription)

Example 52 with ExportPackageDescription

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

the class StateResolverTest method testBug324618.

public void testBug324618() throws BundleException {
    State state = buildEmptyState();
    long bundleID = 0;
    Dictionary manifest;
    manifest = loadManifest("p1.MF");
    BundleDescription p1 = state.getFactory().createBundleDescription(state, manifest, (String) manifest.get(Constants.BUNDLE_SYMBOLICNAME), bundleID++);
    manifest = loadManifest("p2.MF");
    BundleDescription p2 = state.getFactory().createBundleDescription(state, manifest, (String) manifest.get(Constants.BUNDLE_SYMBOLICNAME), bundleID++);
    manifest = loadManifest("c1.MF");
    BundleDescription c1 = state.getFactory().createBundleDescription(state, manifest, (String) manifest.get(Constants.BUNDLE_SYMBOLICNAME), bundleID++);
    state.addBundle(p1);
    state.addBundle(p2);
    state.addBundle(c1);
    state.resolve();
    ExportPackageDescription x = state.linkDynamicImport(c1, "x");
    assertNotNull("x dynamic import is null", x);
    ExportPackageDescription xSub = state.linkDynamicImport(c1, "x.sub");
    assertNotNull("x.sub dynamic import is null", xSub);
    assertEquals("The exporter is not the same for x and x.sub", x.getExporter(), xSub.getExporter());
    ExportPackageDescription xExtra = state.linkDynamicImport(c1, "x.extra");
    assertNotNull("x.extra dynamic import is null", xExtra);
}
Also used : Dictionary(java.util.Dictionary) State(org.eclipse.osgi.service.resolver.State) BundleDescription(org.eclipse.osgi.service.resolver.BundleDescription) ExportPackageDescription(org.eclipse.osgi.service.resolver.ExportPackageDescription)

Example 53 with ExportPackageDescription

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

the class StateResolverTest method testFragmentConstraints02.

public void testFragmentConstraints02() throws BundleException {
    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.IMPORT_PACKAGE, "a");
    // $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$
    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$
    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$
    BundleDescription aFrag3 = state.getFactory().createBundleDescription(state, manifest, (String) manifest.get(Constants.BUNDLE_SYMBOLICNAME) + "_" + manifest.get(Constants.BUNDLE_VERSION), id++);
    // Bug 353103 need to create a bundle that has the same unresolved imports as other bundles
    manifest = new Hashtable();
    // $NON-NLS-1$
    manifest.put(Constants.BUNDLE_MANIFESTVERSION, "2");
    // $NON-NLS-1$
    manifest.put(Constants.BUNDLE_SYMBOLICNAME, "aFrag4");
    // $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, e");
    // $NON-NLS-1$
    BundleDescription aFrag4 = 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++);
    state.addBundle(a);
    state.addBundle(aFrag1);
    state.addBundle(aFrag2);
    state.addBundle(aFrag3);
    state.addBundle(aFrag4);
    state.addBundle(b);
    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$
    assertFalse("0.5", aFrag4.isResolved());
    // $NON-NLS-1$
    assertTrue("0.6", b.isResolved());
    ExportPackageDescription[] aResolvedImports = a.getResolvedImports();
    ExportPackageDescription[] bSelectedExports = b.getSelectedExports();
    // $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]);
    }
}
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 54 with ExportPackageDescription

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

the class StateResolverTest method testFragmentConstraints03.

public void testFragmentConstraints03() throws BundleException {
    // same as testFragmentConstraints02 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$
    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$
    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$
    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$
    BundleDescription aFrag3 = state.getFactory().createBundleDescription(state, manifest, (String) manifest.get(Constants.BUNDLE_SYMBOLICNAME) + "_" + manifest.get(Constants.BUNDLE_VERSION), id++);
    // Bug 353103 need to create a bundle that has the same unresolved imports as other bundles
    manifest = new Hashtable();
    // $NON-NLS-1$
    manifest.put(Constants.BUNDLE_MANIFESTVERSION, "2");
    // $NON-NLS-1$
    manifest.put(Constants.BUNDLE_SYMBOLICNAME, "aFrag4");
    // $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, e");
    // $NON-NLS-1$
    BundleDescription aFrag4 = 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$
    manifest.put(Constants.IMPORT_PACKAGE, "x");
    // $NON-NLS-1$
    BundleDescription b = 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(aFrag4);
    state.addBundle(b);
    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$
    assertFalse("0.5", aFrag4.isResolved());
    // $NON-NLS-1$
    assertTrue("0.6", b.isResolved());
    ExportPackageDescription[] aResolvedImports = a.getResolvedImports();
    ExportPackageDescription[] aSelectedExports = a.getSelectedExports();
    ExportPackageDescription[] bResolvedImports = b.getResolvedImports();
    ExportPackageDescription[] bSelectedExports = b.getSelectedExports();
    // $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++) // $NON-NLS-1$
    assertEquals("1.2", bSelectedExports[i], aResolvedImports[i]);
    // $NON-NLS-1$
    assertEquals("2.0", 1, aSelectedExports.length);
    // $NON-NLS-1$
    assertEquals("2.1", 1, bResolvedImports.length);
    // $NON-NLS-1$
    assertEquals("2.2", aSelectedExports[0], bResolvedImports[0]);
}
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 55 with ExportPackageDescription

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

the class StateResolverTest method testSingletonsSelection7.

public void testSingletonsSelection7() throws BundleException {
    State state = buildEmptyState();
    long id = 0;
    // test the selection algorithm of the resolver to pick the bundles with the largest version
    Hashtable manifest = new Hashtable();
    // $NON-NLS-1$
    manifest.put(Constants.BUNDLE_MANIFESTVERSION, "2");
    // $NON-NLS-1$ //$NON-NLS-2$
    manifest.put(Constants.BUNDLE_SYMBOLICNAME, "singleton; " + Constants.SINGLETON_DIRECTIVE + ":=true");
    // $NON-NLS-1$
    manifest.put(Constants.BUNDLE_VERSION, "1.0");
    // $NON-NLS-1$
    manifest.put(Constants.EXPORT_PACKAGE, "singleton");
    // $NON-NLS-1$
    BundleDescription singleton1 = state.getFactory().createBundleDescription(state, manifest, "singleton1", id++);
    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, "singleton");
    // $NON-NLS-1$
    manifest.put(Constants.EXPORT_PACKAGE, "a;version=1.0.0");
    // $NON-NLS-1$
    BundleDescription a1 = state.getFactory().createBundleDescription(state, manifest, "a1", id++);
    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");
    // $NON-NLS-1$
    BundleDescription b = state.getFactory().createBundleDescription(state, manifest, "b", id++);
    state.addBundle(singleton1);
    state.addBundle(a1);
    state.addBundle(b);
    state.resolve();
    // $NON-NLS-1$
    assertTrue("1.0", singleton1.isResolved());
    // $NON-NLS-1$
    assertTrue("1.1", a1.isResolved());
    // $NON-NLS-1$
    assertTrue("1.2", b.isResolved());
    manifest.clear();
    // $NON-NLS-1$
    manifest.put(Constants.BUNDLE_MANIFESTVERSION, "2");
    // $NON-NLS-1$ //$NON-NLS-2$
    manifest.put(Constants.BUNDLE_SYMBOLICNAME, "singleton; " + Constants.SINGLETON_DIRECTIVE + ":=true");
    // $NON-NLS-1$
    manifest.put(Constants.BUNDLE_VERSION, "1.1");
    // $NON-NLS-1$
    manifest.put(Constants.EXPORT_PACKAGE, "singleton");
    // $NON-NLS-1$
    BundleDescription singleton2 = state.getFactory().createBundleDescription(state, manifest, "singleton2", id++);
    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.1");
    // $NON-NLS-1$
    manifest.put(Constants.IMPORT_PACKAGE, "singleton");
    // $NON-NLS-1$
    manifest.put(Constants.EXPORT_PACKAGE, "a;version=1.0.1");
    // $NON-NLS-1$
    BundleDescription a2 = state.getFactory().createBundleDescription(state, manifest, "a2", id++);
    state.addBundle(singleton2);
    state.addBundle(a2);
    state.resolve(new BundleDescription[] { singleton1, singleton2, a1, a2 });
    // $NON-NLS-1$
    assertFalse("2.0", singleton1.isResolved());
    // $NON-NLS-1$
    assertTrue("2.1", singleton2.isResolved());
    // $NON-NLS-1$
    assertTrue("2.2", a1.isResolved());
    // $NON-NLS-1$
    assertTrue("2.3", a2.isResolved());
    // $NON-NLS-1$
    assertTrue("2.4", b.isResolved());
    ExportPackageDescription[] imports = b.getResolvedImports();
    // $NON-NLS-1$
    assertEquals("Unexpected number of imports", 1, imports.length);
    // $NON-NLS-1$
    assertEquals("Unexpected exporter", a2, imports[0].getExporter());
}
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

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