Search in sources :

Example 1 with BundleWire

use of org.osgi.framework.wiring.BundleWire in project camel by apache.

the class Activator method canSee.

/**
     * Check if bundle can see the given class
     */
protected boolean canSee(Bundle bundle, Class<?> clazz) {
    if (bundle.getBundleId() == bundleId) {
        // Need extra handling of camel core as it does not import the api
        return true;
    }
    BundleCapability packageCap = packageCapabilities.get(clazz.getPackage().getName());
    if (packageCap != null) {
        BundleWiring wiring = bundle.adapt(BundleWiring.class);
        List<BundleWire> imports = wiring.getRequiredWires(PACKAGE_NAMESPACE);
        for (BundleWire importWire : imports) {
            if (packageCap.equals(importWire.getCapability())) {
                return true;
            }
        }
    }
    // then we need to use a different canSee algorithm that works outside real OSGi
    if (bundle.getBundleId() > 0) {
        Bundle root = bundle.getBundleContext().getBundle(0);
        if (root != null && "org.apache.felix.connect".equals(root.getSymbolicName())) {
            return checkCompat(bundle, clazz);
        }
    }
    return false;
}
Also used : Bundle(org.osgi.framework.Bundle) BundleWiring(org.osgi.framework.wiring.BundleWiring) BundleCapability(org.osgi.framework.wiring.BundleCapability) BundleWire(org.osgi.framework.wiring.BundleWire)

Example 2 with BundleWire

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

the class HttpExtension method getAttributes.

private Map<String, Object> getAttributes() {
    BundleWiring bundleWiring = _bundle.adapt(BundleWiring.class);
    List<BundleWire> wires = bundleWiring.getRequiredWires(EXTENDER_NAMESPACE);
    Map<String, Object> cdiAttributes = Collections.emptyMap();
    for (BundleWire wire : wires) {
        BundleCapability capability = wire.getCapability();
        Map<String, Object> attributes = capability.getAttributes();
        String extender = (String) attributes.get(EXTENDER_NAMESPACE);
        if (extender.equals(CDI_CAPABILITY_NAME)) {
            BundleRequirement requirement = wire.getRequirement();
            cdiAttributes = requirement.getAttributes();
            break;
        }
    }
    return cdiAttributes;
}
Also used : BundleWiring(org.osgi.framework.wiring.BundleWiring) BundleCapability(org.osgi.framework.wiring.BundleCapability) BundleWire(org.osgi.framework.wiring.BundleWire) BundleRequirement(org.osgi.framework.wiring.BundleRequirement)

Example 3 with BundleWire

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

the class Activator method requiresCdiExtender.

private boolean requiresCdiExtender(Bundle bundle) {
    BundleWiring bundleWiring = bundle.adapt(BundleWiring.class);
    List<BundleWire> requiredBundleWires = bundleWiring.getRequiredWires(EXTENDER_NAMESPACE);
    for (BundleWire bundleWire : requiredBundleWires) {
        Map<String, Object> attributes = bundleWire.getCapability().getAttributes();
        if (attributes.containsKey(EXTENDER_NAMESPACE) && attributes.get(EXTENDER_NAMESPACE).equals(CDI_CAPABILITY_NAME)) {
            Bundle providerWiringBundle = bundleWire.getProviderWiring().getBundle();
            if (providerWiringBundle.equals(_bundleContext.getBundle())) {
                return true;
            }
        }
    }
    return false;
}
Also used : Bundle(org.osgi.framework.Bundle) BundleWiring(org.osgi.framework.wiring.BundleWiring) BundleWire(org.osgi.framework.wiring.BundleWire)

Example 4 with BundleWire

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

the class AbstractTestCase method getCdiExtenderBundle.

Bundle getCdiExtenderBundle() {
    BundleWiring bundleWiring = cdiBundle.adapt(BundleWiring.class);
    List<BundleWire> requiredWires = bundleWiring.getRequiredWires(ExtenderNamespace.EXTENDER_NAMESPACE);
    for (BundleWire wire : requiredWires) {
        Map<String, Object> attributes = wire.getCapability().getAttributes();
        String extender = (String) attributes.get(ExtenderNamespace.EXTENDER_NAMESPACE);
        if (CdiConstants.CDI_CAPABILITY_NAME.equals(extender)) {
            return wire.getProvider().getBundle();
        }
    }
    return null;
}
Also used : BundleWiring(org.osgi.framework.wiring.BundleWiring) BundleWire(org.osgi.framework.wiring.BundleWire)

Example 5 with BundleWire

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

the class SubsystemDependencyTestBase method verifyRequireBundleWiring.

/**
	 * Verify that the Require-Bundle of wiredBundleName in subsystem s is met by a wire
	 * to expectedProvidingBundleName
	 * @param s
	 * @param wiredBundleName
	 * @param expectedProvidingBundleName
	 */
protected void verifyRequireBundleWiring(Subsystem s, String wiredBundleName, String expectedProvidingBundleName) {
    Bundle wiredBundle = context(s).getBundleByName(BUNDLE_D);
    assertNotNull("Target bundle " + wiredBundleName + " not found", wiredBundle);
    BundleWiring wiring = (BundleWiring) wiredBundle.adapt(BundleWiring.class);
    List<BundleWire> wiredBundles = wiring.getRequiredWires(BUNDLE_NAMESPACE);
    assertEquals("Only one bundle expected", 1, wiredBundles.size());
    String requiredBundleName = (String) wiredBundles.get(0).getCapability().getAttributes().get(BUNDLE_NAMESPACE);
    assertEquals("Wrong bundle requirement", BUNDLE_A, requiredBundleName);
    String providingBundle = wiredBundles.get(0).getProvider().getSymbolicName();
    assertEquals("Wrong bundle provider", expectedProvidingBundleName, providingBundle);
}
Also used : Bundle(org.osgi.framework.Bundle) BundleWiring(org.osgi.framework.wiring.BundleWiring) BundleWire(org.osgi.framework.wiring.BundleWire)

Aggregations

BundleWire (org.osgi.framework.wiring.BundleWire)30 BundleWiring (org.osgi.framework.wiring.BundleWiring)22 Bundle (org.osgi.framework.Bundle)19 ArrayList (java.util.ArrayList)9 BundleRequirement (org.osgi.framework.wiring.BundleRequirement)8 Test (org.junit.Test)7 BundleCapability (org.osgi.framework.wiring.BundleCapability)7 BundleRevision (org.osgi.framework.wiring.BundleRevision)7 List (java.util.List)5 HashMap (java.util.HashMap)4 HashSet (java.util.HashSet)4 CompositeData (javax.management.openmbean.CompositeData)4 AbstractIntegrationTest (org.apache.aries.jmx.AbstractIntegrationTest)4 Version (org.osgi.framework.Version)4 BundleRevisions (org.osgi.framework.wiring.BundleRevisions)4 ByteArrayInputStream (java.io.ByteArrayInputStream)3 ByteArrayOutputStream (java.io.ByteArrayOutputStream)3 Map (java.util.Map)3 JarOutputStream (java.util.jar.JarOutputStream)3 Manifest (java.util.jar.Manifest)3