Search in sources :

Example 76 with BundleCapability

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
        }
    }
}
Also used : HashMap(java.util.HashMap) Bundle(org.osgi.framework.Bundle) BundleWiring(org.osgi.framework.wiring.BundleWiring) BundleException(org.osgi.framework.BundleException) Equinox(org.eclipse.osgi.launch.Equinox) BundleException(org.osgi.framework.BundleException) BundleCapability(org.osgi.framework.wiring.BundleCapability) File(java.io.File) BundleContext(org.osgi.framework.BundleContext)

Example 77 with BundleCapability

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);
    }
}
Also used : OpenDataException(javax.management.openmbean.OpenDataException) CompositeData(javax.management.openmbean.CompositeData) BundleCapability(org.osgi.framework.wiring.BundleCapability)

Example 78 with BundleCapability

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;
}
Also used : CompositeData(javax.management.openmbean.CompositeData) BundleCapability(org.osgi.framework.wiring.BundleCapability)

Example 79 with BundleCapability

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;
}
Also used : HashMap(java.util.HashMap) CompositeData(javax.management.openmbean.CompositeData) CompositeDataSupport(javax.management.openmbean.CompositeDataSupport) BundleCapability(org.osgi.framework.wiring.BundleCapability) BundleWire(org.osgi.framework.wiring.BundleWire) BundleRequirement(org.osgi.framework.wiring.BundleRequirement)

Example 80 with BundleCapability

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);
}
Also used : CompositeData(javax.management.openmbean.CompositeData) BundleRevision(org.osgi.framework.wiring.BundleRevision) BundleCapability(org.osgi.framework.wiring.BundleCapability) HashMap(java.util.HashMap) Map(java.util.Map) Test(org.junit.Test) AbstractIntegrationTest(org.apache.aries.jmx.AbstractIntegrationTest)

Aggregations

BundleCapability (org.osgi.framework.wiring.BundleCapability)83 ArrayList (java.util.ArrayList)30 BundleRevision (org.osgi.framework.wiring.BundleRevision)26 HashMap (java.util.HashMap)24 Bundle (org.osgi.framework.Bundle)24 BundleRequirement (org.osgi.framework.wiring.BundleRequirement)21 BundleWiring (org.osgi.framework.wiring.BundleWiring)19 BundleWire (org.osgi.framework.wiring.BundleWire)18 List (java.util.List)15 Version (org.osgi.framework.Version)12 BundleException (org.osgi.framework.BundleException)11 ResolverHook (org.osgi.framework.hooks.resolver.ResolverHook)11 Collection (java.util.Collection)10 Test (org.junit.Test)10 HashSet (java.util.HashSet)9 Set (java.util.Set)8 ResolverHookFactory (org.osgi.framework.hooks.resolver.ResolverHookFactory)8 LinkedHashMap (java.util.LinkedHashMap)6 Module (org.eclipse.osgi.container.Module)6 CompositeData (javax.management.openmbean.CompositeData)5