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;
}
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;
}
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());
}
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());
}
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());
}
Aggregations