use of org.eclipse.osgi.container.Module in project rt.equinox.framework by eclipse.
the class TestModuleContainer method createContainerWithSystemBundle.
private Module createContainerWithSystemBundle(boolean resolveSystemBundle) throws BundleException, IOException {
DummyContainerAdaptor adaptor = createDummyAdaptor();
ModuleContainer container = adaptor.getContainer();
// install the system.bundle
String systemCapability = "osgi.ee; osgi.ee=\"JavaSE\"; version:List<Version>=\"1.0, 1.1, 1.2, 1.3, 1.4, 1.5, 1.6\", equinox.test; equinox.test=system, osgi.native; osgi.native.osname=test";
Module systemBundle = installDummyModule("system.bundle.MF", Constants.SYSTEM_BUNDLE_LOCATION, Constants.SYSTEM_BUNDLE_SYMBOLICNAME, null, systemCapability, container);
if (resolveSystemBundle) {
ResolutionReport report = container.resolve(Collections.singleton(systemBundle), true);
Assert.assertNull("Found resolution exception.", report.getResolutionException());
Assert.assertEquals("System is not resolved.", State.RESOLVED, systemBundle.getState());
}
return systemBundle;
}
use of org.eclipse.osgi.container.Module in project rt.equinox.framework by eclipse.
the class TestModuleContainer method testCompatReprovide.
@Test
public void testCompatReprovide() throws BundleException, IOException {
DummyContainerAdaptor adaptor = createDummyAdaptor();
ModuleContainer container = adaptor.getContainer();
Module b1 = installDummyModule("compatReprovide1.MF", "b1", container);
Module b2 = installDummyModule("compatReprovide2.MF", "b2", container);
Module b3 = installDummyModule("compatReprovide3.MF", "b3", container);
String b1Visibility = b1.getCurrentRevision().getRequirements(BundleNamespace.BUNDLE_NAMESPACE).iterator().next().getDirectives().get(BundleNamespace.REQUIREMENT_VISIBILITY_DIRECTIVE);
String b2Visibility = b2.getCurrentRevision().getRequirements(BundleNamespace.BUNDLE_NAMESPACE).iterator().next().getDirectives().get(BundleNamespace.REQUIREMENT_VISIBILITY_DIRECTIVE);
String b3Visibility = b3.getCurrentRevision().getRequirements(BundleNamespace.BUNDLE_NAMESPACE).iterator().next().getDirectives().get(BundleNamespace.REQUIREMENT_VISIBILITY_DIRECTIVE);
Assert.assertEquals("Wrong visibility directive: " + b1, BundleNamespace.VISIBILITY_REEXPORT, b1Visibility);
Assert.assertNull("Wrong visibility directive: ", b2Visibility);
Assert.assertEquals("Wrong visibility directive: " + b2, BundleNamespace.VISIBILITY_REEXPORT, b3Visibility);
}
use of org.eclipse.osgi.container.Module in project rt.equinox.framework by eclipse.
the class TestModuleContainer method testUses4.
/*
* Test that fragments and uses constraints
*/
@Test
public void testUses4() 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 uses_h = installDummyModule("uses.h.MF", "h", container);
Module uses_h_frag = installDummyModule("uses.h.frag.MF", "h.frag", container);
container.resolve(null, false);
Assert.assertEquals("h should resolve.", State.RESOLVED, uses_h.getState());
Assert.assertEquals("h.frag should resolve.", State.RESOLVED, uses_h_frag.getState());
Module uses_i = installDummyModule("uses.i.MF", "i", container);
Module uses_j = installDummyModule("uses.j.MF", "j", container);
container.resolve(null, false);
Assert.assertEquals("i should resolve.", State.RESOLVED, uses_i.getState());
Assert.assertEquals("j should resolve.", State.RESOLVED, uses_j.getState());
List<BundleWire> requiredWires = uses_j.getCurrentRevision().getWiring().getRequiredWires(null);
Assert.assertEquals("Wrong number of wires for j", 2, requiredWires.size());
for (BundleWire wire : requiredWires) {
Assert.assertEquals("Wrong provider", uses_i.getCurrentRevision(), wire.getProvider());
}
Module uses_j_dynamic = installDummyModule("uses.j.dynamic.MF", "j.dynamic", container);
container.resolve(null, false);
ModuleWire dynamicWire = container.resolveDynamic("uses2", uses_j_dynamic.getCurrentRevision());
Assert.assertNotNull("Null dynamic wire.", dynamicWire);
Assert.assertEquals("Wrong provider", uses_i.getCurrentRevision(), dynamicWire.getProvider());
}
use of org.eclipse.osgi.container.Module in project rt.equinox.framework by eclipse.
the class TestModuleContainer method testCompatSingleton.
@Test
public void testCompatSingleton() throws BundleException, IOException {
DummyContainerAdaptor adaptor = createDummyAdaptor();
ModuleContainer container = adaptor.getContainer();
Module s1 = installDummyModule("compatSingleton1.MF", "s1", container);
Module s2 = installDummyModule("compatSingleton2.MF", "s2", container);
Module s3 = installDummyModule("compatSingleton3.MF", "s3", container);
String s1Singleton = s1.getCurrentRevision().getCapabilities(IdentityNamespace.IDENTITY_NAMESPACE).iterator().next().getDirectives().get(IdentityNamespace.CAPABILITY_SINGLETON_DIRECTIVE);
String s2Singleton = s2.getCurrentRevision().getCapabilities(IdentityNamespace.IDENTITY_NAMESPACE).iterator().next().getDirectives().get(IdentityNamespace.CAPABILITY_SINGLETON_DIRECTIVE);
String s3Singleton = s3.getCurrentRevision().getCapabilities(IdentityNamespace.IDENTITY_NAMESPACE).iterator().next().getDirectives().get(IdentityNamespace.CAPABILITY_SINGLETON_DIRECTIVE);
Assert.assertEquals("Wrong singleton directive: " + s1, "true", s1Singleton);
Assert.assertNull("Wrong singleton directive: " + s2, s2Singleton);
Assert.assertEquals("Wrong singleton directive: " + s3, "true", s3Singleton);
}
use of org.eclipse.osgi.container.Module in project rt.equinox.framework by eclipse.
the class TestModuleContainer method testSystemBundleFragmentRequiresOtherFragmentFailResolution.
@Test
public void testSystemBundleFragmentRequiresOtherFragmentFailResolution() throws BundleException, IOException {
// install the system.bundle
Module systemBundle = createContainerWithSystemBundle(true);
ModuleContainer container = systemBundle.getContainer();
// install an system.bundle fragment that provides a capability
Map<String, String> systemFragManifest1 = new HashMap<String, String>();
systemFragManifest1.put(Constants.BUNDLE_MANIFESTVERSION, "2");
systemFragManifest1.put(Constants.BUNDLE_SYMBOLICNAME, "systemFrag1");
systemFragManifest1.put(Constants.FRAGMENT_HOST, Constants.SYSTEM_BUNDLE_SYMBOLICNAME);
systemFragManifest1.put(Constants.PROVIDE_CAPABILITY, "fragment.capability; fragment.capability=test1");
Module systemFrag1 = installDummyModule(systemFragManifest1, "systemFrag1", container);
// install an system.bundle fragment that requires a fragment capability, but fails to match
Map<String, String> systemFragManifest2 = new HashMap<String, String>();
systemFragManifest2.put(Constants.BUNDLE_MANIFESTVERSION, "2");
systemFragManifest2.put(Constants.BUNDLE_SYMBOLICNAME, "systemFrag2");
systemFragManifest2.put(Constants.FRAGMENT_HOST, Constants.SYSTEM_BUNDLE_SYMBOLICNAME);
systemFragManifest2.put(Constants.REQUIRE_CAPABILITY, "fragment.capability; filter:=\"(fragment.capability=test4)\"");
systemFragManifest2.put(Constants.PROVIDE_CAPABILITY, "fragment.capability; fragment.capability=test2");
Module systemFrag2 = installDummyModule(systemFragManifest2, "systemFrag2", container);
// install an system.bundle fragment that requires a fragment capability from a fragment that fails to resolve
Map<String, String> systemFragManifest3 = new HashMap<String, String>();
systemFragManifest3.put(Constants.BUNDLE_MANIFESTVERSION, "2");
systemFragManifest3.put(Constants.BUNDLE_SYMBOLICNAME, "systemFrag3");
systemFragManifest3.put(Constants.FRAGMENT_HOST, Constants.SYSTEM_BUNDLE_SYMBOLICNAME);
systemFragManifest3.put(Constants.REQUIRE_CAPABILITY, "fragment.capability; filter:=\"(fragment.capability=test2)\"");
systemFragManifest3.put(Constants.PROVIDE_CAPABILITY, "fragment.capability; fragment.capability=test3");
Module systemFrag3 = installDummyModule(systemFragManifest3, "systemFrag3", container);
ResolutionReport report = container.resolve(Arrays.asList(systemFrag3), true);
Assert.assertNotNull("Expected 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);
// install a bundle that can satisfy the failed requirement, but it should not be allowed since it is not a fragment
Map<String, String> provideCapabilityManifest1 = new HashMap<String, String>();
provideCapabilityManifest1.put(Constants.BUNDLE_MANIFESTVERSION, "2");
provideCapabilityManifest1.put(Constants.BUNDLE_SYMBOLICNAME, "provideCapabilityBundle1");
provideCapabilityManifest1.put(Constants.PROVIDE_CAPABILITY, "fragment.capability; fragment.capability=test4");
installDummyModule(provideCapabilityManifest1, "provideCapabilityBundle1", container);
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);
// install a fragment that satisfies the failed requirement
Map<String, String> systemFragManifest4 = new HashMap<String, String>();
systemFragManifest4.put(Constants.BUNDLE_MANIFESTVERSION, "2");
systemFragManifest4.put(Constants.BUNDLE_SYMBOLICNAME, "systemFrag4");
systemFragManifest4.put(Constants.FRAGMENT_HOST, Constants.SYSTEM_BUNDLE_SYMBOLICNAME);
systemFragManifest4.put(Constants.PROVIDE_CAPABILITY, "fragment.capability; fragment.capability=test4");
Module systemFrag4 = installDummyModule(systemFragManifest4, "systemFrag4", container);
report = container.resolve(Arrays.asList(systemFrag3), true);
Assert.assertNull("Failed to resolve.", report.getResolutionException());
hostWires = systemBundle.getCurrentRevision().getWiring().getProvidedModuleWires(HostNamespace.HOST_NAMESPACE);
assertEquals("Wrong number of fragments.", 4, hostWires.size());
systemFrag1HostWires = systemFrag1.getCurrentRevision().getWiring().getRequiredModuleWires(HostNamespace.HOST_NAMESPACE);
List<ModuleWire> systemFrag2HostWires = systemFrag2.getCurrentRevision().getWiring().getRequiredModuleWires(HostNamespace.HOST_NAMESPACE);
List<ModuleWire> systemFrag3HostWires = systemFrag3.getCurrentRevision().getWiring().getRequiredModuleWires(HostNamespace.HOST_NAMESPACE);
List<ModuleWire> systemFrag4HostWires = systemFrag4.getCurrentRevision().getWiring().getRequiredModuleWires(HostNamespace.HOST_NAMESPACE);
assertWires(systemFrag1HostWires, hostWires);
assertWires(systemFrag2HostWires, hostWires);
assertWires(systemFrag3HostWires, hostWires);
assertWires(systemFrag4HostWires, hostWires);
List<ModuleCapability> fragmentCapabilities = systemBundle.getCurrentRevision().getWiring().getModuleCapabilities("fragment.capability");
assertEquals("Wrong number of fragment capabilities.", 4, fragmentCapabilities.size());
// Use set since the order of required and provided wires will be different
Set<ModuleWire> hostRequiredFragmentCapWires = new HashSet<ModuleWire>(systemBundle.getCurrentRevision().getWiring().getRequiredModuleWires("fragment.capability"));
Set<ModuleWire> hostProvidedFragmentCapWires = new HashSet<ModuleWire>(systemBundle.getCurrentRevision().getWiring().getProvidedModuleWires("fragment.capability"));
assertEquals("Wrong number of wires.", 2, hostProvidedFragmentCapWires.size());
assertEquals("Wrong wires found from host.", hostRequiredFragmentCapWires, hostProvidedFragmentCapWires);
}
Aggregations