Search in sources :

Example 21 with ModuleWire

use of org.eclipse.osgi.container.ModuleWire in project rt.equinox.framework by eclipse.

the class TestModuleContainer method testMultipleSystemBundleFragmentsWithSameName.

@Test
public void testMultipleSystemBundleFragmentsWithSameName() throws BundleException, IOException {
    // install the system.bundle
    Module systemBundle = createContainerWithSystemBundle(true);
    ModuleContainer container = systemBundle.getContainer();
    // install multiple versions of the same fragment
    Map<String, String> systemFragManifest1 = new HashMap<String, String>();
    systemFragManifest1.put(Constants.BUNDLE_MANIFESTVERSION, "2");
    systemFragManifest1.put(Constants.BUNDLE_SYMBOLICNAME, "systemFrag");
    systemFragManifest1.put(Constants.BUNDLE_VERSION, "1.0");
    systemFragManifest1.put(Constants.FRAGMENT_HOST, Constants.SYSTEM_BUNDLE_SYMBOLICNAME);
    Module systemFrag1 = installDummyModule(systemFragManifest1, "systemFrag1", container);
    // first attempt to resolve the lowest version before installing the others
    ResolutionReport report = container.resolve(Arrays.asList(systemFrag1), true);
    Assert.assertNull("Unexpected failure message", report.getResolutionException());
    List<ModuleWire> hostWires = systemBundle.getCurrentRevision().getWiring().getProvidedModuleWires(HostNamespace.HOST_NAMESPACE);
    assertEquals("Wrong number of fragments.", 1, hostWires.size());
    List<ModuleWire> systemFrag1HostWires = systemFrag1.getCurrentRevision().getWiring().getRequiredModuleWires(HostNamespace.HOST_NAMESPACE);
    assertWires(systemFrag1HostWires, hostWires);
    Map<String, String> systemFragManifest2 = new HashMap<String, String>();
    systemFragManifest2.put(Constants.BUNDLE_MANIFESTVERSION, "2");
    systemFragManifest2.put(Constants.BUNDLE_SYMBOLICNAME, "systemFrag");
    systemFragManifest2.put(Constants.BUNDLE_VERSION, "2.0");
    systemFragManifest2.put(Constants.FRAGMENT_HOST, Constants.SYSTEM_BUNDLE_SYMBOLICNAME);
    Module systemFrag2 = installDummyModule(systemFragManifest2, "systemFrag2", container);
    Map<String, String> systemFragManifest3 = new HashMap<String, String>();
    systemFragManifest3.put(Constants.BUNDLE_MANIFESTVERSION, "2");
    systemFragManifest3.put(Constants.BUNDLE_SYMBOLICNAME, "systemFrag");
    systemFragManifest3.put(Constants.BUNDLE_VERSION, "3.0");
    systemFragManifest3.put(Constants.FRAGMENT_HOST, Constants.SYSTEM_BUNDLE_SYMBOLICNAME);
    Module systemFrag3 = installDummyModule(systemFragManifest3, "systemFrag3", container);
    report = container.resolve(Arrays.asList(systemFrag2), true);
    Assert.assertNotNull("Expected failure message", report.getResolutionException());
    report = container.resolve(Arrays.asList(systemFrag3), true);
    Assert.assertNotNull("Expected failure message", report.getResolutionException());
    hostWires = systemBundle.getCurrentRevision().getWiring().getProvidedModuleWires(HostNamespace.HOST_NAMESPACE);
    assertEquals("Wrong number of fragments.", 1, hostWires.size());
    systemFrag1HostWires = systemFrag1.getCurrentRevision().getWiring().getRequiredModuleWires(HostNamespace.HOST_NAMESPACE);
    assertWires(systemFrag1HostWires, hostWires);
    // uninstall the fragments so we can start over
    container.uninstall(systemFrag1);
    container.uninstall(systemFrag2);
    container.uninstall(systemFrag3);
    // refresh the system bundle to get only it resolved
    report = container.refresh(Collections.singleton(systemBundle));
    Assert.assertNull("Unexpected failure message", report.getResolutionException());
    hostWires = systemBundle.getCurrentRevision().getWiring().getProvidedModuleWires(HostNamespace.HOST_NAMESPACE);
    assertEquals("Wrong number of fragments.", 0, hostWires.size());
    // install the fragments again
    systemFrag1 = installDummyModule(systemFragManifest1, "systemFrag1", container);
    systemFrag2 = installDummyModule(systemFragManifest2, "systemFrag2", container);
    systemFrag3 = installDummyModule(systemFragManifest3, "systemFrag3", container);
    report = container.resolve(Arrays.asList(systemFrag1), true);
    Assert.assertNotNull("Expected failure message", report.getResolutionException());
    report = container.resolve(Arrays.asList(systemFrag2), true);
    Assert.assertNotNull("Expected failure message", report.getResolutionException());
    report = container.resolve(Arrays.asList(systemFrag3), true);
    Assert.assertNull("Unexpected failure message", report.getResolutionException());
    hostWires = systemBundle.getCurrentRevision().getWiring().getProvidedModuleWires(HostNamespace.HOST_NAMESPACE);
    List<ModuleWire> systemFrag3HostWires = systemFrag3.getCurrentRevision().getWiring().getRequiredModuleWires(HostNamespace.HOST_NAMESPACE);
    assertWires(systemFrag3HostWires, hostWires);
}
Also used : ModuleWire(org.eclipse.osgi.container.ModuleWire) ModuleContainer(org.eclipse.osgi.container.ModuleContainer) HashMap(java.util.HashMap) Module(org.eclipse.osgi.container.Module) ResolutionReport(org.eclipse.osgi.report.resolution.ResolutionReport) Test(org.junit.Test)

Example 22 with ModuleWire

use of org.eclipse.osgi.container.ModuleWire in project rt.equinox.framework by eclipse.

the class TestModuleContainer method testSystemBundleFragmentsPackageImport.

@Test
public void testSystemBundleFragmentsPackageImport() throws BundleException, IOException {
    // install the system.bundle
    Module systemBundle = createContainerWithSystemBundle(true);
    ModuleContainer container = systemBundle.getContainer();
    // install an system.bundle fragment that imports framework package
    Map<String, String> systemFragManifest = new HashMap<String, String>();
    systemFragManifest.put(Constants.BUNDLE_MANIFESTVERSION, "2");
    systemFragManifest.put(Constants.BUNDLE_SYMBOLICNAME, "systemFrag");
    systemFragManifest.put(Constants.FRAGMENT_HOST, Constants.SYSTEM_BUNDLE_SYMBOLICNAME);
    systemFragManifest.put(Constants.IMPORT_PACKAGE, "org.osgi.framework");
    Module systemFrag = installDummyModule(systemFragManifest, "systemFrag", container);
    ResolutionReport report = container.resolve(Arrays.asList(systemFrag), true);
    Assert.assertNull("Failed to resolve system.bundle.", report.getResolutionException());
    List<ModuleWire> hostWires = systemBundle.getCurrentRevision().getWiring().getProvidedModuleWires(HostNamespace.HOST_NAMESPACE);
    assertEquals("Wrong number of fragments.", 1, hostWires.size());
    Assert.assertEquals("Unexpected fragment revision: " + hostWires, systemFrag.getCurrentRevision(), hostWires.get(0).getRequirer());
    List<ModuleWire> systemBundleRequiredWires = systemBundle.getCurrentRevision().getWiring().getRequiredModuleWires(null);
    assertEquals("No required wires expected.", 0, systemBundleRequiredWires.size());
}
Also used : ModuleWire(org.eclipse.osgi.container.ModuleWire) ModuleContainer(org.eclipse.osgi.container.ModuleContainer) HashMap(java.util.HashMap) Module(org.eclipse.osgi.container.Module) ResolutionReport(org.eclipse.osgi.report.resolution.ResolutionReport) Test(org.junit.Test)

Example 23 with ModuleWire

use of org.eclipse.osgi.container.ModuleWire in project rt.equinox.framework by eclipse.

the class TestModuleContainer method testUses1Dynamic.

@Test
public void testUses1Dynamic() throws BundleException, IOException {
    DummyContainerAdaptor adaptor = createDummyAdaptor(new DummyDebugOptions(Collections.singletonMap("org.eclipse.osgi/resolver/report", "true")));
    ModuleContainer container = adaptor.getContainer();
    Module systemBundle = installDummyModule("system.bundle.MF", Constants.SYSTEM_BUNDLE_LOCATION, container);
    container.resolve(Arrays.asList(systemBundle), true);
    Module uses_a = installDummyModule("uses.a.MF", "a", container);
    Module uses_b = installDummyModule("uses.b.MF", "b", container);
    Module uses_c_dynamic = installDummyModule("uses.c.dynamic.MF", "c", container);
    container.resolve(null, false);
    Assert.assertEquals("a should resolve.", State.RESOLVED, uses_a.getState());
    Assert.assertEquals("b should resolve.", State.RESOLVED, uses_b.getState());
    Assert.assertEquals("c should resolve.", State.RESOLVED, uses_c_dynamic.getState());
    ModuleWire dynamicWire = container.resolveDynamic("uses1", uses_c_dynamic.getCurrentRevision());
    Assert.assertNotNull("No dynamic wire.", dynamicWire);
    PrintStream originalOut = Debug.out;
    ByteArrayOutputStream bytesOut = new ByteArrayOutputStream();
    PrintStream testOut = new PrintStream(bytesOut);
    Debug.out = testOut;
    try {
        dynamicWire = container.resolveDynamic("uses2", uses_c_dynamic.getCurrentRevision());
        Assert.assertNull("Dynamic wire found.", dynamicWire);
    } finally {
        Debug.out = originalOut;
        testOut.close();
    }
    String traceOutput = bytesOut.toString();
    Assert.assertTrue("Wrong traceOutput: " + traceOutput, traceOutput.startsWith("org.osgi.service.resolver.ResolutionException"));
}
Also used : DummyContainerAdaptor(org.eclipse.osgi.tests.container.dummys.DummyContainerAdaptor) PrintStream(java.io.PrintStream) ModuleWire(org.eclipse.osgi.container.ModuleWire) ModuleContainer(org.eclipse.osgi.container.ModuleContainer) DummyDebugOptions(org.eclipse.osgi.tests.container.dummys.DummyDebugOptions) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Module(org.eclipse.osgi.container.Module) Test(org.junit.Test)

Example 24 with ModuleWire

use of org.eclipse.osgi.container.ModuleWire in project rt.equinox.framework by eclipse.

the class TestModuleContainer method testBug457118.

@Test
public void testBug457118() throws BundleException, IOException {
    DummyContainerAdaptor adaptor = createDummyAdaptor();
    ModuleContainer container = adaptor.getContainer();
    Module systemBundle = installDummyModule("system.bundle.MF", Constants.SYSTEM_BUNDLE_LOCATION, container);
    container.resolve(Arrays.asList(systemBundle), true);
    Module e = installDummyModule("bug457118.e.MF", "e", container);
    Module a = installDummyModule("bug457118.a.MF", "a", container);
    Module b = installDummyModule("bug457118.b.MF", "b", container);
    Module c = installDummyModule("bug457118.c.MF", "c", container);
    Module d = installDummyModule("bug457118.d.MF", "d", container);
    installDummyModule("bug457118.a2.MF", "a2", container);
    installDummyModule("bug457118.b2.MF", "b2", container);
    installDummyModule("bug457118.c2.MF", "c2", container);
    installDummyModule("bug457118.d2.MF", "d2", container);
    container.resolve(null, true);
    Assert.assertEquals("e should resolve.", State.RESOLVED, e.getState());
    Assert.assertEquals("a should resolve.", State.RESOLVED, a.getState());
    Assert.assertEquals("b should resolve.", State.RESOLVED, b.getState());
    Assert.assertEquals("c should resolve.", State.RESOLVED, c.getState());
    Assert.assertEquals("d should resolve.", State.RESOLVED, d.getState());
    List<ModuleWire> bundleWires = e.getCurrentRevision().getWiring().getRequiredModuleWires(BundleNamespace.BUNDLE_NAMESPACE);
    Assert.assertEquals("Wrong number of bundle wires: " + bundleWires, 1, bundleWires.size());
    Assert.assertEquals("Wrong bundle provider", a.getCurrentRevision(), bundleWires.get(0).getProvider());
}
Also used : DummyContainerAdaptor(org.eclipse.osgi.tests.container.dummys.DummyContainerAdaptor) ModuleWire(org.eclipse.osgi.container.ModuleWire) ModuleContainer(org.eclipse.osgi.container.ModuleContainer) Module(org.eclipse.osgi.container.Module) Test(org.junit.Test)

Example 25 with ModuleWire

use of org.eclipse.osgi.container.ModuleWire in project rt.equinox.framework by eclipse.

the class TestModuleContainer method testSystemBundleFragmentsNonPayloadRequirements.

@Test
public void testSystemBundleFragmentsNonPayloadRequirements() throws BundleException, IOException {
    // install the system.bundle
    Module systemBundle = createContainerWithSystemBundle(true);
    ModuleContainer container = systemBundle.getContainer();
    // install an system.bundle fragment that imports framework package
    Map<String, String> systemFragManifest = new HashMap<String, String>();
    systemFragManifest.put(Constants.BUNDLE_MANIFESTVERSION, "2");
    systemFragManifest.put(Constants.BUNDLE_SYMBOLICNAME, "systemFrag");
    systemFragManifest.put(Constants.FRAGMENT_HOST, Constants.SYSTEM_BUNDLE_SYMBOLICNAME);
    systemFragManifest.put(Constants.REQUIRE_CAPABILITY, "osgi.ee; filter:=\"(osgi.ee=JavaSE)\"");
    Module systemFrag = installDummyModule(systemFragManifest, "systemFrag", container);
    ResolutionReport report = container.resolve(Arrays.asList(systemFrag), true);
    Assert.assertNull("Failed to resolve system.bundle.", report.getResolutionException());
    List<ModuleWire> hostWires = systemBundle.getCurrentRevision().getWiring().getProvidedModuleWires(HostNamespace.HOST_NAMESPACE);
    assertEquals("Wrong number of fragments.", 1, hostWires.size());
    Assert.assertEquals("Unexpected fragment revision: " + hostWires, systemFrag.getCurrentRevision(), hostWires.get(0).getRequirer());
    List<ModuleWire> systemBundleRequiredWires = systemBundle.getCurrentRevision().getWiring().getRequiredModuleWires(null);
    assertEquals("No required wires expected.", 0, systemBundleRequiredWires.size());
    List<ModuleWire> fragRequiredWires = systemFrag.getCurrentRevision().getWiring().getRequiredModuleWires(null);
    assertEquals("Wrong number of required wires.", 2, fragRequiredWires.size());
    assertWires(fragRequiredWires, systemBundle.getCurrentRevision().getWiring().getProvidedModuleWires(null));
}
Also used : ModuleWire(org.eclipse.osgi.container.ModuleWire) ModuleContainer(org.eclipse.osgi.container.ModuleContainer) HashMap(java.util.HashMap) Module(org.eclipse.osgi.container.Module) ResolutionReport(org.eclipse.osgi.report.resolution.ResolutionReport) Test(org.junit.Test)

Aggregations

ModuleWire (org.eclipse.osgi.container.ModuleWire)45 Module (org.eclipse.osgi.container.Module)32 ModuleContainer (org.eclipse.osgi.container.ModuleContainer)31 Test (org.junit.Test)31 DummyContainerAdaptor (org.eclipse.osgi.tests.container.dummys.DummyContainerAdaptor)25 ModuleWiring (org.eclipse.osgi.container.ModuleWiring)21 ResolutionReport (org.eclipse.osgi.report.resolution.ResolutionReport)13 HashMap (java.util.HashMap)11 ArrayList (java.util.ArrayList)9 ModuleRevision (org.eclipse.osgi.container.ModuleRevision)9 NullPackageSource (org.eclipse.osgi.internal.loader.sources.NullPackageSource)5 PackageSource (org.eclipse.osgi.internal.loader.sources.PackageSource)5 HashSet (java.util.HashSet)4 BundleRequirement (org.osgi.framework.wiring.BundleRequirement)4 ModuleCapability (org.eclipse.osgi.container.ModuleCapability)3 Generation (org.eclipse.osgi.storage.BundleInfo.Generation)3 DummyModuleDatabase (org.eclipse.osgi.tests.container.dummys.DummyModuleDatabase)3 BundleCapability (org.osgi.framework.wiring.BundleCapability)3 Bundle (org.osgi.framework.Bundle)2 BundleException (org.osgi.framework.BundleException)2