use of org.osgi.framework.wiring.BundleRevisions in project aries by apache.
the class BundleWiringStateMBeanTest method testGetRevisionsDeclaredCapabilities.
@Test
public void testGetRevisionsDeclaredCapabilities() throws Exception {
BundleRevisions revisions = (BundleRevisions) bundleA.adapt(BundleRevisions.class);
Assert.assertEquals("Precondition", 1, revisions.getRevisions().size());
TabularData jmxCapabilitiesTable = brsMBean.getRevisionsDeclaredCapabilities(bundleA.getBundleId(), BundleRevision.PACKAGE_NAMESPACE);
Assert.assertEquals(1, jmxCapabilitiesTable.size());
List<BundleCapability> capabilities = ((BundleRevision) revisions.getRevisions().iterator().next()).getDeclaredCapabilities(BundleRevision.PACKAGE_NAMESPACE);
CompositeData jmxRevCapabilities = (CompositeData) jmxCapabilitiesTable.values().iterator().next();
CompositeData[] jmxCapabilities = (CompositeData[]) jmxRevCapabilities.get(BundleWiringStateMBean.CAPABILITIES);
Map<Map<String, Object>, Map<String, String>> expectedCapabilities = capabilitiesToMap(capabilities);
Map<Map<String, Object>, Map<String, String>> actualCapabilities = jmxCapReqToMap(jmxCapabilities);
Assert.assertEquals(expectedCapabilities, actualCapabilities);
}
use of org.osgi.framework.wiring.BundleRevisions in project aries by apache.
the class FrameworkMBeanTest method testRefreshBundleAndWait.
@Test
public void testRefreshBundleAndWait() throws Exception {
FrameworkWiring frameworkWiring = (FrameworkWiring) context().getBundle(0).adapt(FrameworkWiring.class);
Bundle bundleA = getBundleByName("org.apache.aries.jmx.test.bundlea");
Bundle bundleB = getBundleByName("org.apache.aries.jmx.test.bundleb");
BundleWiring bw = (BundleWiring) bundleB.adapt(BundleWiring.class);
List<BundleWire> initialRequiredWires = bw.getRequiredWires(BundleRevision.PACKAGE_NAMESPACE);
assertEquals(1, initialRequiredWires.size());
BundleWire wire = initialRequiredWires.get(0);
Map<String, Object> capabilityAttributes = wire.getCapability().getAttributes();
assertEquals("Precondition", bundleA.getSymbolicName(), capabilityAttributes.get(Constants.BUNDLE_SYMBOLICNAME_ATTRIBUTE));
assertEquals("Precondition", new Version("1.0"), capabilityAttributes.get(Constants.BUNDLE_VERSION_ATTRIBUTE));
assertEquals("Precondition", "org.apache.aries.jmx.test.bundlea.api", capabilityAttributes.get(BundleRevision.PACKAGE_NAMESPACE));
// Create an updated version of Bundle A, which an extra export and version 1.1
Manifest manifest = new Manifest();
manifest.getMainAttributes().putValue("Manifest-Version", "1.0");
manifest.getMainAttributes().putValue(Constants.BUNDLE_SYMBOLICNAME, "org.apache.aries.jmx.test.bundlea");
manifest.getMainAttributes().putValue(Constants.BUNDLE_VERSION, "1.1");
manifest.getMainAttributes().putValue(Constants.EXPORT_PACKAGE, "org.apache.aries.jmx.test.bundlea.api,org.apache.aries.jmx.test.bundlea.impl");
ByteArrayOutputStream baos = new ByteArrayOutputStream();
JarOutputStream jos = new JarOutputStream(baos, manifest);
addResourceToJar("org/apache/aries/jmx/test/bundlea/api/InterfaceA.class", jos, bundleA);
addResourceToJar("org/apache/aries/jmx/test/bundlea/impl/A2.class", jos, bundleA);
jos.close();
assertEquals("Precondition", 0, frameworkWiring.getRemovalPendingBundles().size());
assertEquals(0, framework.getRemovalPendingBundles().length);
assertEquals("Precondition", 1, ((BundleRevisions) bundleA.adapt(BundleRevisions.class)).getRevisions().size());
bundleA.update(new ByteArrayInputStream(baos.toByteArray()));
assertEquals("There should be 2 revisions now", 2, ((BundleRevisions) bundleA.adapt(BundleRevisions.class)).getRevisions().size());
assertEquals("No refresh called, the bundle wiring for B should still be the old one", bw, bundleB.adapt(BundleWiring.class));
assertEquals("Precondition", 1, frameworkWiring.getRemovalPendingBundles().size());
assertEquals(1, framework.getRemovalPendingBundles().length);
assertEquals(((Bundle) frameworkWiring.getRemovalPendingBundles().iterator().next()).getBundleId(), framework.getRemovalPendingBundles()[0]);
assertTrue(framework.refreshBundleAndWait(bundleB.getBundleId()));
List<BundleWire> requiredWires = ((BundleWiring) bundleB.adapt(BundleWiring.class)).getRequiredWires(BundleRevision.PACKAGE_NAMESPACE);
assertEquals(2, requiredWires.size());
List<String> imported = new ArrayList<String>();
for (BundleWire w : requiredWires) {
Map<String, Object> ca = w.getCapability().getAttributes();
assertEquals(bundleA.getSymbolicName(), ca.get(Constants.BUNDLE_SYMBOLICNAME_ATTRIBUTE));
imported.add(ca.get(BundleRevision.PACKAGE_NAMESPACE).toString());
if ("org.apache.aries.jmx.test.bundlea.impl".equals(ca.get(BundleRevision.PACKAGE_NAMESPACE))) {
// Came across an issue where equinox was reporting the other package as still coming from from the 1.0 bundle
// not sure if this is a bug or not...
assertEquals(new Version("1.1"), ca.get(Constants.BUNDLE_VERSION_ATTRIBUTE));
}
}
assertEquals(Arrays.asList("org.apache.aries.jmx.test.bundlea.api", "org.apache.aries.jmx.test.bundlea.impl"), imported);
}
use of org.osgi.framework.wiring.BundleRevisions in project aries by apache.
the class FrameworkMBeanTest method testRefreshBundlesAndWait2.
@Test
public void testRefreshBundlesAndWait2() throws Exception {
Bundle bundleA = getBundleByName("org.apache.aries.jmx.test.bundlea");
Bundle bundleB = getBundleByName("org.apache.aries.jmx.test.bundleb");
BundleWiring bw = (BundleWiring) bundleB.adapt(BundleWiring.class);
List<BundleWire> initialRequiredWires = bw.getRequiredWires(BundleRevision.PACKAGE_NAMESPACE);
assertEquals(1, initialRequiredWires.size());
BundleWire wire = initialRequiredWires.get(0);
Map<String, Object> capabilityAttributes = wire.getCapability().getAttributes();
assertEquals("Precondition", bundleA.getSymbolicName(), capabilityAttributes.get(Constants.BUNDLE_SYMBOLICNAME_ATTRIBUTE));
assertEquals("Precondition", new Version("1.0"), capabilityAttributes.get(Constants.BUNDLE_VERSION_ATTRIBUTE));
assertEquals("Precondition", "org.apache.aries.jmx.test.bundlea.api", capabilityAttributes.get(BundleRevision.PACKAGE_NAMESPACE));
// Create an updated version of Bundle A, which an extra export and version 1.1
Manifest manifest = new Manifest();
manifest.getMainAttributes().putValue("Manifest-Version", "1.0");
manifest.getMainAttributes().putValue(Constants.BUNDLE_SYMBOLICNAME, "org.apache.aries.jmx.test.bundlea");
manifest.getMainAttributes().putValue(Constants.BUNDLE_VERSION, "1.1");
manifest.getMainAttributes().putValue(Constants.EXPORT_PACKAGE, "org.apache.aries.jmx.test.bundlea.api,org.apache.aries.jmx.test.bundlea.impl");
ByteArrayOutputStream baos = new ByteArrayOutputStream();
JarOutputStream jos = new JarOutputStream(baos, manifest);
addResourceToJar("org/apache/aries/jmx/test/bundlea/api/InterfaceA.class", jos, bundleA);
addResourceToJar("org/apache/aries/jmx/test/bundlea/impl/A2.class", jos, bundleA);
jos.close();
assertEquals("Precondition", 1, ((BundleRevisions) bundleA.adapt(BundleRevisions.class)).getRevisions().size());
bundleA.update(new ByteArrayInputStream(baos.toByteArray()));
assertEquals("There should be 2 revisions now", 2, ((BundleRevisions) bundleA.adapt(BundleRevisions.class)).getRevisions().size());
assertEquals("No refresh called, the bundle wiring for B should still be the old one", bw, ((BundleWiring) bundleB.adapt(BundleWiring.class)));
FrameworkMBean framework = getMBean(FrameworkMBean.OBJECTNAME, FrameworkMBean.class);
CompositeData result = framework.refreshBundlesAndWait(null);
Set<Long> completed = new HashSet<Long>(Arrays.asList((Long[]) result.get(FrameworkMBean.COMPLETED)));
assertTrue(completed.contains(bundleA.getBundleId()));
assertTrue(completed.contains(bundleB.getBundleId()));
List<BundleWire> requiredWires = ((BundleWiring) bundleB.adapt(BundleWiring.class)).getRequiredWires(BundleRevision.PACKAGE_NAMESPACE);
assertEquals(2, requiredWires.size());
List<String> imported = new ArrayList<String>();
for (BundleWire w : requiredWires) {
Map<String, Object> ca = w.getCapability().getAttributes();
assertEquals(bundleA.getSymbolicName(), ca.get(Constants.BUNDLE_SYMBOLICNAME_ATTRIBUTE));
imported.add(ca.get(BundleRevision.PACKAGE_NAMESPACE).toString());
if ("org.apache.aries.jmx.test.bundlea.impl".equals(ca.get(BundleRevision.PACKAGE_NAMESPACE))) {
// Came across an issue where equinox was reporting the other package as still coming from from the 1.0 bundle
// not sure if this is a bug or not...
assertEquals(new Version("1.1"), ca.get(Constants.BUNDLE_VERSION_ATTRIBUTE));
}
}
assertEquals(Arrays.asList("org.apache.aries.jmx.test.bundlea.api", "org.apache.aries.jmx.test.bundlea.impl"), imported);
}
use of org.osgi.framework.wiring.BundleRevisions in project karaf by apache.
the class BundleInfoImpl method populateRevisions.
private String populateRevisions(Bundle bundle) {
BundleRevisions revisions = bundle.adapt(BundleRevisions.class);
if (revisions == null) {
return "";
}
StringBuilder ret = new StringBuilder();
for (BundleRevision revision : revisions.getRevisions()) {
ret.append("[").append(revision).append("]").append(" ");
}
return ret.toString();
}
Aggregations