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;
}
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);
}
}
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;
}
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);
}
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);
}
Aggregations