Search in sources :

Example 6 with BundleWiring

use of org.osgi.framework.wiring.BundleWiring 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 7 with BundleWiring

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

the class CdiContainerTests method testGetBeanManagerFromCDI.

public void testGetBeanManagerFromCDI() throws Exception {
    Thread currentThread = Thread.currentThread();
    ClassLoader contextClassLoader = currentThread.getContextClassLoader();
    try {
        BundleWiring bundleWiring = cdiBundle.adapt(BundleWiring.class);
        currentThread.setContextClassLoader(bundleWiring.getClassLoader());
        BeanManager beanManager = CDI.current().getBeanManager();
        assertNotNull(beanManager);
        assertPojoExists(beanManager);
    } finally {
        currentThread.setContextClassLoader(contextClassLoader);
    }
}
Also used : BundleWiring(org.osgi.framework.wiring.BundleWiring) BeanManager(javax.enterprise.inject.spi.BeanManager)

Example 8 with BundleWiring

use of org.osgi.framework.wiring.BundleWiring 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 9 with BundleWiring

use of org.osgi.framework.wiring.BundleWiring 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)

Example 10 with BundleWiring

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

the class BundleStateMBeanTest method getPackageVersion.

private Version getPackageVersion(String packageName) {
    Bundle systemBundle = context().getBundle(0);
    BundleWiring wiring = (BundleWiring) systemBundle.adapt(BundleWiring.class);
    List<BundleCapability> packages = wiring.getCapabilities(BundleRevision.PACKAGE_NAMESPACE);
    for (BundleCapability pkg : packages) {
        Map<String, Object> attrs = pkg.getAttributes();
        if (attrs.get(BundleRevision.PACKAGE_NAMESPACE).equals(packageName)) {
            return (Version) attrs.get(Constants.VERSION_ATTRIBUTE);
        }
    }
    throw new IllegalStateException("Package version not found for " + packageName);
}
Also used : Version(org.osgi.framework.Version) Bundle(org.osgi.framework.Bundle) BundleWiring(org.osgi.framework.wiring.BundleWiring) BundleCapability(org.osgi.framework.wiring.BundleCapability)

Aggregations

BundleWiring (org.osgi.framework.wiring.BundleWiring)60 Bundle (org.osgi.framework.Bundle)38 BundleWire (org.osgi.framework.wiring.BundleWire)22 Test (org.junit.Test)14 BundleRevision (org.osgi.framework.wiring.BundleRevision)10 ArrayList (java.util.ArrayList)9 BundleCapability (org.osgi.framework.wiring.BundleCapability)9 Hashtable (java.util.Hashtable)8 BundleContext (org.osgi.framework.BundleContext)7 Dictionary (java.util.Dictionary)6 HashMap (java.util.HashMap)6 AbstractIntegrationTest (org.apache.aries.jmx.AbstractIntegrationTest)6 IAnswer (org.easymock.IAnswer)6 AsmProxyManager (org.apache.aries.proxy.impl.AsmProxyManager)5 ServiceRegistrationHolder (org.apache.karaf.service.guard.impl.GuardProxyCatalog.ServiceRegistrationHolder)5 ServiceReference (org.osgi.framework.ServiceReference)5 ServiceRegistration (org.osgi.framework.ServiceRegistration)5 Version (org.osgi.framework.Version)5 ByteArrayInputStream (java.io.ByteArrayInputStream)4 HashSet (java.util.HashSet)4