You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@karaf.apache.org by ff...@apache.org on 2012/09/24 11:13:11 UTC

svn commit: r1389255 - /karaf/trunk/features/command/src/main/java/org/apache/karaf/features/command/ListFeaturesCommand.java

Author: ffang
Date: Mon Sep 24 09:13:11 2012
New Revision: 1389255

URL: http://svn.apache.org/viewvc?rev=1389255&view=rev
Log:
[KARAF-1850]add an option to enable feature:list use alphabetical order

Modified:
    karaf/trunk/features/command/src/main/java/org/apache/karaf/features/command/ListFeaturesCommand.java

Modified: karaf/trunk/features/command/src/main/java/org/apache/karaf/features/command/ListFeaturesCommand.java
URL: http://svn.apache.org/viewvc/karaf/trunk/features/command/src/main/java/org/apache/karaf/features/command/ListFeaturesCommand.java?rev=1389255&r1=1389254&r2=1389255&view=diff
==============================================================================
--- karaf/trunk/features/command/src/main/java/org/apache/karaf/features/command/ListFeaturesCommand.java (original)
+++ karaf/trunk/features/command/src/main/java/org/apache/karaf/features/command/ListFeaturesCommand.java Mon Sep 24 09:13:11 2012
@@ -16,7 +16,10 @@
  */
 package org.apache.karaf.features.command;
 
+import java.util.ArrayList;
 import java.util.Arrays;
+import java.util.Collections;
+import java.util.Comparator;
 import java.util.List;
 
 import org.apache.karaf.features.Feature;
@@ -32,6 +35,9 @@ public class ListFeaturesCommand extends
     @Option(name = "-i", aliases = {"--installed"}, description = "Display a list of all installed features only", required = false, multiValued = false)
     boolean onlyInstalled;
 
+    @Option(name = "-o", aliases = {"--ordered"}, description = "Display a list using alphabetical order ", required = false, multiValued = false)
+    boolean ordered;
+
     protected void doExecute(FeaturesService featuresService) throws Exception {
         boolean needsLegend = false;
         
@@ -45,7 +51,11 @@ public class ListFeaturesCommand extends
 
         List<Repository> repos = Arrays.asList(featuresService.listRepositories());
         for (Repository r : repos) {
-            for (Feature f : r.getFeatures()) {
+            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
                     continue;
@@ -74,4 +84,10 @@ public class ListFeaturesCommand extends
         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() );
+        }
+    }
+
 }