karaf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jbono...@apache.org
Subject git commit: [KARAF-3023] Fix association features/repositories in feature:list -o command
Date Mon, 15 Sep 2014 19:42:19 GMT
Repository: karaf
Updated Branches:
  refs/heads/karaf-3.0.x a32bf9a51 -> ea35dfc9e


[KARAF-3023] Fix association features/repositories in feature:list -o command


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

Branch: refs/heads/karaf-3.0.x
Commit: ea35dfc9e1df0b1be435c5b1a812f0d64c2fb5c3
Parents: a32bf9a
Author: Jean-Baptiste Onofré <jbonofre@apache.org>
Authored: Mon Sep 15 21:41:39 2014 +0200
Committer: Jean-Baptiste Onofré <jbonofre@apache.org>
Committed: Mon Sep 15 21:41:39 2014 +0200

----------------------------------------------------------------------
 .../features/command/ListFeaturesCommand.java   | 62 ++++++++++++--------
 1 file changed, 36 insertions(+), 26 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/karaf/blob/ea35dfc9/features/command/src/main/java/org/apache/karaf/features/command/ListFeaturesCommand.java
----------------------------------------------------------------------
diff --git a/features/command/src/main/java/org/apache/karaf/features/command/ListFeaturesCommand.java
b/features/command/src/main/java/org/apache/karaf/features/command/ListFeaturesCommand.java
index 7e3a867..d1efaf2 100644
--- a/features/command/src/main/java/org/apache/karaf/features/command/ListFeaturesCommand.java
+++ b/features/command/src/main/java/org/apache/karaf/features/command/ListFeaturesCommand.java
@@ -16,10 +16,7 @@
  */
 package org.apache.karaf.features.command;
 
-import java.util.Arrays;
-import java.util.Collections;
-import java.util.Comparator;
-import java.util.List;
+import java.util.*;
 
 import org.apache.karaf.features.Feature;
 import org.apache.karaf.features.FeaturesService;
@@ -42,7 +39,7 @@ public class ListFeaturesCommand extends FeaturesCommandSupport {
 
     protected void doExecute(FeaturesService featuresService) throws Exception {
         boolean needsLegend = false;
-        
+
         ShellTable table = new ShellTable();
         table.column("Name");
         table.column("Version");
@@ -51,26 +48,29 @@ public class ListFeaturesCommand extends FeaturesCommandSupport {
         table.column("Description").maxSize(50);
         table.emptyTableText(onlyInstalled ? "No features installed" : "No features available");
 
-        List<Repository> repos = Arrays.asList(featuresService.listRepositories());
-        for (Repository r : repos) {
-            List<Feature> features = Arrays.asList(r.getFeatures());
-            if (ordered) {
-                Collections.sort(features, new FeatureComparator());
-            }
-            for (Feature f : features) {
-                if (onlyInstalled && !featuresService.isInstalled(f)) {
-                    // Filter out not installed features if we only want to see the installed
ones
+        List<FeatureAndRepository> featuresAndRepositories = new ArrayList<FeatureAndRepository>();
+        for (Repository repository : Arrays.asList(featuresService.listRepositories())) {
+            for (Feature feature : Arrays.asList(repository.getFeatures())) {
+                if (onlyInstalled && !featuresService.isInstalled(feature)) {
                     continue;
                 }
-                table.addRow().addContent(
-                        f.getName(),
-                        f.getVersion(),
-                        featuresService.isInstalled(f) ? "x" : "",
-                        r.getName(),
-                        f.getDescription());
-                if (isInstalledViaDeployDir(r.getName())) {
-                    needsLegend = true;
-                }
+                featuresAndRepositories.add(new FeatureAndRepository(feature, repository));
+            }
+        }
+
+        if (ordered) {
+            Collections.sort(featuresAndRepositories, new FeatureAndRepositoryComparator());
+        }
+
+        for (FeatureAndRepository far : featuresAndRepositories) {
+            table.addRow().addContent(
+                    far.feature.getName(),
+                    far.feature.getVersion(),
+                    featuresService.isInstalled(far.feature) ? "x" : "",
+                    far.repository.getName(),
+                    far.feature.getDescription());
+            if (isInstalledViaDeployDir(far.repository.getName())) {
+                needsLegend = true;
             }
         }
 
@@ -86,9 +86,19 @@ public class ListFeaturesCommand extends FeaturesCommandSupport {
         return (st == null || st.length() <= 1) ? false : (st.charAt(st.length() - 1)
== '*');
     }
 
-    class FeatureComparator implements Comparator<Feature> {
-        public int compare(Feature o1, Feature o2) {
-            return o1.getName().toLowerCase().compareTo( o2.getName().toLowerCase() );
+    class FeatureAndRepository {
+        public Feature feature;
+        public Repository repository;
+
+        FeatureAndRepository(Feature feature, Repository repository) {
+            this.feature = feature;
+            this.repository = repository;
+        }
+    }
+
+    class FeatureAndRepositoryComparator implements Comparator<FeatureAndRepository>
{
+        public int compare(FeatureAndRepository o1, FeatureAndRepository o2) {
+            return o1.feature.getName().toLowerCase().compareTo( o2.feature.getName().toLowerCase()
);
         }
     }
 


Mime
View raw message