Search in sources :

Example 11 with ModuleRevision

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

the class NativeCodeBundleTests method setNativeAttribute.

private void setNativeAttribute(String key, String value) {
    Bundle systemBundle = OSGiTestsActivator.getContext().getBundle(0);
    ModuleRevision systemRevision = (ModuleRevision) systemBundle.adapt(BundleRevision.class);
    ModuleCapability nativeCapability = systemRevision.getModuleCapabilities(NativeNamespace.NATIVE_NAMESPACE).get(0);
    Map attrs = new HashMap(nativeCapability.getAttributes());
    attrs.put(key, value);
    nativeCapability.setTransientAttrs(attrs);
}
Also used : HashMap(java.util.HashMap) Bundle(org.osgi.framework.Bundle) BundleRevision(org.osgi.framework.wiring.BundleRevision) ModuleCapability(org.eclipse.osgi.container.ModuleCapability) ModuleRevision(org.eclipse.osgi.container.ModuleRevision) Map(java.util.Map) HashMap(java.util.HashMap)

Example 12 with ModuleRevision

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

the class TestModuleContainer method testSubstitutableExports02.

@Test
public void testSubstitutableExports02() throws BundleException, IOException {
    DummyContainerAdaptor adaptor = createDummyAdaptor();
    ModuleContainer container = adaptor.getContainer();
    Module a = installDummyModule("sub.a.MF", "a", container);
    Module b = installDummyModule("sub.b.MF", "b", container);
    Module c = installDummyModule("sub.c.MF", "c", container);
    container.resolve(Arrays.asList(a, b, c), true);
    ModuleWiring wiringA = a.getCurrentRevision().getWiring();
    ModuleWiring wiringB = b.getCurrentRevision().getWiring();
    ModuleWiring wiringC = c.getCurrentRevision().getWiring();
    List<ModuleWire> providedWiresA = wiringA.getProvidedModuleWires(PackageNamespace.PACKAGE_NAMESPACE);
    Assert.assertEquals("Wrong number of provided wires.", 2, providedWiresA.size());
    Collection<ModuleRevision> requirers = new ArrayList<ModuleRevision>();
    for (ModuleWire wire : providedWiresA) {
        requirers.add(wire.getRequirer());
    }
    Assert.assertTrue("b does not require.", requirers.contains(b.getCurrentRevision()));
    Assert.assertTrue("c does not require.", requirers.contains(c.getCurrentRevision()));
    List<ModuleWire> requiredWiresB = wiringB.getRequiredModuleWires(PackageNamespace.PACKAGE_NAMESPACE);
    Assert.assertEquals("Wrong number of required wires.", 1, requiredWiresB.size());
    Assert.assertEquals("Unexpected package name.", "javax.servlet", requiredWiresB.iterator().next().getCapability().getAttributes().get(PackageNamespace.PACKAGE_NAMESPACE));
    Assert.assertEquals("Wrong provider.", a.getCurrentRevision(), requiredWiresB.iterator().next().getProvider());
    List<ModuleWire> requiredWiresC = wiringC.getRequiredModuleWires(PackageNamespace.PACKAGE_NAMESPACE);
    Assert.assertEquals("Wrong number of required wires.", 1, requiredWiresC.size());
    Assert.assertEquals("Wrong number of required wires.", 1, requiredWiresC.size());
    Assert.assertEquals("Unexpected package name.", "javax.servlet", requiredWiresC.iterator().next().getCapability().getAttributes().get(PackageNamespace.PACKAGE_NAMESPACE));
    Assert.assertEquals("Wrong provider.", a.getCurrentRevision(), requiredWiresC.iterator().next().getProvider());
    Module d = installDummyModule("sub.d.MF", "d", container);
    container.resolve(Arrays.asList(d), true);
    ModuleWiring wiringD = d.getCurrentRevision().getWiring();
    List<ModuleWire> requiredWiresD = wiringD.getRequiredModuleWires(PackageNamespace.PACKAGE_NAMESPACE);
    Assert.assertEquals("Wrong number of required wires.", 2, requiredWiresD.size());
    Assert.assertEquals("Unexpected package name.", "org.ops4j.pax.web.service", requiredWiresD.get(0).getCapability().getAttributes().get(PackageNamespace.PACKAGE_NAMESPACE));
    Assert.assertEquals("Wrong provider.", c.getCurrentRevision(), requiredWiresD.get(0).getProvider());
    Assert.assertEquals("Unexpected package name.", "javax.servlet", requiredWiresD.get(1).getCapability().getAttributes().get(PackageNamespace.PACKAGE_NAMESPACE));
    Assert.assertEquals("Wrong provider.", a.getCurrentRevision(), requiredWiresD.get(1).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) ArrayList(java.util.ArrayList) Module(org.eclipse.osgi.container.Module) ModuleRevision(org.eclipse.osgi.container.ModuleRevision) Test(org.junit.Test)

Example 13 with ModuleRevision

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

the class TestModuleContainer method testSubstitutableExports03.

@Test
public void testSubstitutableExports03() throws BundleException, IOException {
    DummyContainerAdaptor adaptor = createDummyAdaptor();
    ModuleContainer container = adaptor.getContainer();
    // install order does not really matter
    Module g = installDummyModule("sub.g.MF", "g", container);
    Module f = installDummyModule("sub.f.MF", "f", container);
    Module e = installDummyModule("sub.e.MF", "e", 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(g, f, e), true);
    ModuleWiring wiringE = e.getCurrentRevision().getWiring();
    ModuleWiring wiringF = f.getCurrentRevision().getWiring();
    List<ModuleWire> providedWiresE = wiringE.getProvidedModuleWires(PackageNamespace.PACKAGE_NAMESPACE);
    Assert.assertEquals("Wrong number of provided wires.", 3, providedWiresE.size());
    Collection<ModuleRevision> requirers = new HashSet<ModuleRevision>();
    for (ModuleWire wire : providedWiresE) {
        requirers.add(wire.getRequirer());
    }
    Assert.assertTrue("f does not require.", requirers.remove(f.getCurrentRevision()));
    Assert.assertTrue("g does not require.", requirers.remove(g.getCurrentRevision()));
    Assert.assertTrue("No requirers should be left: " + requirers, requirers.isEmpty());
    List<ModuleWire> providedWiresF = wiringF.getProvidedModuleWires(PackageNamespace.PACKAGE_NAMESPACE);
    Assert.assertEquals("Wrong number of provided wires: " + providedWiresF, 0, providedWiresF.size());
}
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) ModuleRevision(org.eclipse.osgi.container.ModuleRevision) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 14 with ModuleRevision

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

the class TestModuleContainer method testSystemBundleOnDemandFragments.

@Test
public void testSystemBundleOnDemandFragments() throws BundleException, IOException {
    DummyContainerAdaptor adaptor = createDummyAdaptor();
    ModuleContainer container = adaptor.getContainer();
    // install the system.bundle
    Module systemBundle = installDummyModule("system.bundle.MF", Constants.SYSTEM_BUNDLE_LOCATION, Constants.SYSTEM_BUNDLE_SYMBOLICNAME, null, null, container);
    // install an equinox fragment
    Map<String, String> equinoxFragManifest = new HashMap<String, String>();
    equinoxFragManifest.put(Constants.BUNDLE_MANIFESTVERSION, "2");
    equinoxFragManifest.put(Constants.BUNDLE_SYMBOLICNAME, "equinoxFrag");
    equinoxFragManifest.put(Constants.FRAGMENT_HOST, "org.eclipse.osgi");
    Module equinoxFrag = installDummyModule(equinoxFragManifest, "equinoxFrag", container);
    // install a system.bundle fragment
    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, "system.bundle");
    Module systemFrag = installDummyModule(systemFragManifest, "systemFrag", container);
    ResolutionReport report = container.resolve(Arrays.asList(systemBundle), 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.", 2, hostWires.size());
    Set<ModuleRevision> fragmentRevisions = new HashSet(Arrays.asList(equinoxFrag.getCurrentRevision(), systemFrag.getCurrentRevision()));
    for (ModuleWire hostWire : hostWires) {
        if (!fragmentRevisions.remove(hostWire.getRequirer())) {
            Assert.fail("Unexpected fragment revision: " + hostWire.getRequirer());
        }
    }
}
Also used : DummyContainerAdaptor(org.eclipse.osgi.tests.container.dummys.DummyContainerAdaptor) 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) ModuleRevision(org.eclipse.osgi.container.ModuleRevision) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 15 with ModuleRevision

use of org.eclipse.osgi.container.ModuleRevision 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)

Aggregations

ModuleRevision (org.eclipse.osgi.container.ModuleRevision)35 Module (org.eclipse.osgi.container.Module)21 Generation (org.eclipse.osgi.storage.BundleInfo.Generation)15 ModuleWiring (org.eclipse.osgi.container.ModuleWiring)12 ArrayList (java.util.ArrayList)9 ModuleContainer (org.eclipse.osgi.container.ModuleContainer)9 ModuleWire (org.eclipse.osgi.container.ModuleWire)9 DummyContainerAdaptor (org.eclipse.osgi.tests.container.dummys.DummyContainerAdaptor)8 Test (org.junit.Test)8 BundleException (org.osgi.framework.BundleException)5 IOException (java.io.IOException)4 ModuleCapability (org.eclipse.osgi.container.ModuleCapability)4 File (java.io.File)3 HashMap (java.util.HashMap)3 HashSet (java.util.HashSet)3 SystemModule (org.eclipse.osgi.container.SystemModule)3 BundleFile (org.eclipse.osgi.storage.bundlefile.BundleFile)3 DirBundleFile (org.eclipse.osgi.storage.bundlefile.DirBundleFile)3 NestedDirBundleFile (org.eclipse.osgi.storage.bundlefile.NestedDirBundleFile)3 ZipBundleFile (org.eclipse.osgi.storage.bundlefile.ZipBundleFile)3