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 2015/04/14 14:33:21 UTC

karaf git commit: Fix completion for features:start and features:stop commands

Repository: karaf
Updated Branches:
  refs/heads/master 8c901d311 -> 0a3f500f4


Fix completion for features:start and features:stop commands

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

Branch: refs/heads/master
Commit: 0a3f500f438cedb70c12e1d5ee3c14f9620bbbc3
Parents: 8c901d3
Author: Guillaume Nodet <gn...@gmail.com>
Authored: Tue Apr 14 13:33:14 2015 +0200
Committer: Guillaume Nodet <gn...@gmail.com>
Committed: Tue Apr 14 13:33:14 2015 +0200

----------------------------------------------------------------------
 .../features/command/StartFeaturesCommand.java  |  7 ++--
 .../features/command/StopFeaturesCommand.java   |  5 ++-
 .../completers/FeatureCompleterSupport.java     |  7 +++-
 .../completers/ResolvedFeatureCompleter.java    | 40 ++++++++++++++++++++
 .../completers/StartedFeatureCompleter.java     | 40 ++++++++++++++++++++
 5 files changed, 92 insertions(+), 7 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/karaf/blob/0a3f500f/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 5660ab0..2d319ae 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
@@ -18,13 +18,12 @@ package org.apache.karaf.features.command;
 
 import java.util.EnumSet;
 import java.util.HashMap;
-import java.util.HashSet;
 import java.util.List;
 import java.util.Map;
 
 import org.apache.karaf.features.FeatureState;
 import org.apache.karaf.features.FeaturesService;
-import org.apache.karaf.features.command.completers.AvailableFeatureCompleter;
+import org.apache.karaf.features.command.completers.ResolvedFeatureCompleter;
 import org.apache.karaf.shell.api.action.Argument;
 import org.apache.karaf.shell.api.action.Command;
 import org.apache.karaf.shell.api.action.Completion;
@@ -35,8 +34,8 @@ import org.apache.karaf.shell.api.action.lifecycle.Service;
 @Service
 public class StartFeaturesCommand extends FeaturesCommandSupport {
 
-    @Argument(index = 0, name = "feature", description = "The name and version of the features to install. A feature id looks like name/version. The version is optional.", required = true, multiValued = true)
-    @Completion(AvailableFeatureCompleter.class)
+    @Argument(index = 0, name = "feature", description = "The name and version of the features to start. A feature id looks like name/version.", required = true, multiValued = true)
+    @Completion(ResolvedFeatureCompleter.class)
     List<String> features;
 
     @Option(name = "-v", aliases = "--verbose", description = "Explain what is being done", required = false, multiValued = false)

http://git-wip-us.apache.org/repos/asf/karaf/blob/0a3f500f/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 13ff618..b89adee 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
@@ -24,6 +24,7 @@ import java.util.Map;
 import org.apache.karaf.features.FeatureState;
 import org.apache.karaf.features.FeaturesService;
 import org.apache.karaf.features.command.completers.AvailableFeatureCompleter;
+import org.apache.karaf.features.command.completers.StartedFeatureCompleter;
 import org.apache.karaf.shell.api.action.Argument;
 import org.apache.karaf.shell.api.action.Command;
 import org.apache.karaf.shell.api.action.Completion;
@@ -34,8 +35,8 @@ import org.apache.karaf.shell.api.action.lifecycle.Service;
 @Service
 public class StopFeaturesCommand extends FeaturesCommandSupport {
 
-    @Argument(index = 0, name = "feature", description = "The name and version of the features to install. A feature id looks like name/version. The version is optional.", required = true, multiValued = true)
-    @Completion(AvailableFeatureCompleter.class)
+    @Argument(index = 0, name = "feature", description = "The name and version of the features to stop. A feature id looks like name/version.", required = true, multiValued = true)
+    @Completion(StartedFeatureCompleter.class)
     List<String> features;
 
     @Option(name = "-v", aliases = "--verbose", description = "Explain what is being done", required = false, multiValued = false)

http://git-wip-us.apache.org/repos/asf/karaf/blob/0a3f500f/features/command/src/main/java/org/apache/karaf/features/command/completers/FeatureCompleterSupport.java
----------------------------------------------------------------------
diff --git a/features/command/src/main/java/org/apache/karaf/features/command/completers/FeatureCompleterSupport.java b/features/command/src/main/java/org/apache/karaf/features/command/completers/FeatureCompleterSupport.java
index d01e5af..e4f9854 100644
--- a/features/command/src/main/java/org/apache/karaf/features/command/completers/FeatureCompleterSupport.java
+++ b/features/command/src/main/java/org/apache/karaf/features/command/completers/FeatureCompleterSupport.java
@@ -17,6 +17,7 @@
 package org.apache.karaf.features.command.completers;
 
 import java.util.List;
+import java.util.SortedSet;
 
 import org.apache.karaf.features.Feature;
 import org.apache.karaf.features.FeaturesService;
@@ -46,7 +47,7 @@ public abstract class FeatureCompleterSupport implements Completer {
         try {
             for (Feature feature : featuresService.listFeatures()) {
                 if (acceptsFeature(feature)) {
-                    delegate.getStrings().add(feature.getName());
+                    add(delegate.getStrings(), feature);
                 }
             }
         } catch (Exception e) {
@@ -55,6 +56,10 @@ public abstract class FeatureCompleterSupport implements Completer {
         return delegate.complete(session, commandLine, candidates);
     }
 
+    protected void add(SortedSet<String> candidates, Feature feature) {
+        candidates.add(feature.getName());
+    }
+
     /**
      * Method for filtering features.
      *

http://git-wip-us.apache.org/repos/asf/karaf/blob/0a3f500f/features/command/src/main/java/org/apache/karaf/features/command/completers/ResolvedFeatureCompleter.java
----------------------------------------------------------------------
diff --git a/features/command/src/main/java/org/apache/karaf/features/command/completers/ResolvedFeatureCompleter.java b/features/command/src/main/java/org/apache/karaf/features/command/completers/ResolvedFeatureCompleter.java
new file mode 100644
index 0000000..3bccda5
--- /dev/null
+++ b/features/command/src/main/java/org/apache/karaf/features/command/completers/ResolvedFeatureCompleter.java
@@ -0,0 +1,40 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.karaf.features.command.completers;
+
+import java.util.SortedSet;
+
+import org.apache.karaf.features.Feature;
+import org.apache.karaf.features.FeatureState;
+import org.apache.karaf.shell.api.action.lifecycle.Service;
+
+/**
+ * {@link org.apache.karaf.shell.api.console.Completer} for features not installed yet.
+ */
+@Service
+public class ResolvedFeatureCompleter extends FeatureCompleterSupport {
+
+    @Override
+    protected boolean acceptsFeature(Feature feature) {
+        return featuresService.getState(feature.getId()) == FeatureState.Resolved;
+    }
+
+    protected void add(SortedSet<String> candidates, Feature feature) {
+        candidates.add(feature.getId());
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/karaf/blob/0a3f500f/features/command/src/main/java/org/apache/karaf/features/command/completers/StartedFeatureCompleter.java
----------------------------------------------------------------------
diff --git a/features/command/src/main/java/org/apache/karaf/features/command/completers/StartedFeatureCompleter.java b/features/command/src/main/java/org/apache/karaf/features/command/completers/StartedFeatureCompleter.java
new file mode 100644
index 0000000..c04d25c
--- /dev/null
+++ b/features/command/src/main/java/org/apache/karaf/features/command/completers/StartedFeatureCompleter.java
@@ -0,0 +1,40 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.karaf.features.command.completers;
+
+import java.util.SortedSet;
+
+import org.apache.karaf.features.Feature;
+import org.apache.karaf.features.FeatureState;
+import org.apache.karaf.shell.api.action.lifecycle.Service;
+
+/**
+ * {@link org.apache.karaf.shell.api.console.Completer} for features not installed yet.
+ */
+@Service
+public class StartedFeatureCompleter extends FeatureCompleterSupport {
+
+    @Override
+    protected boolean acceptsFeature(Feature feature) {
+        return featuresService.getState(feature.getId()) == FeatureState.Started;
+    }
+
+    protected void add(SortedSet<String> candidates, Feature feature) {
+        candidates.add(feature.getId());
+    }
+
+}