Search in sources :

Example 1 with BundleRevisions

use of org.osgi.framework.wiring.BundleRevisions in project karaf by apache.

the class BundleInfoImpl method populateFragementInfos.

private void populateFragementInfos(Bundle bundle) {
    this.isFragment = bundle.getHeaders().get(Constants.FRAGMENT_HOST) != null;
    this.fragments = new ArrayList<>();
    this.fragmentHosts = new ArrayList<>();
    BundleRevisions revisions = bundle.adapt(BundleRevisions.class);
    if (revisions == null) {
        return;
    }
    for (BundleRevision revision : revisions.getRevisions()) {
        if (revision.getWiring() != null) {
            getFragments(revision);
            getFragmentHosts(revision);
        }
    }
}
Also used : BundleRevision(org.osgi.framework.wiring.BundleRevision) BundleRevisions(org.osgi.framework.wiring.BundleRevisions)

Example 2 with BundleRevisions

use of org.osgi.framework.wiring.BundleRevisions in project felix by apache.

the class DTOFactory method createBundleRevisionDTOArray.

private static BundleRevisionDTO[] createBundleRevisionDTOArray(Bundle bundle) {
    BundleRevisions brs = bundle.adapt(BundleRevisions.class);
    if (brs == null || brs.getRevisions() == null)
        return null;
    List<BundleRevision> revisions = brs.getRevisions();
    BundleRevisionDTO[] dtos = new BundleRevisionDTO[revisions.size()];
    for (int i = 0; i < revisions.size(); i++) {
        if (revisions.get(i) instanceof BundleRevisionImpl)
            dtos[i] = createBundleRevisionDTO(bundle, (BundleRevisionImpl) revisions.get(i), new HashSet<BundleRevisionDTO>());
    }
    return dtos;
}
Also used : BundleRevisionDTO(org.osgi.framework.wiring.dto.BundleRevisionDTO) BundleRevision(org.osgi.framework.wiring.BundleRevision) BundleRevisions(org.osgi.framework.wiring.BundleRevisions)

Example 3 with BundleRevisions

use of org.osgi.framework.wiring.BundleRevisions in project aries by apache.

the class FrameworkMBeanTest method testRefreshBundlesAndWait.

@Test
public void testRefreshBundlesAndWait() 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, bundleB.adapt(BundleWiring.class));
    FrameworkMBean framework = getMBean(FrameworkMBean.OBJECTNAME, FrameworkMBean.class);
    CompositeData result = framework.refreshBundlesAndWait(new long[] { bundleB.getBundleId() });
    assertTrue((Boolean) result.get(FrameworkMBean.SUCCESS));
    assertTrue(Arrays.equals(new Long[] { bundleB.getBundleId() }, (Long[]) result.get(FrameworkMBean.COMPLETED)));
    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);
}
Also used : Bundle(org.osgi.framework.Bundle) BundleWiring(org.osgi.framework.wiring.BundleWiring) CompositeData(javax.management.openmbean.CompositeData) ArrayList(java.util.ArrayList) JarOutputStream(java.util.jar.JarOutputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Manifest(java.util.jar.Manifest) FrameworkMBean(org.osgi.jmx.framework.FrameworkMBean) BundleWire(org.osgi.framework.wiring.BundleWire) Version(org.osgi.framework.Version) ByteArrayInputStream(java.io.ByteArrayInputStream) BundleRevisions(org.osgi.framework.wiring.BundleRevisions) Test(org.junit.Test) AbstractIntegrationTest(org.apache.aries.jmx.AbstractIntegrationTest)

Example 4 with BundleRevisions

use of org.osgi.framework.wiring.BundleRevisions in project aries by apache.

the class BundleWiringState method getRevisionsDeclaredCapabilities.

/* (non-Javadoc)
     * @see org.osgi.jmx.framework.BundleRevisionsStateMBean#getRevisionsDeclaredCapabilities(long, java.lang.String, boolean)
     */
public TabularData getRevisionsDeclaredCapabilities(long bundleId, String namespace) throws IOException {
    Bundle bundle = FrameworkUtils.resolveBundle(bundleContext, bundleId);
    BundleRevisions revisions = bundle.adapt(BundleRevisions.class);
    TabularData td = new TabularDataSupport(BundleWiringStateMBean.REVISIONS_CAPABILITIES_TYPE);
    for (BundleRevision revision : revisions.getRevisions()) {
        td.put(BundleWiringData.getRevisionCapabilities(System.identityHashCode(revision), revision.getDeclaredCapabilities(namespace)));
    }
    return td;
}
Also used : Bundle(org.osgi.framework.Bundle) TabularDataSupport(javax.management.openmbean.TabularDataSupport) BundleRevision(org.osgi.framework.wiring.BundleRevision) BundleRevisions(org.osgi.framework.wiring.BundleRevisions) TabularData(javax.management.openmbean.TabularData)

Example 5 with BundleRevisions

use of org.osgi.framework.wiring.BundleRevisions in project karaf by apache.

the class BundleInfoImpl method populateRevisions.

private String populateRevisions(Bundle bundle) {
    String ret = "";
    BundleRevisions revisions = bundle.adapt(BundleRevisions.class);
    if (revisions == null) {
        return ret;
    }
    for (BundleRevision revision : revisions.getRevisions()) {
        ret = ret + "[" + revision + "]" + " ";
    }
    return ret;
}
Also used : BundleRevision(org.osgi.framework.wiring.BundleRevision) BundleRevisions(org.osgi.framework.wiring.BundleRevisions)

Aggregations

BundleRevisions (org.osgi.framework.wiring.BundleRevisions)14 BundleRevision (org.osgi.framework.wiring.BundleRevision)11 Bundle (org.osgi.framework.Bundle)8 TabularData (javax.management.openmbean.TabularData)6 AbstractIntegrationTest (org.apache.aries.jmx.AbstractIntegrationTest)5 Test (org.junit.Test)5 BundleWiring (org.osgi.framework.wiring.BundleWiring)5 CompositeData (javax.management.openmbean.CompositeData)4 TabularDataSupport (javax.management.openmbean.TabularDataSupport)4 BundleWire (org.osgi.framework.wiring.BundleWire)4 ByteArrayInputStream (java.io.ByteArrayInputStream)3 ByteArrayOutputStream (java.io.ByteArrayOutputStream)3 ArrayList (java.util.ArrayList)3 HashMap (java.util.HashMap)3 Map (java.util.Map)3 JarOutputStream (java.util.jar.JarOutputStream)3 Manifest (java.util.jar.Manifest)3 Version (org.osgi.framework.Version)3 FrameworkMBean (org.osgi.jmx.framework.FrameworkMBean)2 HashSet (java.util.HashSet)1