use of org.osgi.framework.wiring.BundleCapability in project rt.equinox.framework by eclipse.
the class ImportJavaSEPackagesTests method doSystemPackages.
public void doSystemPackages(int rv, int expectedPackages) throws Exception {
if (rv < 9) {
System.setProperty("java.specification.version", "1." + rv);
} else {
System.setProperty("java.specification.version", Integer.toString(rv));
}
File config = OSGiTestsActivator.getContext().getDataFile(getName());
Map<String, String> headers = new HashMap<String, String>();
headers.put(Constants.BUNDLE_MANIFESTVERSION, "2");
headers.put(Constants.BUNDLE_SYMBOLICNAME, getName());
config.mkdirs();
File bundle = SystemBundleTests.createBundle(config, getName(), headers);
Equinox equinox = new Equinox(Collections.singletonMap(Constants.FRAMEWORK_STORAGE, config.getAbsolutePath()));
try {
equinox.start();
BundleContext systemContext = equinox.getBundleContext();
Dictionary<String, String> testHeaders = equinox.getHeaders();
assertTrue(Constants.EXPORT_PACKAGE + " does not contain the java.* package", testHeaders.get(Constants.EXPORT_PACKAGE).contains(JAVA_LANG));
assertTrue(Constants.EXPORT_PACKAGE + " does not contain the java.* package", testHeaders.get(Constants.EXPORT_PACKAGE).contains(JAVA_UTIL));
List<BundleCapability> capabilities = equinox.adapt(BundleWiring.class).getCapabilities(PackageNamespace.PACKAGE_NAMESPACE);
int count = 0;
for (BundleCapability cap : capabilities) {
if (cap.getAttributes().get(PackageNamespace.PACKAGE_NAMESPACE).toString().startsWith("java.")) {
count++;
}
}
assertEquals("Wrong number of java.* packages for version " + rv, expectedPackages, count);
Bundle testBundle = systemContext.installBundle(bundle.toURI().toString());
testBundle.start();
String systemPackages = testBundle.getBundleContext().getProperty(Constants.FRAMEWORK_SYSTEMPACKAGES);
assertTrue("System packages should include java.* packages", systemPackages.contains(JAVA_LANG));
assertTrue("System packages should include java.* packages", systemPackages.contains(JAVA_UTIL));
} catch (BundleException e) {
fail("Failed to test System packages");
} finally {
try {
equinox.stop();
equinox.waitForStop(10000);
} catch (Exception e) {
// do nothing
}
}
}
use of org.osgi.framework.wiring.BundleCapability in project aries by apache.
the class BundleWiringData method getCapabilitiesCompositeData.
public static CompositeData[] getCapabilitiesCompositeData(List<BundleCapability> bundleCapabilities) {
try {
CompositeData[] data = new CompositeData[bundleCapabilities.size()];
for (int i = 0; i < bundleCapabilities.size(); i++) {
BundleCapability requirement = bundleCapabilities.get(i);
CompositeData cd = BundleWiringData.getCapReqCompositeData(BundleWiringStateMBean.BUNDLE_CAPABILITY_TYPE, requirement.getNamespace(), requirement.getAttributes().entrySet(), requirement.getDirectives().entrySet());
data[i] = cd;
}
return data;
} catch (OpenDataException e) {
throw new IllegalStateException("Can't create CompositeData", e);
}
}
use of org.osgi.framework.wiring.BundleCapability in project aries by apache.
the class BundleWiringData method getCapabilities.
private static CompositeData[] getCapabilities(List<BundleCapability> capabilityList) throws OpenDataException {
CompositeData[] capData = new CompositeData[capabilityList.size()];
for (int i = 0; i < capabilityList.size(); i++) {
BundleCapability capability = capabilityList.get(i);
capData[i] = getCapReqCompositeData(BundleWiringStateMBean.BUNDLE_CAPABILITY_TYPE, capability.getNamespace(), capability.getAttributes().entrySet(), capability.getDirectives().entrySet());
}
return capData;
}
use of org.osgi.framework.wiring.BundleCapability in project aries by apache.
the class BundleWiringData method getWiresCompositeData.
private CompositeData[] getWiresCompositeData(List<BundleWire> wires) throws OpenDataException {
CompositeData[] reqWiresData = new CompositeData[wires.size()];
for (int i = 0; i < wires.size(); i++) {
BundleWire requiredWire = wires.get(i);
Map<String, Object> wireItems = new HashMap<String, Object>();
BundleCapability capability = requiredWire.getCapability();
wireItems.put(BundleWiringStateMBean.PROVIDER_BUNDLE_ID, capability.getRevision().getBundle().getBundleId());
wireItems.put(BundleWiringStateMBean.PROVIDER_BUNDLE_REVISION_ID, revisionIDMap.get(capability.getRevision()));
wireItems.put(BundleWiringStateMBean.BUNDLE_CAPABILITY, getCapReqCompositeData(BundleWiringStateMBean.BUNDLE_CAPABILITY_TYPE, capability.getNamespace(), capability.getAttributes().entrySet(), capability.getDirectives().entrySet()));
BundleRequirement requirement = requiredWire.getRequirement();
wireItems.put(BundleWiringStateMBean.REQUIRER_BUNDLE_ID, requirement.getRevision().getBundle().getBundleId());
wireItems.put(BundleWiringStateMBean.REQUIRER_BUNDLE_REVISION_ID, revisionIDMap.get(requirement.getRevision()));
wireItems.put(BundleWiringStateMBean.BUNDLE_REQUIREMENT, getCapReqCompositeData(BundleWiringStateMBean.BUNDLE_REQUIREMENT_TYPE, requirement.getNamespace(), requirement.getAttributes().entrySet(), requirement.getDirectives().entrySet()));
CompositeData wireData = new CompositeDataSupport(BundleWiringStateMBean.BUNDLE_WIRE_TYPE, wireItems);
reqWiresData[i] = wireData;
}
return reqWiresData;
}
use of org.osgi.framework.wiring.BundleCapability in project aries by apache.
the class BundleWiringStateMBeanTest method testGetCurrentRevisionDeclaredCapabilities.
@Test
public void testGetCurrentRevisionDeclaredCapabilities() throws Exception {
BundleRevision br = (BundleRevision) bundleA.adapt(BundleRevision.class);
List<BundleCapability> capabilities = br.getDeclaredCapabilities(BundleRevision.PACKAGE_NAMESPACE);
CompositeData[] jmxCapabilities = brsMBean.getCurrentRevisionDeclaredCapabilities(bundleA.getBundleId(), BundleRevision.PACKAGE_NAMESPACE);
Assert.assertEquals(capabilities.size(), jmxCapabilities.length);
Map<Map<String, Object>, Map<String, String>> expectedCapabilities = capabilitiesToMap(capabilities);
Map<Map<String, Object>, Map<String, String>> actualCapabilities = jmxCapReqToMap(jmxCapabilities);
Assert.assertEquals(expectedCapabilities, actualCapabilities);
}
Aggregations