use of org.osgi.framework.wiring.BundleCapability in project karaf by apache.
the class ShowBundleTree method createNodeForImport.
/*
* Create a child node for a given import (by finding a matching export in the currently installed bundles)
*/
private void createNodeForImport(Node<Bundle> node, Bundle bundle, Clause i) {
VersionRange range = VersionRange.parseVersionRange(i.getAttribute(Constants.VERSION_ATTRIBUTE));
boolean foundMatch = false;
for (Bundle b : bundleContext.getBundles()) {
BundleWiring wiring = b.adapt(BundleWiring.class);
if (wiring != null) {
List<BundleCapability> caps = wiring.getCapabilities(BundleRevision.PACKAGE_NAMESPACE);
if (caps != null) {
for (BundleCapability cap : caps) {
String n = getAttribute(cap, BundleRevision.PACKAGE_NAMESPACE);
String v = getAttribute(cap, Constants.VERSION_ATTRIBUTE);
if (i.getName().equals(n) && range.contains(VersionTable.getVersion(v))) {
boolean existing = tree.flatten().contains(b);
System.out.printf("- import %s: resolved using %s%n", i, b);
foundMatch = true;
if (!node.hasChild(b)) {
Node<Bundle> child = node.addChild(b);
if (!existing) {
createNode(child);
}
}
}
}
}
}
}
if (!foundMatch) {
System.out.printf("- import %s: WARNING - unable to find matching export%n", i);
}
}
use of org.osgi.framework.wiring.BundleCapability in project karaf by apache.
the class Capabilities method printMatchingCapabilities.
private static boolean printMatchingCapabilities(BundleWiring wiring, Pattern namespace) {
List<BundleWire> wires = wiring.getProvidedWires(null);
Map<BundleCapability, List<BundleWire>> aggregateCaps = aggregateCapabilities(namespace, wires);
List<BundleCapability> allCaps = wiring.getCapabilities(null);
boolean matches = false;
for (BundleCapability cap : allCaps) {
if (matchNamespace(namespace, cap.getNamespace())) {
matches = true;
List<BundleWire> dependents = aggregateCaps.get(cap);
Object keyAttr = cap.getAttributes().get(cap.getNamespace());
if (dependents != null) {
String msg;
if (keyAttr != null) {
msg = cap.getNamespace() + "; " + keyAttr + " " + getVersionFromCapability(cap);
} else {
msg = cap.toString();
}
msg = msg + " required by:";
System.out.println(msg);
for (BundleWire wire : dependents) {
System.out.println(" " + wire.getRequirerWiring().getBundle());
}
} else if (keyAttr != null) {
System.out.println(cap.getNamespace() + "; " + cap.getAttributes().get(cap.getNamespace()) + " " + getVersionFromCapability(cap) + " " + UNUSED_MESSAGE);
} else {
System.out.println(cap + " " + UNUSED_MESSAGE);
}
}
}
return matches;
}
use of org.osgi.framework.wiring.BundleCapability in project sling by apache.
the class OsgiInstallerTestBase method isPackageExported.
protected boolean isPackageExported(Bundle b, String packageName) {
final BundleWiring wiring = b.adapt(BundleWiring.class);
assertNotNull("Expecting non-null BundleWiring for bundle " + b, wiring);
for (BundleCapability c : wiring.getCapabilities(PackageNamespace.PACKAGE_NAMESPACE)) {
if (packageName.equals(c.getAttributes().get(PackageNamespace.PACKAGE_NAMESPACE))) {
return true;
}
}
return false;
}
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);
}
}
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;
}
Aggregations