Search in sources :

Example 41 with BundleRevision

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

the class PackageServiceImpl method getImports.

@Override
public List<String> getImports(long bundleId) {
    Bundle bundle = bundleContext.getBundle(bundleId);
    BundleRevision rev = bundle.adapt(BundleRevision.class);
    List<BundleRequirement> reqs = rev.getDeclaredRequirements(BundleRevision.PACKAGE_NAMESPACE);
    List<String> imports = new ArrayList<>();
    for (BundleRequirement req : reqs) {
        PackageRequirement packageReq = create(req, bundle);
        imports.add(packageReq.getPackageName());
    }
    return imports;
}
Also used : Bundle(org.osgi.framework.Bundle) PackageRequirement(org.apache.karaf.packages.core.PackageRequirement) BundleRevision(org.osgi.framework.wiring.BundleRevision) ArrayList(java.util.ArrayList) BundleRequirement(org.osgi.framework.wiring.BundleRequirement)

Example 42 with BundleRevision

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

the class PackageServiceImpl method getExports.

public List<PackageVersion> getExports() {
    Bundle[] bundles = bundleContext.getBundles();
    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 new ArrayList<>(packageVersionMap.values());
}
Also used : Bundle(org.osgi.framework.Bundle) ArrayList(java.util.ArrayList) TreeMap(java.util.TreeMap) PackageVersion(org.apache.karaf.packages.core.PackageVersion) PackageVersion(org.apache.karaf.packages.core.PackageVersion) Version(org.osgi.framework.Version) BundleRevision(org.osgi.framework.wiring.BundleRevision) BundleCapability(org.osgi.framework.wiring.BundleCapability)

Example 43 with BundleRevision

use of org.osgi.framework.wiring.BundleRevision 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 44 with BundleRevision

use of org.osgi.framework.wiring.BundleRevision 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)

Example 45 with BundleRevision

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

the class BundleWiresTest method bundleCap.

private BundleCapability bundleCap(long bundleId, String version) {
    BundleRevision rev = c.createMock(BundleRevision.class);
    Bundle bundle = c.createMock(Bundle.class);
    expect(bundle.getBundleId()).andReturn(bundleId);
    expect(rev.getBundle()).andReturn(bundle);
    BundleCapability cap = c.createMock(BundleCapability.class);
    expect(cap.getRevision()).andReturn(rev);
    Map<String, Object> attrs = new HashMap<>();
    attrs.put(Constants.VERSION_ATTRIBUTE, version);
    expect(cap.getAttributes()).andReturn(attrs);
    return cap;
}
Also used : HashMap(java.util.HashMap) Bundle(org.osgi.framework.Bundle) BundleRevision(org.osgi.framework.wiring.BundleRevision) BundleCapability(org.osgi.framework.wiring.BundleCapability)

Aggregations

BundleRevision (org.osgi.framework.wiring.BundleRevision)79 Bundle (org.osgi.framework.Bundle)42 ArrayList (java.util.ArrayList)24 HashMap (java.util.HashMap)18 BundleWiring (org.osgi.framework.wiring.BundleWiring)14 BundleCapability (org.osgi.framework.wiring.BundleCapability)13 Test (org.junit.Test)12 Map (java.util.Map)11 BundleRequirement (org.osgi.framework.wiring.BundleRequirement)11 Resource (org.osgi.resource.Resource)11 HashSet (java.util.HashSet)9 BundleRevisions (org.osgi.framework.wiring.BundleRevisions)9 BundleContext (org.osgi.framework.BundleContext)8 BundleException (org.osgi.framework.BundleException)8 List (java.util.List)7 BundleConstituent (org.apache.aries.subsystem.core.internal.BundleResourceInstaller.BundleConstituent)7 BundleWire (org.osgi.framework.wiring.BundleWire)7 Requirement (org.osgi.resource.Requirement)7 File (java.io.File)6 Collection (java.util.Collection)6