You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@karaf.apache.org by cs...@apache.org on 2015/04/14 17:27:52 UTC

[2/2] karaf git commit: [KARAF-2952] Add support for plain feature names and error handling in feature:stop and start

[KARAF-2952] Add support for plain feature names and error handling in feature:stop and start


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

Branch: refs/heads/master
Commit: 02684347939bfe2f8f8ae9061f711696a8e6a1fb
Parents: 2dbb490
Author: Christian Schneider <ch...@die-schneider.net>
Authored: Tue Apr 14 17:27:31 2015 +0200
Committer: Christian Schneider <ch...@die-schneider.net>
Committed: Tue Apr 14 17:27:31 2015 +0200

----------------------------------------------------------------------
 .../karaf/features/command/FeaturesCommandSupport.java  | 12 ++++++++++++
 .../karaf/features/command/StartFeaturesCommand.java    |  9 +++------
 .../karaf/features/command/StopFeaturesCommand.java     |  7 +++++--
 3 files changed, 20 insertions(+), 8 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/karaf/blob/02684347/features/command/src/main/java/org/apache/karaf/features/command/FeaturesCommandSupport.java
----------------------------------------------------------------------
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 61e4d4f..f015237 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
@@ -18,6 +18,7 @@ package org.apache.karaf.features.command;
 
 import java.util.EnumSet;
 
+import org.apache.karaf.features.Feature;
 import org.apache.karaf.features.FeaturesService;
 import org.apache.karaf.shell.api.action.Action;
 import org.apache.karaf.shell.api.action.lifecycle.Reference;
@@ -48,4 +49,15 @@ public abstract class FeaturesCommandSupport implements Action {
             options.add(option);
         }
     }
+    
+    protected String getFeatureId(FeaturesService admin, String featureName) throws Exception {
+        Feature[] matchingFeatures = admin.getFeatures(featureName);
+        if (matchingFeatures.length == 0) {
+            throw new IllegalArgumentException("No matching feature found for " + featureName);
+        }
+        if (matchingFeatures.length > 1) {
+            throw new IllegalArgumentException("More than one matching feature found for " + featureName);
+        }
+        return matchingFeatures[0].getId();
+    }
 }

http://git-wip-us.apache.org/repos/asf/karaf/blob/02684347/features/command/src/main/java/org/apache/karaf/features/command/StartFeaturesCommand.java
----------------------------------------------------------------------
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 a0e11b8..2200aa0 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
@@ -49,14 +49,11 @@ public class StartFeaturesCommand extends FeaturesCommandSupport {
     protected void doExecute(FeaturesService admin) throws Exception {
         addOption(FeaturesService.Option.Simulate, simulate);
         addOption(FeaturesService.Option.Verbose, verbose);
-        setFeaturesToStatus(admin);
-    }
-
-    private void setFeaturesToStatus(FeaturesService admin) throws Exception {
         Map<String, Map<String, FeatureState>> stateChanges = new HashMap<>();
         Map<String, FeatureState> regionChanges = new HashMap<>();
-        for (String feature : features) {
-            regionChanges.put(feature, FeatureState.Started);
+        for (String featureName : features) {
+            String featureId = getFeatureId(admin, featureName);
+            regionChanges.put(featureId, FeatureState.Started);
         }
         stateChanges.put(region, regionChanges);
         admin.updateFeaturesState(stateChanges, options);

http://git-wip-us.apache.org/repos/asf/karaf/blob/02684347/features/command/src/main/java/org/apache/karaf/features/command/StopFeaturesCommand.java
----------------------------------------------------------------------
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 ab23d32..371e03c 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
@@ -20,6 +20,7 @@ import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
 
+import org.apache.karaf.features.Feature;
 import org.apache.karaf.features.FeatureState;
 import org.apache.karaf.features.FeaturesService;
 import org.apache.karaf.features.command.completers.StartedFeatureCompleter;
@@ -51,10 +52,12 @@ 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 feature : features) {
-            regionChanges.put(feature, FeatureState.Resolved);
+        for (String featureName : features) {
+            String featureId = getFeatureId(admin, featureName);
+            regionChanges.put(featureId, FeatureState.Resolved);
         }
         stateChanges.put(region, regionChanges);
         admin.updateFeaturesState(stateChanges, options);
     }
+
 }