Search in sources :

Example 1 with Tree

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);
            }
        }
    }
}
Also used : Constants(org.osgi.framework.Constants) LoggerFactory(org.slf4j.LoggerFactory) HashMap(java.util.HashMap) Parser(org.apache.felix.utils.manifest.Parser) Command(org.apache.karaf.shell.api.action.Command) HashSet(java.util.HashSet) BundleCapability(org.osgi.framework.wiring.BundleCapability) Clause(org.apache.felix.utils.manifest.Clause) Map(java.util.Map) Node(org.apache.karaf.bundle.command.bundletree.Node) VersionTable(org.apache.felix.utils.version.VersionTable) Bundle(org.osgi.framework.Bundle) BundleRevision(org.osgi.framework.wiring.BundleRevision) BundleWiring(org.osgi.framework.wiring.BundleWiring) Logger(org.slf4j.Logger) Collection(java.util.Collection) Set(java.util.Set) VersionRange(org.apache.felix.utils.version.VersionRange) String.format(java.lang.String.format) BundleRevisions(org.osgi.framework.wiring.BundleRevisions) List(java.util.List) Service(org.apache.karaf.shell.api.action.lifecycle.Service) BundleWire(org.osgi.framework.wiring.BundleWire) Option(org.apache.karaf.shell.api.action.Option) Tree(org.apache.karaf.bundle.command.bundletree.Tree) HashSet(java.util.HashSet) Set(java.util.Set) HashMap(java.util.HashMap) Bundle(org.osgi.framework.Bundle) BundleWiring(org.osgi.framework.wiring.BundleWiring) BundleWire(org.osgi.framework.wiring.BundleWire) BundleRevision(org.osgi.framework.wiring.BundleRevision) BundleRevisions(org.osgi.framework.wiring.BundleRevisions) HashSet(java.util.HashSet)

Aggregations

String.format (java.lang.String.format)1 Collection (java.util.Collection)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 List (java.util.List)1 Map (java.util.Map)1 Set (java.util.Set)1 Clause (org.apache.felix.utils.manifest.Clause)1 Parser (org.apache.felix.utils.manifest.Parser)1 VersionRange (org.apache.felix.utils.version.VersionRange)1 VersionTable (org.apache.felix.utils.version.VersionTable)1 Node (org.apache.karaf.bundle.command.bundletree.Node)1 Tree (org.apache.karaf.bundle.command.bundletree.Tree)1 Command (org.apache.karaf.shell.api.action.Command)1 Option (org.apache.karaf.shell.api.action.Option)1 Service (org.apache.karaf.shell.api.action.lifecycle.Service)1 Bundle (org.osgi.framework.Bundle)1 Constants (org.osgi.framework.Constants)1 BundleCapability (org.osgi.framework.wiring.BundleCapability)1 BundleRevision (org.osgi.framework.wiring.BundleRevision)1