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 2018/04/12 16:12:33 UTC

[karaf] 01/02: [KARAF-5697] feature:start and feature:stop should be able to select multiple features

This is an automated email from the ASF dual-hosted git repository.

gnodet pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/karaf.git

commit 94b9534045f34a1ec96d4cd543e959cf15cfe9f6
Author: Guillaume Nodet <gn...@gmail.com>
AuthorDate: Thu Apr 12 17:20:41 2018 +0200

    [KARAF-5697] feature:start and feature:stop should be able to select multiple features
---
 .../karaf/features/command/FeaturesCommandSupport.java  | 17 ++++++++++++++---
 .../karaf/features/command/StartFeaturesCommand.java    |  3 +--
 .../karaf/features/command/StopFeaturesCommand.java     |  3 +--
 3 files changed, 16 insertions(+), 7 deletions(-)

diff --git a/features/command/src/main/java/org/apache/karaf/features/command/FeaturesCommandSupport.java b/features/command/src/main/java/org/apache/karaf/features/command/FeaturesCommandSupport.java
index 3efe67a..e7f6a84 100644
--- a/features/command/src/main/java/org/apache/karaf/features/command/FeaturesCommandSupport.java
+++ b/features/command/src/main/java/org/apache/karaf/features/command/FeaturesCommandSupport.java
@@ -17,9 +17,7 @@
 package org.apache.karaf.features.command;
 
 import java.net.URI;
-import java.util.EnumSet;
-import java.util.LinkedHashSet;
-import java.util.Set;
+import java.util.*;
 import java.util.regex.Pattern;
 
 import org.apache.karaf.features.Feature;
@@ -86,4 +84,17 @@ public abstract class FeaturesCommandSupport implements Action {
         }
         return matchingFeatures[0].getId();
     }
+
+    protected List<String> getFeatureIds(FeaturesService admin, List<String> nameOrIds) throws Exception {
+        List<String> ids = new ArrayList<>();
+        for (String nameOrId : nameOrIds) {
+            for (Feature f : admin.getFeatures(nameOrId)) {
+                ids.add(f.getId());
+            }
+        }
+        if (ids.isEmpty()) {
+            throw new IllegalArgumentException("No matching feature found for " + nameOrIds);
+        }
+        return ids;
+    }
 }
diff --git a/features/command/src/main/java/org/apache/karaf/features/command/StartFeaturesCommand.java b/features/command/src/main/java/org/apache/karaf/features/command/StartFeaturesCommand.java
index 2200aa0..7e86b82 100644
--- a/features/command/src/main/java/org/apache/karaf/features/command/StartFeaturesCommand.java
+++ b/features/command/src/main/java/org/apache/karaf/features/command/StartFeaturesCommand.java
@@ -51,8 +51,7 @@ public class StartFeaturesCommand extends FeaturesCommandSupport {
         addOption(FeaturesService.Option.Verbose, verbose);
         Map<String, Map<String, FeatureState>> stateChanges = new HashMap<>();
         Map<String, FeatureState> regionChanges = new HashMap<>();
-        for (String featureName : features) {
-            String featureId = getFeatureId(admin, featureName);
+        for (String featureId : getFeatureIds(admin, features)) {
             regionChanges.put(featureId, FeatureState.Started);
         }
         stateChanges.put(region, regionChanges);
diff --git a/features/command/src/main/java/org/apache/karaf/features/command/StopFeaturesCommand.java b/features/command/src/main/java/org/apache/karaf/features/command/StopFeaturesCommand.java
index f58ea50..cf7b397 100644
--- a/features/command/src/main/java/org/apache/karaf/features/command/StopFeaturesCommand.java
+++ b/features/command/src/main/java/org/apache/karaf/features/command/StopFeaturesCommand.java
@@ -51,8 +51,7 @@ public class StopFeaturesCommand extends FeaturesCommandSupport {
         addOption(FeaturesService.Option.Verbose, verbose);
         Map<String, Map<String, FeatureState>> stateChanges = new HashMap<>();
         Map<String, FeatureState> regionChanges = new HashMap<>();
-        for (String featureName : features) {
-            String featureId = getFeatureId(admin, featureName);
+        for (String featureId : getFeatureIds(admin, features)) {
             regionChanges.put(featureId, FeatureState.Resolved);
         }
         stateChanges.put(region, regionChanges);

-- 
To stop receiving notification emails like this one, please contact
gnodet@apache.org.