Search in sources :

Example 31 with ModuleWire

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

the class TestModuleContainer method testDynamicImport02.

@Test
public void testDynamicImport02() 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 c4 = installDummyModule("c4_v1.MF", "c4_v1", container);
    Module dynamic1 = installDummyModule("dynamic1_v1.MF", "dynamic1_v1", container);
    Module dynamic1Frag = installDummyModule("dynamic1.frag_v1.MF", "dynamic1.frag_v1", container);
    container.resolve(Arrays.asList(c1, c4, dynamic1, dynamic1Frag), true);
    ModuleWire 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());
    dynamicWire = container.resolveDynamic("c4.a", dynamic1.getCurrentRevision());
    Assert.assertNotNull("No dynamic wire found.", dynamicWire);
    Assert.assertEquals("Wrong package found.", "c4.a", dynamicWire.getCapability().getAttributes().get(PackageNamespace.PACKAGE_NAMESPACE));
    Assert.assertEquals("Wrong provider for the wire found.", c4.getCurrentRevision(), dynamicWire.getProvider());
    dynamicWire = container.resolveDynamic("c4.b", dynamic1.getCurrentRevision());
    Assert.assertNotNull("No dynamic wire found.", dynamicWire);
    Assert.assertEquals("Wrong package found.", "c4.b", dynamicWire.getCapability().getAttributes().get(PackageNamespace.PACKAGE_NAMESPACE));
    Assert.assertEquals("Wrong provider for the wire found.", c4.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 32 with ModuleWire

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

the class TestModuleContainer method testFragments01.

@Test
public void testFragments01() throws BundleException, IOException {
    DummyContainerAdaptor adaptor = createDummyAdaptor();
    ModuleContainer container = adaptor.getContainer();
    Module systemModule = installDummyModule("system.bundle.MF", Constants.SYSTEM_BUNDLE_LOCATION, container);
    Module c1 = installDummyModule("c1_v1.MF", "c1_v1", container);
    Module h2 = installDummyModule("h2_v1.MF", "h2_v1", container);
    Module f2 = installDummyModule("f2_v1.MF", "f2_v1", container);
    container.resolve(Arrays.asList(systemModule, c1, h2, f2), true);
    ModuleWiring wiring = h2.getCurrentRevision().getWiring();
    List<ModuleWire> requiredWires = wiring.getRequiredModuleWires(null);
    Assert.assertEquals("Wrong number of required wires.", 3, requiredWires.size());
    for (ModuleWire wire : requiredWires) {
        ModuleCapability capability = wire.getCapability();
        Assert.assertEquals("Wrong namespace.", PackageNamespace.PACKAGE_NAMESPACE, capability.getNamespace());
        Assert.assertEquals("Wrong requirer.", h2.getCurrentRevision(), wire.getRequirer());
        String pkgName = (String) capability.getAttributes().get(PackageNamespace.PACKAGE_NAMESPACE);
        Assert.assertNotNull("No package name.", pkgName);
        ModuleRevision expectedReqRevision;
        if (pkgName.equals("org.osgi.framework")) {
            expectedReqRevision = h2.getCurrentRevision();
        } else {
            expectedReqRevision = f2.getCurrentRevision();
        }
        Assert.assertEquals("Wrong requirement revision.", expectedReqRevision, wire.getRequirement().getRevision());
    }
}
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) ModuleCapability(org.eclipse.osgi.container.ModuleCapability) Module(org.eclipse.osgi.container.Module) ModuleRevision(org.eclipse.osgi.container.ModuleRevision) Test(org.junit.Test)

Example 33 with ModuleWire

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

the class TestModuleContainer method testSubstitutableExports04.

@Test
public void testSubstitutableExports04() throws BundleException, IOException {
    DummyContainerAdaptor adaptor = createDummyAdaptor();
    ModuleContainer container = adaptor.getContainer();
    // install order does not really matter
    installDummyModule("sub.h.MF", "h", container);
    Module i = installDummyModule("sub.i.MF", "i", container);
    installDummyModule("sub.j.MF", "j", container);
    Module k = installDummyModule("sub.k.MF", "k", container);
    // resolve order does matter so that transitive dependencies are pulled in
    // and cause substitution to happen in a certain way
    container.resolve(Arrays.asList(k), true);
    ModuleWiring wiringI = i.getCurrentRevision().getWiring();
    ModuleWiring wiringK = k.getCurrentRevision().getWiring();
    List<ModuleWire> requiredWiresK = wiringK.getRequiredModuleWires(PackageNamespace.PACKAGE_NAMESPACE);
    // I should be the provider for all of K
    Assert.assertEquals("Wrong number of required wires: " + requiredWiresK, 2, requiredWiresK.size());
    for (ModuleWire moduleWire : requiredWiresK) {
        Assert.assertEquals("Wrong provider: " + moduleWire.getProviderWiring(), wiringI, moduleWire.getProviderWiring());
    }
}
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) Test(org.junit.Test)

Example 34 with ModuleWire

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

the class TestModuleContainer method testUses4.

/*
	 * Test that fragments and uses constraints
	 */
@Test
public void testUses4() 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 uses_h = installDummyModule("uses.h.MF", "h", container);
    Module uses_h_frag = installDummyModule("uses.h.frag.MF", "h.frag", container);
    container.resolve(null, false);
    Assert.assertEquals("h should resolve.", State.RESOLVED, uses_h.getState());
    Assert.assertEquals("h.frag should resolve.", State.RESOLVED, uses_h_frag.getState());
    Module uses_i = installDummyModule("uses.i.MF", "i", container);
    Module uses_j = installDummyModule("uses.j.MF", "j", container);
    container.resolve(null, false);
    Assert.assertEquals("i should resolve.", State.RESOLVED, uses_i.getState());
    Assert.assertEquals("j should resolve.", State.RESOLVED, uses_j.getState());
    List<BundleWire> requiredWires = uses_j.getCurrentRevision().getWiring().getRequiredWires(null);
    Assert.assertEquals("Wrong number of wires for j", 2, requiredWires.size());
    for (BundleWire wire : requiredWires) {
        Assert.assertEquals("Wrong provider", uses_i.getCurrentRevision(), wire.getProvider());
    }
    Module uses_j_dynamic = installDummyModule("uses.j.dynamic.MF", "j.dynamic", container);
    container.resolve(null, false);
    ModuleWire dynamicWire = container.resolveDynamic("uses2", uses_j_dynamic.getCurrentRevision());
    Assert.assertNotNull("Null dynamic wire.", dynamicWire);
    Assert.assertEquals("Wrong provider", uses_i.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) BundleWire(org.osgi.framework.wiring.BundleWire) Test(org.junit.Test)

Example 35 with ModuleWire

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

the class TestModuleContainer method testSystemBundleFragmentRequiresOtherFragmentFailResolution.

@Test
public void testSystemBundleFragmentRequiresOtherFragmentFailResolution() throws BundleException, IOException {
    // install the system.bundle
    Module systemBundle = createContainerWithSystemBundle(true);
    ModuleContainer container = systemBundle.getContainer();
    // install an system.bundle fragment that provides a capability
    Map<String, String> systemFragManifest1 = new HashMap<String, String>();
    systemFragManifest1.put(Constants.BUNDLE_MANIFESTVERSION, "2");
    systemFragManifest1.put(Constants.BUNDLE_SYMBOLICNAME, "systemFrag1");
    systemFragManifest1.put(Constants.FRAGMENT_HOST, Constants.SYSTEM_BUNDLE_SYMBOLICNAME);
    systemFragManifest1.put(Constants.PROVIDE_CAPABILITY, "fragment.capability; fragment.capability=test1");
    Module systemFrag1 = installDummyModule(systemFragManifest1, "systemFrag1", container);
    // install an system.bundle fragment that requires a fragment capability, but fails to match
    Map<String, String> systemFragManifest2 = new HashMap<String, String>();
    systemFragManifest2.put(Constants.BUNDLE_MANIFESTVERSION, "2");
    systemFragManifest2.put(Constants.BUNDLE_SYMBOLICNAME, "systemFrag2");
    systemFragManifest2.put(Constants.FRAGMENT_HOST, Constants.SYSTEM_BUNDLE_SYMBOLICNAME);
    systemFragManifest2.put(Constants.REQUIRE_CAPABILITY, "fragment.capability; filter:=\"(fragment.capability=test4)\"");
    systemFragManifest2.put(Constants.PROVIDE_CAPABILITY, "fragment.capability; fragment.capability=test2");
    Module systemFrag2 = installDummyModule(systemFragManifest2, "systemFrag2", container);
    // install an system.bundle fragment that requires a fragment capability from a fragment that fails to resolve
    Map<String, String> systemFragManifest3 = new HashMap<String, String>();
    systemFragManifest3.put(Constants.BUNDLE_MANIFESTVERSION, "2");
    systemFragManifest3.put(Constants.BUNDLE_SYMBOLICNAME, "systemFrag3");
    systemFragManifest3.put(Constants.FRAGMENT_HOST, Constants.SYSTEM_BUNDLE_SYMBOLICNAME);
    systemFragManifest3.put(Constants.REQUIRE_CAPABILITY, "fragment.capability; filter:=\"(fragment.capability=test2)\"");
    systemFragManifest3.put(Constants.PROVIDE_CAPABILITY, "fragment.capability; fragment.capability=test3");
    Module systemFrag3 = installDummyModule(systemFragManifest3, "systemFrag3", container);
    ResolutionReport report = container.resolve(Arrays.asList(systemFrag3), true);
    Assert.assertNotNull("Expected 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);
    // install a bundle that can satisfy the failed requirement, but it should not be allowed since it is not a fragment
    Map<String, String> provideCapabilityManifest1 = new HashMap<String, String>();
    provideCapabilityManifest1.put(Constants.BUNDLE_MANIFESTVERSION, "2");
    provideCapabilityManifest1.put(Constants.BUNDLE_SYMBOLICNAME, "provideCapabilityBundle1");
    provideCapabilityManifest1.put(Constants.PROVIDE_CAPABILITY, "fragment.capability; fragment.capability=test4");
    installDummyModule(provideCapabilityManifest1, "provideCapabilityBundle1", container);
    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);
    // install a fragment that satisfies the failed requirement
    Map<String, String> systemFragManifest4 = new HashMap<String, String>();
    systemFragManifest4.put(Constants.BUNDLE_MANIFESTVERSION, "2");
    systemFragManifest4.put(Constants.BUNDLE_SYMBOLICNAME, "systemFrag4");
    systemFragManifest4.put(Constants.FRAGMENT_HOST, Constants.SYSTEM_BUNDLE_SYMBOLICNAME);
    systemFragManifest4.put(Constants.PROVIDE_CAPABILITY, "fragment.capability; fragment.capability=test4");
    Module systemFrag4 = installDummyModule(systemFragManifest4, "systemFrag4", container);
    report = container.resolve(Arrays.asList(systemFrag3), true);
    Assert.assertNull("Failed to resolve.", report.getResolutionException());
    hostWires = systemBundle.getCurrentRevision().getWiring().getProvidedModuleWires(HostNamespace.HOST_NAMESPACE);
    assertEquals("Wrong number of fragments.", 4, hostWires.size());
    systemFrag1HostWires = systemFrag1.getCurrentRevision().getWiring().getRequiredModuleWires(HostNamespace.HOST_NAMESPACE);
    List<ModuleWire> systemFrag2HostWires = systemFrag2.getCurrentRevision().getWiring().getRequiredModuleWires(HostNamespace.HOST_NAMESPACE);
    List<ModuleWire> systemFrag3HostWires = systemFrag3.getCurrentRevision().getWiring().getRequiredModuleWires(HostNamespace.HOST_NAMESPACE);
    List<ModuleWire> systemFrag4HostWires = systemFrag4.getCurrentRevision().getWiring().getRequiredModuleWires(HostNamespace.HOST_NAMESPACE);
    assertWires(systemFrag1HostWires, hostWires);
    assertWires(systemFrag2HostWires, hostWires);
    assertWires(systemFrag3HostWires, hostWires);
    assertWires(systemFrag4HostWires, hostWires);
    List<ModuleCapability> fragmentCapabilities = systemBundle.getCurrentRevision().getWiring().getModuleCapabilities("fragment.capability");
    assertEquals("Wrong number of fragment capabilities.", 4, fragmentCapabilities.size());
    // Use set since the order of required and provided wires will be different
    Set<ModuleWire> hostRequiredFragmentCapWires = new HashSet<ModuleWire>(systemBundle.getCurrentRevision().getWiring().getRequiredModuleWires("fragment.capability"));
    Set<ModuleWire> hostProvidedFragmentCapWires = new HashSet<ModuleWire>(systemBundle.getCurrentRevision().getWiring().getProvidedModuleWires("fragment.capability"));
    assertEquals("Wrong number of wires.", 2, hostProvidedFragmentCapWires.size());
    assertEquals("Wrong wires found from host.", hostRequiredFragmentCapWires, hostProvidedFragmentCapWires);
}
Also used : ModuleWire(org.eclipse.osgi.container.ModuleWire) ModuleContainer(org.eclipse.osgi.container.ModuleContainer) HashMap(java.util.HashMap) ModuleCapability(org.eclipse.osgi.container.ModuleCapability) Module(org.eclipse.osgi.container.Module) ResolutionReport(org.eclipse.osgi.report.resolution.ResolutionReport) HashSet(java.util.HashSet) 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