use of org.apache.karaf.bundle.command.bundletree.Tree in project karaf by apache.
the class ShowBundleTree method printDuplicatePackages.
/*
* Check for bundles in the tree exporting the same package
* as a possible cause for 'Unresolved constraint...' on a uses-conflict
*/
private void printDuplicatePackages(Tree<Bundle> tree) {
Set<Bundle> bundles = tree.flatten();
Map<String, Set<Bundle>> exports = new HashMap<>();
for (Bundle bundle : bundles) {
for (BundleRevision revision : bundle.adapt(BundleRevisions.class).getRevisions()) {
BundleWiring wiring = revision.getWiring();
if (wiring != null) {
List<BundleWire> wires = wiring.getProvidedWires(BundleRevision.PACKAGE_NAMESPACE);
if (wires != null) {
for (BundleWire wire : wires) {
String name = wire.getCapability().getAttributes().get(BundleRevision.PACKAGE_NAMESPACE).toString();
exports.computeIfAbsent(name, k -> new HashSet<>()).add(bundle);
}
}
}
}
}
for (String pkg : exports.keySet()) {
if (exports.get(pkg).size() > 1) {
System.out.printf("%n");
System.out.printf("WARNING: multiple bundles are exporting package %s%n", pkg);
for (Bundle bundle : exports.get(pkg)) {
System.out.printf("- %s%n", bundle);
}
}
}
}
Aggregations