Search in sources :

Example 61 with BundleRevision

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

the class Subsystems method populateRootSubsystem.

private void populateRootSubsystem(BasicSubsystem root, Coordination coordination) throws Exception {
    // TODO Begin proof of concept.
    // This is a proof of concept for initializing the relationships between the root subsystem and bundles
    // that already existed in its region. Not sure this will be the final resting place. Plus, there are issues
    // since this does not take into account the possibility of already existing bundles going away or new bundles
    // being installed out of band while this initialization is taking place. Need a bundle event hook for that.
    BundleContext context = Activator.getInstance().getBundleContext().getBundle(org.osgi.framework.Constants.SYSTEM_BUNDLE_LOCATION).getBundleContext();
    for (Bundle bundle : context.getBundles()) {
        BundleRevision revision = bundle.adapt(BundleRevision.class);
        if (revision == null)
            // The bundle has been uninstalled. Do not process.
            continue;
        if (!resourceReferences.getSubsystems(revision).isEmpty())
            continue;
        ResourceInstaller.newInstance(coordination, revision, root).install();
    }
// TODO End proof of concept.
}
Also used : Bundle(org.osgi.framework.Bundle) BundleRevision(org.osgi.framework.wiring.BundleRevision) BundleContext(org.osgi.framework.BundleContext)

Example 62 with BundleRevision

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

the class BundleRevisionResourceTest method testNoModellerServiceCapabilities.

@Test
public void testNoModellerServiceCapabilities() {
    BundleRevision br = createNiceMock(BundleRevision.class);
    expect(br.getCapabilities(anyObject(String.class))).andReturn(Collections.<Capability>emptyList());
    expect(br.getRequirements(anyObject(String.class))).andReturn(Collections.<Requirement>emptyList());
    replay(br);
    BundleRevisionResource brr = new BundleRevisionResource(br);
    assertEquals(0, brr.getCapabilities("osgi.service").size());
}
Also used : BundleRevision(org.osgi.framework.wiring.BundleRevision) Test(org.junit.Test)

Example 63 with BundleRevision

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

the class Aries1417Test method testOsgiImplementation.

@Test
public void testOsgiImplementation() throws Exception {
    Bundle bundle = getSubsystemCoreBundle();
    BundleRevision revision = bundle.adapt(BundleRevision.class);
    List<Capability> capabilities = revision.getCapabilities(ImplementationNamespace.IMPLEMENTATION_NAMESPACE);
    assertEquals("Wrong capabilities", 1, capabilities.size());
    Capability capability = capabilities.get(0);
    Map<String, Object> attributes = capability.getAttributes();
    assertEquals("Wrong namespace value", "osgi.subsystem", attributes.get(ImplementationNamespace.IMPLEMENTATION_NAMESPACE));
    Object version = attributes.get(ImplementationNamespace.CAPABILITY_VERSION_ATTRIBUTE);
    assertTrue("Wrong version type", version instanceof Version);
    assertEquals("Wrong version", Version.parseVersion("1.1"), version);
    assertEquals("Wrong uses", "org.osgi.service.subsystem", capability.getDirectives().get(ImplementationNamespace.CAPABILITY_USES_DIRECTIVE));
}
Also used : Capability(org.osgi.resource.Capability) Version(org.osgi.framework.Version) Bundle(org.osgi.framework.Bundle) BundleRevision(org.osgi.framework.wiring.BundleRevision) Test(org.junit.Test) SubsystemTest(org.apache.aries.subsystem.itests.SubsystemTest)

Example 64 with BundleRevision

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

the class Aries1417Test method testOsgiService.

@Test
public void testOsgiService() throws Exception {
    Bundle bundle = getSubsystemCoreBundle();
    BundleRevision revision = bundle.adapt(BundleRevision.class);
    List<Capability> capabilities = revision.getCapabilities(ServiceNamespace.SERVICE_NAMESPACE);
    assertEquals("Wrong capabilities", 1, capabilities.size());
    Capability capability = capabilities.get(0);
    Map<String, Object> attributes = capability.getAttributes();
    Object objectClass = attributes.get(ServiceNamespace.CAPABILITY_OBJECTCLASS_ATTRIBUTE);
    assertTrue("Wrong objectClass type", objectClass instanceof List);
    @SuppressWarnings({ "rawtypes" }) List objectClassList = (List) objectClass;
    assertEquals("Wrong objectClass size", 2, objectClassList.size());
    Object objectClass1 = objectClassList.get(0);
    assertTrue("Wrong objectClass type", objectClass1 instanceof String);
    assertEquals("Wrong objectClass", "org.osgi.service.subsystem.Subsystem", objectClass1);
    Object objectClass2 = objectClassList.get(1);
    assertTrue("Wrong objectClass type", objectClass2 instanceof String);
    assertEquals("Wrong objectClass", "org.apache.aries.subsystem.AriesSubsystem", objectClass2);
    assertEquals("Wrong uses", "org.osgi.service.subsystem,org.apache.aries.subsystem", capability.getDirectives().get(ServiceNamespace.CAPABILITY_USES_DIRECTIVE));
}
Also used : Capability(org.osgi.resource.Capability) Bundle(org.osgi.framework.Bundle) BundleRevision(org.osgi.framework.wiring.BundleRevision) List(java.util.List) Test(org.junit.Test) SubsystemTest(org.apache.aries.subsystem.itests.SubsystemTest)

Example 65 with BundleRevision

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

the class BundleWiringState method getRevisionsWiring.

/* (non-Javadoc)
     * @see org.osgi.jmx.framework.BundleRevisionsStateMBean#getRevisionsWiring(long, java.lang.String)
     */
public TabularData getRevisionsWiring(long bundleId, String namespace) throws IOException {
    Bundle bundle = FrameworkUtils.resolveBundle(bundleContext, bundleId);
    BundleRevisions revisions = bundle.adapt(BundleRevisions.class);
    TabularData td = new TabularDataSupport(BundleWiringStateMBean.BUNDLES_WIRING_TYPE);
    for (BundleRevision revision : revisions.getRevisions()) {
        Map<BundleRevision, Integer> revisionIDMap = getRevisionTransitiveClosure(revision, namespace);
        td.put(getRevisionWiring(revision, System.identityHashCode(revision), namespace, revisionIDMap));
    }
    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)

Aggregations

BundleRevision (org.osgi.framework.wiring.BundleRevision)79 Bundle (org.osgi.framework.Bundle)42 ArrayList (java.util.ArrayList)24 HashMap (java.util.HashMap)18 BundleWiring (org.osgi.framework.wiring.BundleWiring)14 BundleCapability (org.osgi.framework.wiring.BundleCapability)13 Test (org.junit.Test)12 Map (java.util.Map)11 BundleRequirement (org.osgi.framework.wiring.BundleRequirement)11 Resource (org.osgi.resource.Resource)11 HashSet (java.util.HashSet)9 BundleRevisions (org.osgi.framework.wiring.BundleRevisions)9 BundleContext (org.osgi.framework.BundleContext)8 BundleException (org.osgi.framework.BundleException)8 List (java.util.List)7 BundleConstituent (org.apache.aries.subsystem.core.internal.BundleResourceInstaller.BundleConstituent)7 BundleWire (org.osgi.framework.wiring.BundleWire)7 Requirement (org.osgi.resource.Requirement)7 File (java.io.File)6 Collection (java.util.Collection)6