Search in sources :

Example 11 with BundleCapability

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);
    }
}
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 12 with BundleCapability

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;
}
Also used : ArrayList(java.util.ArrayList) List(java.util.List) BundleCapability(org.osgi.framework.wiring.BundleCapability) BundleWire(org.osgi.framework.wiring.BundleWire)

Example 13 with BundleCapability

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

Example 14 with BundleCapability

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);
    }
}
Also used : OpenDataException(javax.management.openmbean.OpenDataException) CompositeData(javax.management.openmbean.CompositeData) BundleCapability(org.osgi.framework.wiring.BundleCapability)

Example 15 with BundleCapability

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;
}
Also used : CompositeData(javax.management.openmbean.CompositeData) BundleCapability(org.osgi.framework.wiring.BundleCapability)

Aggregations

BundleCapability (org.osgi.framework.wiring.BundleCapability)27 Bundle (org.osgi.framework.Bundle)11 BundleRevision (org.osgi.framework.wiring.BundleRevision)10 BundleWiring (org.osgi.framework.wiring.BundleWiring)9 HashMap (java.util.HashMap)8 ArrayList (java.util.ArrayList)7 BundleRequirement (org.osgi.framework.wiring.BundleRequirement)7 CompositeData (javax.management.openmbean.CompositeData)6 BundleWire (org.osgi.framework.wiring.BundleWire)6 List (java.util.List)4 Map (java.util.Map)4 Region (org.eclipse.equinox.region.Region)3 Test (org.junit.Test)3 HashSet (java.util.HashSet)2 Iterator (java.util.Iterator)2 Set (java.util.Set)2 TreeMap (java.util.TreeMap)2 AbstractIntegrationTest (org.apache.aries.jmx.AbstractIntegrationTest)2 VersionRange (org.apache.felix.utils.version.VersionRange)2 PackageVersion (org.apache.karaf.packages.core.PackageVersion)2