use of org.eclipse.osgi.container.ModuleWire in project rt.equinox.framework by eclipse.
the class TestModuleContainer method testMultipleSystemBundleFragmentsWithSameName.
@Test
public void testMultipleSystemBundleFragmentsWithSameName() throws BundleException, IOException {
// install the system.bundle
Module systemBundle = createContainerWithSystemBundle(true);
ModuleContainer container = systemBundle.getContainer();
// install multiple versions of the same fragment
Map<String, String> systemFragManifest1 = new HashMap<String, String>();
systemFragManifest1.put(Constants.BUNDLE_MANIFESTVERSION, "2");
systemFragManifest1.put(Constants.BUNDLE_SYMBOLICNAME, "systemFrag");
systemFragManifest1.put(Constants.BUNDLE_VERSION, "1.0");
systemFragManifest1.put(Constants.FRAGMENT_HOST, Constants.SYSTEM_BUNDLE_SYMBOLICNAME);
Module systemFrag1 = installDummyModule(systemFragManifest1, "systemFrag1", container);
// first attempt to resolve the lowest version before installing the others
ResolutionReport report = container.resolve(Arrays.asList(systemFrag1), true);
Assert.assertNull("Unexpected 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);
Map<String, String> systemFragManifest2 = new HashMap<String, String>();
systemFragManifest2.put(Constants.BUNDLE_MANIFESTVERSION, "2");
systemFragManifest2.put(Constants.BUNDLE_SYMBOLICNAME, "systemFrag");
systemFragManifest2.put(Constants.BUNDLE_VERSION, "2.0");
systemFragManifest2.put(Constants.FRAGMENT_HOST, Constants.SYSTEM_BUNDLE_SYMBOLICNAME);
Module systemFrag2 = installDummyModule(systemFragManifest2, "systemFrag2", container);
Map<String, String> systemFragManifest3 = new HashMap<String, String>();
systemFragManifest3.put(Constants.BUNDLE_MANIFESTVERSION, "2");
systemFragManifest3.put(Constants.BUNDLE_SYMBOLICNAME, "systemFrag");
systemFragManifest3.put(Constants.BUNDLE_VERSION, "3.0");
systemFragManifest3.put(Constants.FRAGMENT_HOST, Constants.SYSTEM_BUNDLE_SYMBOLICNAME);
Module systemFrag3 = installDummyModule(systemFragManifest3, "systemFrag3", container);
report = container.resolve(Arrays.asList(systemFrag2), true);
Assert.assertNotNull("Expected failure message", report.getResolutionException());
report = container.resolve(Arrays.asList(systemFrag3), true);
Assert.assertNotNull("Expected failure message", report.getResolutionException());
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);
// uninstall the fragments so we can start over
container.uninstall(systemFrag1);
container.uninstall(systemFrag2);
container.uninstall(systemFrag3);
// refresh the system bundle to get only it resolved
report = container.refresh(Collections.singleton(systemBundle));
Assert.assertNull("Unexpected failure message", report.getResolutionException());
hostWires = systemBundle.getCurrentRevision().getWiring().getProvidedModuleWires(HostNamespace.HOST_NAMESPACE);
assertEquals("Wrong number of fragments.", 0, hostWires.size());
// install the fragments again
systemFrag1 = installDummyModule(systemFragManifest1, "systemFrag1", container);
systemFrag2 = installDummyModule(systemFragManifest2, "systemFrag2", container);
systemFrag3 = installDummyModule(systemFragManifest3, "systemFrag3", container);
report = container.resolve(Arrays.asList(systemFrag1), true);
Assert.assertNotNull("Expected failure message", report.getResolutionException());
report = container.resolve(Arrays.asList(systemFrag2), true);
Assert.assertNotNull("Expected failure message", report.getResolutionException());
report = container.resolve(Arrays.asList(systemFrag3), true);
Assert.assertNull("Unexpected failure message", report.getResolutionException());
hostWires = systemBundle.getCurrentRevision().getWiring().getProvidedModuleWires(HostNamespace.HOST_NAMESPACE);
List<ModuleWire> systemFrag3HostWires = systemFrag3.getCurrentRevision().getWiring().getRequiredModuleWires(HostNamespace.HOST_NAMESPACE);
assertWires(systemFrag3HostWires, hostWires);
}
use of org.eclipse.osgi.container.ModuleWire in project rt.equinox.framework by eclipse.
the class TestModuleContainer method testSystemBundleFragmentsPackageImport.
@Test
public void testSystemBundleFragmentsPackageImport() throws BundleException, IOException {
// install the system.bundle
Module systemBundle = createContainerWithSystemBundle(true);
ModuleContainer container = systemBundle.getContainer();
// install an system.bundle fragment that imports framework package
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, Constants.SYSTEM_BUNDLE_SYMBOLICNAME);
systemFragManifest.put(Constants.IMPORT_PACKAGE, "org.osgi.framework");
Module systemFrag = installDummyModule(systemFragManifest, "systemFrag", container);
ResolutionReport report = container.resolve(Arrays.asList(systemFrag), 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.", 1, hostWires.size());
Assert.assertEquals("Unexpected fragment revision: " + hostWires, systemFrag.getCurrentRevision(), hostWires.get(0).getRequirer());
List<ModuleWire> systemBundleRequiredWires = systemBundle.getCurrentRevision().getWiring().getRequiredModuleWires(null);
assertEquals("No required wires expected.", 0, systemBundleRequiredWires.size());
}
use of org.eclipse.osgi.container.ModuleWire in project rt.equinox.framework by eclipse.
the class TestModuleContainer method testUses1Dynamic.
@Test
public void testUses1Dynamic() throws BundleException, IOException {
DummyContainerAdaptor adaptor = createDummyAdaptor(new DummyDebugOptions(Collections.singletonMap("org.eclipse.osgi/resolver/report", "true")));
ModuleContainer container = adaptor.getContainer();
Module systemBundle = installDummyModule("system.bundle.MF", Constants.SYSTEM_BUNDLE_LOCATION, container);
container.resolve(Arrays.asList(systemBundle), true);
Module uses_a = installDummyModule("uses.a.MF", "a", container);
Module uses_b = installDummyModule("uses.b.MF", "b", container);
Module uses_c_dynamic = installDummyModule("uses.c.dynamic.MF", "c", container);
container.resolve(null, false);
Assert.assertEquals("a should resolve.", State.RESOLVED, uses_a.getState());
Assert.assertEquals("b should resolve.", State.RESOLVED, uses_b.getState());
Assert.assertEquals("c should resolve.", State.RESOLVED, uses_c_dynamic.getState());
ModuleWire dynamicWire = container.resolveDynamic("uses1", uses_c_dynamic.getCurrentRevision());
Assert.assertNotNull("No dynamic wire.", dynamicWire);
PrintStream originalOut = Debug.out;
ByteArrayOutputStream bytesOut = new ByteArrayOutputStream();
PrintStream testOut = new PrintStream(bytesOut);
Debug.out = testOut;
try {
dynamicWire = container.resolveDynamic("uses2", uses_c_dynamic.getCurrentRevision());
Assert.assertNull("Dynamic wire found.", dynamicWire);
} finally {
Debug.out = originalOut;
testOut.close();
}
String traceOutput = bytesOut.toString();
Assert.assertTrue("Wrong traceOutput: " + traceOutput, traceOutput.startsWith("org.osgi.service.resolver.ResolutionException"));
}
use of org.eclipse.osgi.container.ModuleWire in project rt.equinox.framework by eclipse.
the class TestModuleContainer method testBug457118.
@Test
public void testBug457118() 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 e = installDummyModule("bug457118.e.MF", "e", container);
Module a = installDummyModule("bug457118.a.MF", "a", container);
Module b = installDummyModule("bug457118.b.MF", "b", container);
Module c = installDummyModule("bug457118.c.MF", "c", container);
Module d = installDummyModule("bug457118.d.MF", "d", container);
installDummyModule("bug457118.a2.MF", "a2", container);
installDummyModule("bug457118.b2.MF", "b2", container);
installDummyModule("bug457118.c2.MF", "c2", container);
installDummyModule("bug457118.d2.MF", "d2", container);
container.resolve(null, true);
Assert.assertEquals("e should resolve.", State.RESOLVED, e.getState());
Assert.assertEquals("a should resolve.", State.RESOLVED, a.getState());
Assert.assertEquals("b should resolve.", State.RESOLVED, b.getState());
Assert.assertEquals("c should resolve.", State.RESOLVED, c.getState());
Assert.assertEquals("d should resolve.", State.RESOLVED, d.getState());
List<ModuleWire> bundleWires = e.getCurrentRevision().getWiring().getRequiredModuleWires(BundleNamespace.BUNDLE_NAMESPACE);
Assert.assertEquals("Wrong number of bundle wires: " + bundleWires, 1, bundleWires.size());
Assert.assertEquals("Wrong bundle provider", a.getCurrentRevision(), bundleWires.get(0).getProvider());
}
use of org.eclipse.osgi.container.ModuleWire in project rt.equinox.framework by eclipse.
the class TestModuleContainer method testSystemBundleFragmentsNonPayloadRequirements.
@Test
public void testSystemBundleFragmentsNonPayloadRequirements() throws BundleException, IOException {
// install the system.bundle
Module systemBundle = createContainerWithSystemBundle(true);
ModuleContainer container = systemBundle.getContainer();
// install an system.bundle fragment that imports framework package
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, Constants.SYSTEM_BUNDLE_SYMBOLICNAME);
systemFragManifest.put(Constants.REQUIRE_CAPABILITY, "osgi.ee; filter:=\"(osgi.ee=JavaSE)\"");
Module systemFrag = installDummyModule(systemFragManifest, "systemFrag", container);
ResolutionReport report = container.resolve(Arrays.asList(systemFrag), 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.", 1, hostWires.size());
Assert.assertEquals("Unexpected fragment revision: " + hostWires, systemFrag.getCurrentRevision(), hostWires.get(0).getRequirer());
List<ModuleWire> systemBundleRequiredWires = systemBundle.getCurrentRevision().getWiring().getRequiredModuleWires(null);
assertEquals("No required wires expected.", 0, systemBundleRequiredWires.size());
List<ModuleWire> fragRequiredWires = systemFrag.getCurrentRevision().getWiring().getRequiredModuleWires(null);
assertEquals("Wrong number of required wires.", 2, fragRequiredWires.size());
assertWires(fragRequiredWires, systemBundle.getCurrentRevision().getWiring().getProvidedModuleWires(null));
}
Aggregations