Search in sources :

Example 26 with BundleCapability

use of org.osgi.framework.wiring.BundleCapability in project karaf by apache.

the class PackageServiceImpl method getExports.

@Override
public List<String> getExports(long bundleId) {
    Bundle bundle = bundleContext.getBundle(bundleId);
    BundleRevision rev = bundle.adapt(BundleRevision.class);
    List<BundleCapability> caps = rev.getDeclaredCapabilities(BundleRevision.PACKAGE_NAMESPACE);
    List<String> exports = new ArrayList<>();
    for (BundleCapability cap : caps) {
        Map<String, Object> attr = cap.getAttributes();
        String packageName = (String) attr.get(BundleRevision.PACKAGE_NAMESPACE);
        exports.add(packageName);
    }
    return exports;
}
Also used : Bundle(org.osgi.framework.Bundle) BundleRevision(org.osgi.framework.wiring.BundleRevision) ArrayList(java.util.ArrayList) BundleCapability(org.osgi.framework.wiring.BundleCapability)

Example 27 with BundleCapability

use of org.osgi.framework.wiring.BundleCapability in project karaf by apache.

the class Exports method getDuplicatePackages.

private SortedMap<String, PackageVersion> getDuplicatePackages(Bundle[] bundles) {
    SortedMap<String, PackageVersion> packageVersionMap = new TreeMap<>();
    for (Bundle bundle : bundles) {
        BundleRevision rev = bundle.adapt(BundleRevision.class);
        if (rev != null) {
            List<BundleCapability> caps = rev.getDeclaredCapabilities(BundleRevision.PACKAGE_NAMESPACE);
            for (BundleCapability cap : caps) {
                Map<String, Object> attr = cap.getAttributes();
                String packageName = (String) attr.get(BundleRevision.PACKAGE_NAMESPACE);
                Version version = (Version) attr.get("version");
                String key = packageName + ":" + version.toString();
                PackageVersion pVer = packageVersionMap.computeIfAbsent(key, k -> new PackageVersion(packageName, version));
                pVer.addBundle(bundle);
            }
        }
    }
    return packageVersionMap;
}
Also used : PackageVersion(org.apache.karaf.packages.core.PackageVersion) Version(org.osgi.framework.Version) Bundle(org.osgi.framework.Bundle) BundleRevision(org.osgi.framework.wiring.BundleRevision) TreeMap(java.util.TreeMap) BundleCapability(org.osgi.framework.wiring.BundleCapability) PackageVersion(org.apache.karaf.packages.core.PackageVersion)

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