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;
}
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());
}
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;
}
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;
}
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;
}
Aggregations