use of org.osgi.framework.wiring.BundleWiring in project karaf by apache.
the class Headers method checkPackage.
private boolean checkPackage(String packageName, String version) {
VersionRange range = VersionRange.parseVersionRange(version);
Bundle[] bundles = bundleContext.getBundles();
for (int i = 0; (bundles != null) && (i < bundles.length); i++) {
BundleWiring wiring = bundles[i].adapt(BundleWiring.class);
List<BundleCapability> caps = wiring != null ? wiring.getCapabilities(BundleRevision.PACKAGE_NAMESPACE) : null;
if (caps != null) {
for (BundleCapability cap : caps) {
String n = getAttribute(cap, BundleRevision.PACKAGE_NAMESPACE);
String v = getAttribute(cap, Constants.VERSION_ATTRIBUTE);
if (packageName.equals(n) && range.contains(VersionTable.getVersion(v))) {
return true;
}
}
}
}
return false;
}
use of org.osgi.framework.wiring.BundleWiring in project karaf by apache.
the class Requirements method doExecute.
@Override
protected Object doExecute(List<Bundle> bundles) throws Exception {
boolean separatorNeeded = false;
Pattern ns = Pattern.compile(namespace.replaceAll("\\.", "\\\\.").replaceAll("\\*", ".*"));
for (Bundle b : bundles) {
if (separatorNeeded) {
System.out.println("");
}
// Print out any matching generic requirements.
BundleWiring wiring = b.adapt(BundleWiring.class);
if (wiring != null) {
String title = b + " requires:";
System.out.println(title);
System.out.println(ShellUtil.getUnderlineString(title));
boolean matches = printMatchingRequirements(wiring, ns);
// of the generic model in OSGi.
if (matchNamespace(ns, NONSTANDARD_SERVICE_NAMESPACE)) {
matches |= printServiceRequirements(b);
}
// then say so.
if (!matches) {
System.out.println(namespace + " " + EMPTY_MESSAGE);
}
} else {
System.out.println("Bundle " + b.getBundleId() + " is not resolved.");
}
separatorNeeded = true;
}
return null;
}
use of org.osgi.framework.wiring.BundleWiring in project karaf by apache.
the class BundleWiresTest method wiredBundle.
private Bundle wiredBundle(List<BundleWire> wires) {
Bundle bundle = c.createMock(Bundle.class);
EasyMock.expect(bundle.getBundleId()).andReturn(1l);
BundleWiring wiring = c.createMock(BundleWiring.class);
expect(wiring.getRequiredWires(null)).andReturn(wires);
expect(bundle.adapt(BundleWiring.class)).andReturn(wiring);
return bundle;
}
use of org.osgi.framework.wiring.BundleWiring in project geronimo-xbean by apache.
the class BundleUtils method getWiredBundles43.
// OSGi 4.3 API
private static LinkedHashSet<Bundle> getWiredBundles43(Bundle bundle) {
LinkedHashSet<Bundle> wiredBundles = new LinkedHashSet<Bundle>();
BundleWiring wiring = bundle.adapt(BundleWiring.class);
if (wiring != null) {
List<BundleWire> wires;
wires = wiring.getRequiredWires(BundleRevision.PACKAGE_NAMESPACE);
for (BundleWire wire : wires) {
wiredBundles.add(wire.getProviderWiring().getBundle());
}
wires = wiring.getRequiredWires(BundleRevision.BUNDLE_NAMESPACE);
for (BundleWire wire : wires) {
wiredBundles.add(wire.getProviderWiring().getBundle());
}
}
return wiredBundles;
}
use of org.osgi.framework.wiring.BundleWiring 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;
}
Aggregations