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 2014/07/17 05:18:08 UTC
git commit: [KARAF-3126]add more specific completer for
admin:start|stop command
Repository: karaf
Updated Branches:
refs/heads/karaf-2.x ffa0e42e5 -> 44af35c8e
[KARAF-3126]add more specific completer for admin:start|stop command
Project: http://git-wip-us.apache.org/repos/asf/karaf/repo
Commit: http://git-wip-us.apache.org/repos/asf/karaf/commit/44af35c8
Tree: http://git-wip-us.apache.org/repos/asf/karaf/tree/44af35c8
Diff: http://git-wip-us.apache.org/repos/asf/karaf/diff/44af35c8
Branch: refs/heads/karaf-2.x
Commit: 44af35c8ef6be7a577a3ceed487029b683e4de6d
Parents: ffa0e42
Author: Freeman Fang <fr...@gmail.com>
Authored: Thu Jul 17 11:17:54 2014 +0800
Committer: Freeman Fang <fr...@gmail.com>
Committed: Thu Jul 17 11:17:54 2014 +0800
----------------------------------------------------------------------
.../command/completers/InstanceCompleter.java | 8 ++++-
.../completers/StartedInstanceCompleter.java | 35 +++++++++++++++++++
.../completers/StoppedInstanceCompleter.java | 36 ++++++++++++++++++++
.../OSGI-INF/blueprint/admin-command.xml | 12 +++++--
4 files changed, 88 insertions(+), 3 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/karaf/blob/44af35c8/admin/command/src/main/java/org/apache/karaf/admin/command/completers/InstanceCompleter.java
----------------------------------------------------------------------
diff --git a/admin/command/src/main/java/org/apache/karaf/admin/command/completers/InstanceCompleter.java b/admin/command/src/main/java/org/apache/karaf/admin/command/completers/InstanceCompleter.java
index c894da9..7addde4 100644
--- a/admin/command/src/main/java/org/apache/karaf/admin/command/completers/InstanceCompleter.java
+++ b/admin/command/src/main/java/org/apache/karaf/admin/command/completers/InstanceCompleter.java
@@ -39,8 +39,14 @@ public class InstanceCompleter implements Completer {
public int complete(String buffer, int cursor, List candidates) {
StringsCompleter delegate = new StringsCompleter();
for (Instance instance : adminService.getInstances()) {
- delegate.getStrings().add(instance.getName());
+ if (acceptsInstance(instance)) {
+ delegate.getStrings().add(instance.getName());
+ }
}
return delegate.complete(buffer, cursor, candidates);
}
+
+ protected boolean acceptsInstance(Instance instance) {
+ return true;
+ }
}
http://git-wip-us.apache.org/repos/asf/karaf/blob/44af35c8/admin/command/src/main/java/org/apache/karaf/admin/command/completers/StartedInstanceCompleter.java
----------------------------------------------------------------------
diff --git a/admin/command/src/main/java/org/apache/karaf/admin/command/completers/StartedInstanceCompleter.java b/admin/command/src/main/java/org/apache/karaf/admin/command/completers/StartedInstanceCompleter.java
new file mode 100644
index 0000000..1462bf6
--- /dev/null
+++ b/admin/command/src/main/java/org/apache/karaf/admin/command/completers/StartedInstanceCompleter.java
@@ -0,0 +1,35 @@
+/*
+ * 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.admin.command.completers;
+
+import org.apache.karaf.admin.Instance;
+
+public class StartedInstanceCompleter extends InstanceCompleter {
+
+ protected boolean acceptsInstance(Instance instance) {
+ try {
+ if (instance.getState().equals(Instance.STARTED)) {
+ return true;
+ } else {
+ return false;
+ }
+ } catch (Exception e) {
+ return false;
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/karaf/blob/44af35c8/admin/command/src/main/java/org/apache/karaf/admin/command/completers/StoppedInstanceCompleter.java
----------------------------------------------------------------------
diff --git a/admin/command/src/main/java/org/apache/karaf/admin/command/completers/StoppedInstanceCompleter.java b/admin/command/src/main/java/org/apache/karaf/admin/command/completers/StoppedInstanceCompleter.java
new file mode 100644
index 0000000..0e90911
--- /dev/null
+++ b/admin/command/src/main/java/org/apache/karaf/admin/command/completers/StoppedInstanceCompleter.java
@@ -0,0 +1,36 @@
+/*
+ * 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.admin.command.completers;
+
+import org.apache.karaf.admin.Instance;
+
+public class StoppedInstanceCompleter extends InstanceCompleter {
+
+ protected boolean acceptsInstance(Instance instance) {
+ try {
+ if (instance.getState().equals(Instance.STOPPED)) {
+ return true;
+ } else {
+ return false;
+ }
+ } catch (Exception e) {
+ return false;
+ }
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/karaf/blob/44af35c8/admin/command/src/main/resources/OSGI-INF/blueprint/admin-command.xml
----------------------------------------------------------------------
diff --git a/admin/command/src/main/resources/OSGI-INF/blueprint/admin-command.xml b/admin/command/src/main/resources/OSGI-INF/blueprint/admin-command.xml
index 951bbe5..c4e404a 100644
--- a/admin/command/src/main/resources/OSGI-INF/blueprint/admin-command.xml
+++ b/admin/command/src/main/resources/OSGI-INF/blueprint/admin-command.xml
@@ -49,7 +49,7 @@
<property name="adminService" ref="adminService" />
</action>
<completers>
- <ref component-id="instanceCompleter" />
+ <ref component-id="stoppedInstanceCompleter" />
<null/>
</completers>
</command>
@@ -58,7 +58,7 @@
<property name="adminService" ref="adminService" />
</action>
<completers>
- <ref component-id="instanceCompleter" />
+ <ref component-id="startedInstanceCompleter" />
<null/>
</completers>
</command>
@@ -143,6 +143,14 @@
<property name="adminService" ref="adminService" />
</bean>
+ <bean id="stoppedInstanceCompleter" class="org.apache.karaf.admin.command.completers.StoppedInstanceCompleter">
+ <property name="adminService" ref="adminService" />
+ </bean>
+
+ <bean id="startedInstanceCompleter" class="org.apache.karaf.admin.command.completers.StartedInstanceCompleter">
+ <property name="adminService" ref="adminService" />
+ </bean>
+
<bean id="allFeatureCompleter" class="org.apache.karaf.features.command.completers.AllFeatureCompleter">
<property name="featuresService" ref="featuresService" />
</bean>