Search in sources :

Example 66 with BundleWiring

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

Example 67 with BundleWiring

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

Example 68 with BundleWiring

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

Example 69 with BundleWiring

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

Example 70 with BundleWiring

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

Aggregations

BundleWiring (org.osgi.framework.wiring.BundleWiring)110 Bundle (org.osgi.framework.Bundle)61 BundleWire (org.osgi.framework.wiring.BundleWire)39 ArrayList (java.util.ArrayList)23 BundleRevision (org.osgi.framework.wiring.BundleRevision)23 BundleCapability (org.osgi.framework.wiring.BundleCapability)19 Test (org.junit.Test)15 HashMap (java.util.HashMap)13 Hashtable (java.util.Hashtable)12 List (java.util.List)12 BundleContext (org.osgi.framework.BundleContext)12 URL (java.net.URL)10 Dictionary (java.util.Dictionary)10 HashSet (java.util.HashSet)9 LinkedHashMap (java.util.LinkedHashMap)8 Version (org.osgi.framework.Version)7 BundleRevisions (org.osgi.framework.wiring.BundleRevisions)7 AbstractIntegrationTest (org.apache.aries.jmx.AbstractIntegrationTest)6 IAnswer (org.easymock.IAnswer)6 ServiceReference (org.osgi.framework.ServiceReference)6