use of org.osgi.framework.Bundle in project karaf by apache.
the class BundlesCommand method doExecute.
protected Object doExecute(List<Bundle> bundles) throws Exception {
if (bundles.isEmpty()) {
throw new IllegalArgumentException("No matching bundles");
}
List<Exception> exceptions = new ArrayList<>();
for (Bundle bundle : bundles) {
try {
executeOnBundle(bundle);
} catch (Exception e) {
exceptions.add(new Exception(errorMessage + bundle.getBundleId() + ": " + e.getMessage(), e));
}
}
MultiException.throwIf("Error executing command on bundles", exceptions);
return null;
}
use of org.osgi.framework.Bundle in project karaf by apache.
the class Capabilities 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 capabilities.
BundleWiring wiring = b.adapt(BundleWiring.class);
if (wiring != null) {
String title = b + " provides:";
System.out.println(title);
System.out.println(ShellUtil.getUnderlineString(title));
// Print generic capabilities for matching namespaces.
boolean matches = printMatchingCapabilities(wiring, ns);
// of the generic model in OSGi.
if (matchNamespace(ns, NONSTANDARD_SERVICE_NAMESPACE)) {
matches |= printServiceCapabilities(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.Bundle in project karaf by apache.
the class Capabilities method printServiceCapabilities.
static boolean printServiceCapabilities(Bundle b) {
boolean matches = false;
try {
ServiceReference<?>[] refs = b.getRegisteredServices();
if ((refs != null) && (refs.length > 0)) {
matches = true;
// Print properties for each service.
for (ServiceReference<?> ref : refs) {
// Print object class with "namespace".
System.out.println(NONSTANDARD_SERVICE_NAMESPACE + "; " + ShellUtil.getValueString(ref.getProperty("objectClass")) + " with properties:");
// Print service properties.
String[] keys = ref.getPropertyKeys();
for (String key : keys) {
if (!key.equalsIgnoreCase(Constants.OBJECTCLASS)) {
Object v = ref.getProperty(key);
System.out.println(" " + key + " = " + ShellUtil.getValueString(v));
}
}
Bundle[] users = ref.getUsingBundles();
if ((users != null) && (users.length > 0)) {
System.out.println(" Used by:");
for (Bundle user : users) {
System.out.println(" " + user);
}
}
}
}
} catch (Exception ex) {
System.err.println(ex.toString());
}
return matches;
}
use of org.osgi.framework.Bundle in project karaf by apache.
the class BundleInfoImpl method getFragments.
private void getFragments(BundleRevision revision) {
List<BundleWire> wires = revision.getWiring().getProvidedWires(BundleRevision.HOST_NAMESPACE);
if (wires != null) {
for (BundleWire w : wires) {
Bundle b = w.getRequirerWiring().getBundle();
this.fragments.add(b);
}
}
}
use of org.osgi.framework.Bundle in project karaf by apache.
the class Headers method checkBundle.
private boolean checkBundle(String bundleName, String version) {
VersionRange vr = VersionRange.parseVersionRange(version);
Bundle[] bundles = bundleContext.getBundles();
for (int i = 0; (bundles != null) && (i < bundles.length); i++) {
String sym = bundles[i].getSymbolicName();
if ((sym != null) && sym.equals(bundleName)) {
if (vr.contains(bundles[i].getVersion())) {
return true;
}
}
}
return false;
}
Aggregations