use of org.eclipse.osgi.container.ModuleWire 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.ModuleWire in project rt.equinox.framework by eclipse.
the class TestModuleContainer method testDynamicWithOptionalImport.
@Test
public void testDynamicWithOptionalImport() 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 importer
Map<String, String> optionalImporterManifest = new HashMap<String, String>();
optionalImporterManifest.put(Constants.BUNDLE_MANIFESTVERSION, "2");
optionalImporterManifest.put(Constants.BUNDLE_SYMBOLICNAME, "importer");
optionalImporterManifest.put(Constants.IMPORT_PACKAGE, "exporter; resolution:=optional");
optionalImporterManifest.put(Constants.DYNAMICIMPORT_PACKAGE, "exporter");
Module optionalImporterModule = installDummyModule(optionalImporterManifest, "optionalImporter", container);
// unsatisfied optional and dynamic imports do not fail a resolve.
report = container.resolve(Arrays.asList(optionalImporterModule), true);
Assert.assertNull("Failed to resolve system.bundle.", report.getResolutionException());
// dynamic and optional imports are same. Optional import is not satisfied we should only see the dynamic import
List<BundleRequirement> importReqsList = optionalImporterModule.getCurrentRevision().getWiring().getRequirements(PackageNamespace.PACKAGE_NAMESPACE);
assertEquals("Wrong number of imports.", 1, importReqsList.size());
assertEquals("Import was not dynamic", PackageNamespace.RESOLUTION_DYNAMIC, importReqsList.get(0).getDirectives().get(Namespace.REQUIREMENT_RESOLUTION_DIRECTIVE));
// install a exporter to satisfy existing optional import
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");
installDummyModule(exporterManifest, "exporter", container);
ModuleWire dynamicWire = container.resolveDynamic("exporter", optionalImporterModule.getCurrentRevision());
Assert.assertNotNull("Expected to find a dynamic wire.", dynamicWire);
// re-resolve importer
container.refresh(Collections.singleton(optionalImporterModule));
report = container.resolve(Arrays.asList(optionalImporterModule), true);
Assert.assertNull("Failed to resolve system.bundle.", report.getResolutionException());
importReqsList = optionalImporterModule.getCurrentRevision().getWiring().getRequirements(PackageNamespace.PACKAGE_NAMESPACE);
assertEquals("Wrong number of imports.", 2, importReqsList.size());
}
use of org.eclipse.osgi.container.ModuleWire 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());
}
use of org.eclipse.osgi.container.ModuleWire 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());
}
}
}
use of org.eclipse.osgi.container.ModuleWire in project rt.equinox.framework by eclipse.
the class TestModuleContainer method testDynamicImportMiss01.
@Test
public void testDynamicImportMiss01() 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);
DummyResolverHookFactory factory = (DummyResolverHookFactory) adaptor.getResolverHookFactory();
DummyResolverHook hook = (DummyResolverHook) factory.getHook();
hook.getResolutionReports().clear();
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());
Assert.assertEquals("Wrong number of reports.", 1, hook.getResolutionReports().size());
hook.getResolutionReports().clear();
dynamicWire = container.resolveDynamic("does.not.exist", dynamic1.getCurrentRevision());
Assert.assertNull("Unexpected Dynamic wire found.", dynamicWire);
Assert.assertEquals("Wrong number of reports.", 1, hook.getResolutionReports().size());
// Try again; no report should be generated a second time
hook.getResolutionReports().clear();
dynamicWire = container.resolveDynamic("does.not.exist", dynamic1.getCurrentRevision());
Assert.assertNull("Unexpected Dynamic wire found.", dynamicWire);
Assert.assertEquals("Wrong number of reports.", 0, hook.getResolutionReports().size());
}
Aggregations