Search in sources :

Example 36 with ModuleWire

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

the class TestModuleContainer method testDynamicImport03.

@Test
public void testDynamicImport03() throws BundleException, IOException {
    DummyContainerAdaptor adaptor = createDummyAdaptor();
    ModuleContainer container = adaptor.getContainer();
    DummyModuleDatabase database = adaptor.getDatabase();
    Module systemBundle = installDummyModule("system.bundle.MF", Constants.SYSTEM_BUNDLE_LOCATION, container);
    container.resolve(Arrays.asList(systemBundle), true);
    Module dynamic3 = installDummyModule("dynamic2_v1.MF", "dynamic2_v1", container);
    container.resolve(Arrays.asList(systemBundle, dynamic3), true);
    ModuleWire dynamicWire = container.resolveDynamic("c1.a", dynamic3.getCurrentRevision());
    Assert.assertNull("Dynamic wire found.", dynamicWire);
    Module c1v1 = installDummyModule("c1_v1.MF", "c1_v1", container);
    database.getModuleEvents();
    dynamicWire = container.resolveDynamic("c1.a", dynamic3.getCurrentRevision());
    Assert.assertNotNull("Dynamic wire not found.", dynamicWire);
    Assert.assertEquals("Wrong package found.", "c1.a", dynamicWire.getCapability().getAttributes().get(PackageNamespace.PACKAGE_NAMESPACE));
    Assert.assertEquals("Wrong provider for the wire found.", c1v1.getCurrentRevision(), dynamicWire.getProvider());
    ModuleWiring c1v1Wiring = c1v1.getCurrentRevision().getWiring();
    Assert.assertNotNull("c1 wiring is null.", c1v1Wiring);
    Module c1v2 = installDummyModule("c1_v2.MF", "c1_v2", container);
    container.resolve(Arrays.asList(c1v2), true);
    database.getModuleEvents();
    dynamicWire = container.resolveDynamic("c1.b", dynamic3.getCurrentRevision());
    Assert.assertNotNull("Dynamic wire not found.", dynamicWire);
    Assert.assertEquals("Wrong package found.", "c1.b", dynamicWire.getCapability().getAttributes().get(PackageNamespace.PACKAGE_NAMESPACE));
    Assert.assertEquals("Wrong provider.", c1v1.getCurrentRevision(), dynamicWire.getProvider());
}
Also used : DummyContainerAdaptor(org.eclipse.osgi.tests.container.dummys.DummyContainerAdaptor) ModuleWire(org.eclipse.osgi.container.ModuleWire) ModuleContainer(org.eclipse.osgi.container.ModuleContainer) ModuleWiring(org.eclipse.osgi.container.ModuleWiring) Module(org.eclipse.osgi.container.Module) DummyModuleDatabase(org.eclipse.osgi.tests.container.dummys.DummyModuleDatabase) Test(org.junit.Test)

Example 37 with ModuleWire

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

the class TestModuleContainer method testSystemBundleFragmentsWithPayloadRequirements.

@Test
public void testSystemBundleFragmentsWithPayloadRequirements() throws BundleException, IOException {
    // install the system.bundle
    Module systemBundle = createContainerWithSystemBundle(true);
    ModuleContainer container = systemBundle.getContainer();
    // install an system.bundle fragment that requires a payload requirement from system.bundle
    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, "equinox.test; filter:=\"(equinox.test=system)\"");
    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("Wrong number of wires.", 1, systemBundleRequiredWires.size());
    assertEquals("Wrong requirer.", systemBundle.getCurrentRevision(), systemBundleRequiredWires.get(0).getRequirer());
    assertEquals("Wrong requirement.", systemFrag.getCurrentRevision(), systemBundleRequiredWires.get(0).getRequirement().getRevision());
    List<ModuleWire> fragRequiredWires = systemFrag.getCurrentRevision().getWiring().getRequiredModuleWires(null);
    assertEquals("Wrong number of required wires.", 1, fragRequiredWires.size());
    assertWires(fragRequiredWires, 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 38 with ModuleWire

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

the class TestModuleContainer method testDynamicImport01.

@Test
public void testDynamicImport01() throws BundleException, IOException {
    DummyContainerAdaptor adaptor = createDummyAdaptor();
    ModuleContainer container = adaptor.getContainer();
    Module systemBundle = installDummyModule("system.bundle.MF", Constants.SYSTEM_BUNDLE_LOCATION, null, null, "osgi.ee; osgi.ee=JavaSE; version:Version=\"1.5.0\"", container);
    container.resolve(Arrays.asList(systemBundle), true);
    Module c1 = installDummyModule("c1_v1.MF", "c1_v1", container);
    Module dynamic1 = installDummyModule("dynamic1_v1.MF", "dynamic1_v1", container);
    container.resolve(Arrays.asList(c1, dynamic1), true);
    ModuleWire dynamicWire = container.resolveDynamic("org.osgi.framework", dynamic1.getCurrentRevision());
    Assert.assertNotNull("No dynamic wire found.", dynamicWire);
    Assert.assertEquals("Wrong package found.", "org.osgi.framework", dynamicWire.getCapability().getAttributes().get(PackageNamespace.PACKAGE_NAMESPACE));
    Assert.assertEquals("Wrong provider for the wire found.", systemBundle.getCurrentRevision(), dynamicWire.getProvider());
    dynamicWire = container.resolveDynamic("org.osgi.framework.wiring", dynamic1.getCurrentRevision());
    Assert.assertNotNull("No dynamic wire found.", dynamicWire);
    Assert.assertEquals("Wrong package found.", "org.osgi.framework.wiring", dynamicWire.getCapability().getAttributes().get(PackageNamespace.PACKAGE_NAMESPACE));
    Assert.assertEquals("Wrong provider for the wire found.", systemBundle.getCurrentRevision(), dynamicWire.getProvider());
    dynamicWire = container.resolveDynamic("c1.b", dynamic1.getCurrentRevision());
    Assert.assertNotNull("No dynamic wire found.", dynamicWire);
    Assert.assertEquals("Wrong package found.", "c1.b", dynamicWire.getCapability().getAttributes().get(PackageNamespace.PACKAGE_NAMESPACE));
    Assert.assertEquals("Wrong provider for the wire found.", c1.getCurrentRevision(), dynamicWire.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 39 with ModuleWire

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

the class TestModuleContainer method testMissingHost.

@Test
public void testMissingHost() throws BundleException, IOException {
    DummyContainerAdaptor adaptor = createDummyAdaptor();
    ModuleContainer container = adaptor.getContainer();
    installDummyModule("system.bundle.MF", Constants.SYSTEM_BUNDLE_LOCATION, container);
    Module f1v1 = installDummyModule("f1_v1.MF", "f1_v1", container);
    Module b3 = installDummyModule("b3_v1.MF", "b3_v1", container);
    ResolutionReport report = container.resolve(Arrays.asList(f1v1, b3), true);
    Assert.assertNotNull("Expected a resolution exception.", report.getResolutionException());
    Module h1v1 = installDummyModule("h1_v1.MF", "h1_v1", container);
    report = container.resolve(Arrays.asList(b3), true);
    Assert.assertNull("Expected no resolution exception.", report.getResolutionException());
    ModuleWiring wiring = b3.getCurrentRevision().getWiring();
    List<ModuleWire> packageWires = wiring.getRequiredModuleWires(PackageNamespace.PACKAGE_NAMESPACE);
    Assert.assertEquals("Expected 1 import.", 1, packageWires.size());
    ModuleWire pkgWire = packageWires.get(0);
    Assert.assertEquals("Wrong host exporter.", pkgWire.getProviderWiring().getRevision(), h1v1.getCurrentRevision());
}
Also used : DummyContainerAdaptor(org.eclipse.osgi.tests.container.dummys.DummyContainerAdaptor) ModuleWire(org.eclipse.osgi.container.ModuleWire) ModuleContainer(org.eclipse.osgi.container.ModuleContainer) ModuleWiring(org.eclipse.osgi.container.ModuleWiring) Module(org.eclipse.osgi.container.Module) ResolutionReport(org.eclipse.osgi.report.resolution.ResolutionReport) Test(org.junit.Test)

Example 40 with ModuleWire

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

the class Storage method installExtensions.

private void installExtensions() {
    Module systemModule = moduleContainer.getModule(0);
    ModuleRevision systemRevision = systemModule == null ? null : systemModule.getCurrentRevision();
    ModuleWiring systemWiring = systemRevision == null ? null : systemRevision.getWiring();
    if (systemWiring == null) {
        return;
    }
    Collection<ModuleRevision> fragments = new ArrayList<>();
    for (ModuleWire hostWire : systemWiring.getProvidedModuleWires(HostNamespace.HOST_NAMESPACE)) {
        fragments.add(hostWire.getRequirer());
    }
    try {
        getExtensionInstaller().addExtensionContent(fragments, null);
    } catch (BundleException e) {
        getLogServices().log(EquinoxContainer.NAME, FrameworkLogEntry.ERROR, e.getMessage(), e);
    }
}
Also used : ModuleWire(org.eclipse.osgi.container.ModuleWire) ModuleWiring(org.eclipse.osgi.container.ModuleWiring) ArrayList(java.util.ArrayList) BundleException(org.osgi.framework.BundleException) Module(org.eclipse.osgi.container.Module) ModuleRevision(org.eclipse.osgi.container.ModuleRevision)

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