use of org.eclipse.osgi.container.ModuleRevision in project rt.equinox.framework by eclipse.
the class NativeCodeBundleTests method setNativeAttribute.
private void setNativeAttribute(String key, String value) {
Bundle systemBundle = OSGiTestsActivator.getContext().getBundle(0);
ModuleRevision systemRevision = (ModuleRevision) systemBundle.adapt(BundleRevision.class);
ModuleCapability nativeCapability = systemRevision.getModuleCapabilities(NativeNamespace.NATIVE_NAMESPACE).get(0);
Map attrs = new HashMap(nativeCapability.getAttributes());
attrs.put(key, value);
nativeCapability.setTransientAttrs(attrs);
}
use of org.eclipse.osgi.container.ModuleRevision 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.ModuleRevision 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.ModuleRevision 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.ModuleRevision in project rt.equinox.framework by eclipse.
the class TestModuleContainer method testFragments01.
@Test
public void testFragments01() throws BundleException, IOException {
DummyContainerAdaptor adaptor = createDummyAdaptor();
ModuleContainer container = adaptor.getContainer();
Module systemModule = installDummyModule("system.bundle.MF", Constants.SYSTEM_BUNDLE_LOCATION, container);
Module c1 = installDummyModule("c1_v1.MF", "c1_v1", container);
Module h2 = installDummyModule("h2_v1.MF", "h2_v1", container);
Module f2 = installDummyModule("f2_v1.MF", "f2_v1", container);
container.resolve(Arrays.asList(systemModule, c1, h2, f2), true);
ModuleWiring wiring = h2.getCurrentRevision().getWiring();
List<ModuleWire> requiredWires = wiring.getRequiredModuleWires(null);
Assert.assertEquals("Wrong number of required wires.", 3, requiredWires.size());
for (ModuleWire wire : requiredWires) {
ModuleCapability capability = wire.getCapability();
Assert.assertEquals("Wrong namespace.", PackageNamespace.PACKAGE_NAMESPACE, capability.getNamespace());
Assert.assertEquals("Wrong requirer.", h2.getCurrentRevision(), wire.getRequirer());
String pkgName = (String) capability.getAttributes().get(PackageNamespace.PACKAGE_NAMESPACE);
Assert.assertNotNull("No package name.", pkgName);
ModuleRevision expectedReqRevision;
if (pkgName.equals("org.osgi.framework")) {
expectedReqRevision = h2.getCurrentRevision();
} else {
expectedReqRevision = f2.getCurrentRevision();
}
Assert.assertEquals("Wrong requirement revision.", expectedReqRevision, wire.getRequirement().getRevision());
}
}
Aggregations