Search in sources :

Example 86 with Bundle

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;
}
Also used : Bundle(org.osgi.framework.Bundle) ArrayList(java.util.ArrayList) MultiException(org.apache.karaf.shell.support.MultiException)

Example 87 with Bundle

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;
}
Also used : Pattern(java.util.regex.Pattern) Bundle(org.osgi.framework.Bundle) BundleWiring(org.osgi.framework.wiring.BundleWiring)

Example 88 with Bundle

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;
}
Also used : Bundle(org.osgi.framework.Bundle) ServiceReference(org.osgi.framework.ServiceReference)

Example 89 with Bundle

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);
        }
    }
}
Also used : Bundle(org.osgi.framework.Bundle) BundleWire(org.osgi.framework.wiring.BundleWire)

Example 90 with Bundle

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;
}
Also used : Bundle(org.osgi.framework.Bundle) VersionRange(org.apache.felix.utils.version.VersionRange)

Aggregations

Bundle (org.osgi.framework.Bundle)2490 Test (org.junit.Test)659 URL (java.net.URL)388 BundleContext (org.osgi.framework.BundleContext)311 File (java.io.File)298 ArrayList (java.util.ArrayList)292 IOException (java.io.IOException)278 BundleException (org.osgi.framework.BundleException)270 HashMap (java.util.HashMap)149 ServiceReference (org.osgi.framework.ServiceReference)145 Path (org.eclipse.core.runtime.Path)126 Hashtable (java.util.Hashtable)124 HashSet (java.util.HashSet)95 InputStream (java.io.InputStream)94 IStatus (org.eclipse.core.runtime.IStatus)86 Status (org.eclipse.core.runtime.Status)82 List (java.util.List)80 Map (java.util.Map)74 BundleWiring (org.osgi.framework.wiring.BundleWiring)74 Version (org.osgi.framework.Version)73