You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@karaf.apache.org by gn...@apache.org on 2016/03/31 09:58:15 UTC

[2/3] karaf git commit: [KARAF-4422] Ability to show wiring between features or all resources after a resolution

[KARAF-4422] Ability to show wiring between features or all resources after a resolution


Project: http://git-wip-us.apache.org/repos/asf/karaf/repo
Commit: http://git-wip-us.apache.org/repos/asf/karaf/commit/2fe35a3e
Tree: http://git-wip-us.apache.org/repos/asf/karaf/tree/2fe35a3e
Diff: http://git-wip-us.apache.org/repos/asf/karaf/diff/2fe35a3e

Branch: refs/heads/master
Commit: 2fe35a3e5adc4c625534e94c20581bd4ec11c487
Parents: 07cb6c1
Author: Guillaume Nodet <gn...@apache.org>
Authored: Wed Mar 16 09:51:37 2016 +0100
Committer: Guillaume Nodet <gn...@apache.org>
Committed: Thu Mar 31 09:24:59 2016 +0200

----------------------------------------------------------------------
 .../features/command/InstallFeatureCommand.java |  8 +++++
 .../apache/karaf/features/FeaturesService.java  |  4 ++-
 .../features/internal/service/Deployer.java     | 38 +++++++++++++++++++-
 3 files changed, 48 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/karaf/blob/2fe35a3e/features/command/src/main/java/org/apache/karaf/features/command/InstallFeatureCommand.java
----------------------------------------------------------------------
diff --git a/features/command/src/main/java/org/apache/karaf/features/command/InstallFeatureCommand.java b/features/command/src/main/java/org/apache/karaf/features/command/InstallFeatureCommand.java
index 8983009..abcff31 100644
--- a/features/command/src/main/java/org/apache/karaf/features/command/InstallFeatureCommand.java
+++ b/features/command/src/main/java/org/apache/karaf/features/command/InstallFeatureCommand.java
@@ -58,6 +58,12 @@ public class InstallFeatureCommand extends FeaturesCommandSupport {
     @Option(name = "--store", description = "Store the resolution into the given file and result for offline analysis")
     String outputFile;
 
+    @Option(name = "--features-wiring", description = "Print the wiring between features")
+    boolean featuresWiring;
+
+    @Option(name = "--all-wiring", description = "Print the full wiring")
+    boolean allWiring;
+
     @Option(name = "-g", aliases = "--region", description = "Region to install to")
     String region;
 
@@ -68,6 +74,8 @@ public class InstallFeatureCommand extends FeaturesCommandSupport {
         addOption(FeaturesService.Option.NoAutoManageBundles, noManage);
         addOption(FeaturesService.Option.Verbose, verbose);
         addOption(FeaturesService.Option.Upgrade, upgrade);
+        addOption(FeaturesService.Option.DisplayFeaturesWiring, featuresWiring);
+        addOption(FeaturesService.Option.DisplayAllWiring, allWiring);
         admin.setResolutionOutputFile(outputFile);
         admin.installFeatures(new HashSet<String>(features), region, options);
     }

http://git-wip-us.apache.org/repos/asf/karaf/blob/2fe35a3e/features/core/src/main/java/org/apache/karaf/features/FeaturesService.java
----------------------------------------------------------------------
diff --git a/features/core/src/main/java/org/apache/karaf/features/FeaturesService.java b/features/core/src/main/java/org/apache/karaf/features/FeaturesService.java
index a9aab6b..cee23c0 100644
--- a/features/core/src/main/java/org/apache/karaf/features/FeaturesService.java
+++ b/features/core/src/main/java/org/apache/karaf/features/FeaturesService.java
@@ -57,7 +57,9 @@ public interface FeaturesService {
         NoAutoManageBundles,
         Simulate,
         Verbose,
-        Upgrade
+        Upgrade,
+        DisplayFeaturesWiring,
+        DisplayAllWiring
     }
 
     /**

http://git-wip-us.apache.org/repos/asf/karaf/blob/2fe35a3e/features/core/src/main/java/org/apache/karaf/features/internal/service/Deployer.java
----------------------------------------------------------------------
diff --git a/features/core/src/main/java/org/apache/karaf/features/internal/service/Deployer.java b/features/core/src/main/java/org/apache/karaf/features/internal/service/Deployer.java
index 3a053f4..670985b 100644
--- a/features/core/src/main/java/org/apache/karaf/features/internal/service/Deployer.java
+++ b/features/core/src/main/java/org/apache/karaf/features/internal/service/Deployer.java
@@ -49,6 +49,8 @@ import org.apache.karaf.features.internal.download.DownloadManager;
 import org.apache.karaf.features.internal.download.StreamProvider;
 import org.apache.karaf.features.internal.region.SubsystemResolver;
 import org.apache.karaf.features.internal.resolver.FeatureResource;
+import org.apache.karaf.features.internal.resolver.ResolverUtil;
+import org.apache.karaf.features.internal.resolver.ResourceUtils;
 import org.apache.karaf.features.internal.util.ChecksumUtils;
 import org.apache.karaf.features.internal.util.Macro;
 import org.apache.karaf.features.internal.util.MapUtils;
@@ -97,7 +99,6 @@ import static org.apache.karaf.features.internal.util.MapUtils.map;
 import static org.apache.karaf.features.internal.util.MapUtils.removeFromMapSet;
 import static org.osgi.framework.Bundle.ACTIVE;
 import static org.osgi.framework.Bundle.RESOLVED;
-import static org.osgi.framework.Bundle.STARTING;
 import static org.osgi.framework.Bundle.STOPPING;
 import static org.osgi.framework.Bundle.STOP_TRANSIENT;
 import static org.osgi.framework.Bundle.UNINSTALLED;
@@ -206,6 +207,10 @@ public class Deployer {
         boolean verbose = request.options.contains(FeaturesService.Option.Verbose);
         boolean simulate = request.options.contains(FeaturesService.Option.Simulate);
         boolean noManageBundles = request.options.contains(FeaturesService.Option.NoAutoManageBundles);
+        boolean showWiring = request.options.contains(FeaturesService.Option.DisplayFeaturesWiring)
+                    || request.options.contains(FeaturesService.Option.DisplayAllWiring);
+        boolean showFeaturesWiringOnly = request.options.contains(FeaturesService.Option.DisplayFeaturesWiring)
+                    && !request.options.contains(FeaturesService.Option.DisplayAllWiring);
 
         // TODO: add an option to unmanage bundles instead of uninstalling those
 
@@ -491,6 +496,13 @@ public class Deployer {
         }
 
         //
+        // Log wiring
+        //
+        if (showWiring) {
+            logWiring(resolver.getWiring(), showFeaturesWiringOnly);
+        }
+
+        //
         // Log deployment
         //
         logDeployment(deployment, verbose);
@@ -1061,6 +1073,30 @@ public class Deployer {
         }
     }
 
+    protected void logWiring(Map<Resource, List<Wire>> wiring, boolean onlyFeatures) {
+        print("Wiring:", true);
+        Map<Resource, Set<Resource>> wires = new HashMap<>();
+        for (Resource r : wiring.keySet()) {
+            if (onlyFeatures && !ResourceUtils.TYPE_FEATURE.equals(ResourceUtils.getType(r))) {
+                continue;
+            }
+            for (Wire w : wiring.get(r)) {
+                if (onlyFeatures && !ResourceUtils.TYPE_FEATURE.equals(ResourceUtils.getType(w.getProvider()))) {
+                    continue;
+                }
+                MapUtils.addToMapSet(wires, w.getRequirer(), w.getProvider());
+            }
+        }
+        List<Resource> sorted = new ArrayList<>(wires.keySet());
+        Collections.sort(sorted, (r1, r2) -> wires.get(r1).size() - wires.get(r2).size());
+        for (Resource r : sorted) {
+            print("    " + ResolverUtil.getSymbolicName(r) + " / " + ResolverUtil.getVersion(r), true);
+            for (Resource w : wires.get(r)) {
+                print("        " + ResolverUtil.getSymbolicName(w) + " / " + ResolverUtil.getVersion(w), true);
+            }
+        }
+    }
+
     protected void logDeployment(Deployer.Deployment overallDeployment, boolean verbose) {
         if (overallDeployment.regions.isEmpty()) {
             print("No deployment change.", verbose);