use of org.osgi.framework.wiring.BundleCapability in project karaf by apache.
the class BundleWiresTest method bundleCap.
private BundleCapability bundleCap(long bundleId, String version) {
BundleRevision rev = c.createMock(BundleRevision.class);
Bundle bundle = c.createMock(Bundle.class);
expect(bundle.getBundleId()).andReturn(bundleId);
expect(rev.getBundle()).andReturn(bundle);
BundleCapability cap = c.createMock(BundleCapability.class);
expect(cap.getRevision()).andReturn(rev);
Map<String, Object> attrs = new HashMap<>();
attrs.put(Constants.VERSION_ATTRIBUTE, version);
expect(cap.getAttributes()).andReturn(attrs);
return cap;
}
use of org.osgi.framework.wiring.BundleCapability in project aries by apache.
the class JndiExtensionTests method testDisableExtensionAndCDIContainerWaits.
public void testDisableExtensionAndCDIContainerWaits() throws Exception {
BundleTracker<Bundle> bt = new BundleTracker<>(bundle.getBundleContext(), Bundle.RESOLVED | Bundle.ACTIVE, new BundleTrackerCustomizer<Bundle>() {
@Override
public Bundle addingBundle(Bundle bundle, BundleEvent arg1) {
List<BundleCapability> capabilities = bundle.adapt(BundleWiring.class).getCapabilities(CdiConstants.CDI_EXTENSION_NAMESPACE);
if (capabilities.isEmpty()) {
return null;
}
for (Capability capability : capabilities) {
if (capability.getAttributes().containsValue("jndi")) {
return bundle;
}
}
return null;
}
@Override
public void modifiedBundle(Bundle bundle, BundleEvent arg1, Bundle arg2) {
}
@Override
public void removedBundle(Bundle bundle, BundleEvent arg1, Bundle arg2) {
}
});
bt.open();
assertFalse(bt.isEmpty());
Bundle extensionBundle = bt.getBundles()[0];
Collection<ServiceReference<CdiContainer>> serviceReferences = bundleContext.getServiceReferences(CdiContainer.class, "(&(objectClass=" + CdiContainer.class.getName() + ")(service.bundleid=" + cdiBundle.getBundleId() + "))");
assertNotNull(serviceReferences);
assertFalse(serviceReferences.isEmpty());
ServiceReference<CdiContainer> serviceReference = serviceReferences.iterator().next();
CdiEvent.Type state = (CdiEvent.Type) serviceReference.getProperty(CdiConstants.CDI_CONTAINER_STATE);
assertEquals(CdiEvent.Type.CREATED, state);
extensionBundle.stop();
state = (CdiEvent.Type) serviceReference.getProperty(CdiConstants.CDI_CONTAINER_STATE);
assertEquals(CdiEvent.Type.WAITING_FOR_EXTENSIONS, state);
extensionBundle.start();
state = (CdiEvent.Type) serviceReference.getProperty(CdiConstants.CDI_CONTAINER_STATE);
assertEquals(CdiEvent.Type.CREATED, state);
}
use of org.osgi.framework.wiring.BundleCapability in project geronimo-xbean by apache.
the class DelegatingBundle method buildPackageBundleMap.
private Map<String, Bundle> buildPackageBundleMap() {
Map<String, Bundle> map = new HashMap<String, Bundle>();
Iterator<Bundle> iterator = bundles.iterator();
// skip first bundle
iterator.next();
// attempt to load the class from the remaining bundles
while (iterator.hasNext()) {
Bundle bundle = iterator.next();
BundleWiring wiring = bundle.adapt(BundleWiring.class);
if (wiring != null) {
List<BundleCapability> capabilities = wiring.getCapabilities(BundleRevision.PACKAGE_NAMESPACE);
if (capabilities != null && !capabilities.isEmpty()) {
for (BundleCapability capability : capabilities) {
Map<String, Object> attributes = capability.getAttributes();
if (attributes != null) {
String packageName = String.valueOf(attributes.get(BundleRevision.PACKAGE_NAMESPACE));
if (!map.containsKey(packageName)) {
map.put(packageName, bundle);
}
}
}
}
}
}
return map;
}
use of org.osgi.framework.wiring.BundleCapability in project felix by apache.
the class ExtensionManager method convertCapabilitiesToHeaders.
private String convertCapabilitiesToHeaders(Map headers) {
StringBuffer exportSB = new StringBuffer("");
Set<String> exportNames = new HashSet<String>();
List<BundleCapability> caps = m_capabilities;
for (BundleCapability cap : caps) {
if (cap.getNamespace().equals(BundleRevision.PACKAGE_NAMESPACE)) {
// Add a comma separate if there is an existing package.
if (exportSB.length() > 0) {
exportSB.append(", ");
}
// Append exported package information.
exportSB.append(cap.getAttributes().get(BundleRevision.PACKAGE_NAMESPACE));
for (Entry<String, String> entry : cap.getDirectives().entrySet()) {
exportSB.append("; ");
exportSB.append(entry.getKey());
exportSB.append(":=\"");
exportSB.append(entry.getValue());
exportSB.append("\"");
}
for (Entry<String, Object> entry : cap.getAttributes().entrySet()) {
if (!entry.getKey().equals(BundleRevision.PACKAGE_NAMESPACE) && !entry.getKey().equals(Constants.BUNDLE_SYMBOLICNAME_ATTRIBUTE) && !entry.getKey().equals(Constants.BUNDLE_VERSION_ATTRIBUTE)) {
exportSB.append("; ");
exportSB.append(entry.getKey());
exportSB.append("=\"");
exportSB.append(entry.getValue());
exportSB.append("\"");
}
}
// Remember exported packages.
exportNames.add((String) cap.getAttributes().get(BundleRevision.PACKAGE_NAMESPACE));
}
}
m_exportNames = exportNames;
return exportSB.toString();
}
use of org.osgi.framework.wiring.BundleCapability in project felix by apache.
the class ExtensionManager method removeExtensionBundles.
public void removeExtensionBundles(Felix felix) {
m_resolvedExtensions.clear();
m_unresolvedExtensions.clear();
m_failedExtensions.clear();
m_headerMap.clear();
m_headerMap.putAll(m_originalHeaderMap);
try {
ManifestParser mp = new ManifestParser(m_logger, m_configMap, m_systemBundleRevision, m_headerMap);
List<BundleCapability> caps = ManifestParser.aliasSymbolicName(mp.getCapabilities(), m_systemBundleRevision);
caps.add(buildNativeCapabilites());
appendCapabilities(caps);
} catch (Exception ex) {
m_capabilities = Collections.EMPTY_LIST;
m_logger.log(Logger.LOG_ERROR, "Error parsing system bundle export statement", ex);
}
}
Aggregations