Search in sources :

Example 6 with ModuleWiring

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

the class DependentPolicy method loadResource.

public URL loadResource(String name) {
    if (allDependents == null)
        return null;
    URL result = null;
    // size may change, so we must check it every time
    for (int i = 0; i < allDependents.size() && result == null; i++) {
        ModuleWiring searchWiring = allDependents.get(i);
        BundleLoader searchLoader = (BundleLoader) searchWiring.getModuleLoader();
        if (searchLoader != null) {
            result = searchLoader.findResource(name);
            if (result == null) {
                addDependent(i, searchWiring);
            }
        }
    }
    return result;
}
Also used : ModuleWiring(org.eclipse.osgi.container.ModuleWiring) URL(java.net.URL) BundleLoader(org.eclipse.osgi.internal.loader.BundleLoader)

Example 7 with ModuleWiring

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

the class DependentPolicy method loadClass.

public Class<?> loadClass(String name) {
    if (allDependents == null)
        return null;
    Class<?> result = null;
    // size may change, so we must check it every time
    for (int i = 0; i < allDependents.size() && result == null; i++) {
        ModuleWiring searchWiring = allDependents.get(i);
        BundleLoader searchLoader = (BundleLoader) searchWiring.getModuleLoader();
        if (searchLoader != null) {
            try {
                result = searchLoader.findClass(name);
            } catch (ClassNotFoundException e) {
                if (result == null)
                    addDependent(i, searchWiring);
            }
        }
    }
    return result;
}
Also used : ModuleWiring(org.eclipse.osgi.container.ModuleWiring) BundleLoader(org.eclipse.osgi.internal.loader.BundleLoader)

Example 8 with ModuleWiring

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

the class TestModuleContainer method testSubstitutableExport.

@Test
public void testSubstitutableExport() 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);
    ResolutionReport report = container.resolve(Arrays.asList(systemBundle), true);
    Assert.assertNull("Failed to resolve system.bundle.", report.getResolutionException());
    // install an exporter with substitutable export.
    Map<String, String> exporterManifest = new HashMap<String, String>();
    exporterManifest.put(Constants.BUNDLE_MANIFESTVERSION, "2");
    exporterManifest.put(Constants.BUNDLE_SYMBOLICNAME, "exporter");
    exporterManifest.put(Constants.EXPORT_PACKAGE, "exporter");
    exporterManifest.put(Constants.IMPORT_PACKAGE, "exporter");
    Module moduleSubsExport = installDummyModule(exporterManifest, "exporter", container);
    report = container.resolve(Arrays.asList(moduleSubsExport), true);
    Assert.assertNull("Failed to resolve", report.getResolutionException());
    List<BundleRequirement> reqs = moduleSubsExport.getCurrentRevision().getWiring().getRequirements(PackageNamespace.PACKAGE_NAMESPACE);
    assertEquals("Wrong number of imports.", 0, reqs.size());
    container.uninstall(moduleSubsExport);
    exporterManifest = new HashMap<String, String>();
    exporterManifest.put(Constants.BUNDLE_MANIFESTVERSION, "2");
    exporterManifest.put(Constants.BUNDLE_SYMBOLICNAME, "substitutableExporter");
    exporterManifest.put(Constants.EXPORT_PACKAGE, "exporter");
    exporterManifest.put(Constants.IMPORT_PACKAGE, "exporter; pickme=true");
    moduleSubsExport = installDummyModule(exporterManifest, "substitutableExporter", container);
    exporterManifest = new HashMap<String, String>();
    exporterManifest.put(Constants.BUNDLE_MANIFESTVERSION, "2");
    exporterManifest.put(Constants.BUNDLE_SYMBOLICNAME, "exporter");
    exporterManifest.put(Constants.EXPORT_PACKAGE, "exporter; pickme=true");
    Module moduleExport = installDummyModule(exporterManifest, "exporter", container);
    report = container.resolve(Arrays.asList(moduleSubsExport), true);
    Assert.assertNull("Failed to resolve", report.getResolutionException());
    List<BundleCapability> caps = moduleSubsExport.getCurrentRevision().getWiring().getCapabilities(PackageNamespace.PACKAGE_NAMESPACE);
    assertEquals("Wrong number of capabilities.", 0, caps.size());
    reqs = moduleSubsExport.getCurrentRevision().getWiring().getRequirements(PackageNamespace.PACKAGE_NAMESPACE);
    assertEquals("Wrong number of imports.", 1, reqs.size());
    ModuleWiring wiring = moduleSubsExport.getCurrentRevision().getWiring();
    List<ModuleWire> packageWires = wiring.getRequiredModuleWires(PackageNamespace.PACKAGE_NAMESPACE);
    Assert.assertEquals("Unexpected number of wires", 1, packageWires.size());
    Assert.assertEquals("Wrong exporter", packageWires.get(0).getProviderWiring().getRevision(), moduleExport.getCurrentRevision());
}
Also used : ModuleWire(org.eclipse.osgi.container.ModuleWire) ModuleContainer(org.eclipse.osgi.container.ModuleContainer) HashMap(java.util.HashMap) ResolutionReport(org.eclipse.osgi.report.resolution.ResolutionReport) BundleRequirement(org.osgi.framework.wiring.BundleRequirement) DummyContainerAdaptor(org.eclipse.osgi.tests.container.dummys.DummyContainerAdaptor) ModuleWiring(org.eclipse.osgi.container.ModuleWiring) Module(org.eclipse.osgi.container.Module) BundleCapability(org.osgi.framework.wiring.BundleCapability) Test(org.junit.Test)

Example 9 with ModuleWiring

use of org.eclipse.osgi.container.ModuleWiring 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 10 with ModuleWiring

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

Aggregations

ModuleWiring (org.eclipse.osgi.container.ModuleWiring)39 Module (org.eclipse.osgi.container.Module)22 ModuleWire (org.eclipse.osgi.container.ModuleWire)21 ModuleContainer (org.eclipse.osgi.container.ModuleContainer)20 DummyContainerAdaptor (org.eclipse.osgi.tests.container.dummys.DummyContainerAdaptor)20 Test (org.junit.Test)20 ModuleRevision (org.eclipse.osgi.container.ModuleRevision)12 BundleLoader (org.eclipse.osgi.internal.loader.BundleLoader)8 ArrayList (java.util.ArrayList)7 ResolutionReport (org.eclipse.osgi.report.resolution.ResolutionReport)6 URL (java.net.URL)5 BundleCapability (org.osgi.framework.wiring.BundleCapability)4 HashMap (java.util.HashMap)3 ModuleCapability (org.eclipse.osgi.container.ModuleCapability)3 DummyModuleDatabase (org.eclipse.osgi.tests.container.dummys.DummyModuleDatabase)3 Bundle (org.osgi.framework.Bundle)3 BundleException (org.osgi.framework.BundleException)3 IOException (java.io.IOException)2 ModuleClassLoader (org.eclipse.osgi.internal.loader.ModuleClassLoader)2 BundleRequirement (org.osgi.framework.wiring.BundleRequirement)2