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 2017/10/26 09:15:50 UTC

[karaf] branch master updated: [KARAF-5443] Add a completer for bundle symbolic names

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


The following commit(s) were added to refs/heads/master by this push:
     new fdc0397  [KARAF-5443] Add a completer for bundle symbolic names
fdc0397 is described below

commit fdc03979edc424ad7601bf7563b33c7a9b508a1b
Author: Guillaume Nodet <gn...@gmail.com>
AuthorDate: Thu Oct 26 11:15:24 2017 +0200

    [KARAF-5443] Add a completer for bundle symbolic names
---
 .../apache/karaf/bundle/command/BundleCommand.java |  3 ++
 .../karaf/bundle/command/BundlesCommand.java       |  3 ++
 .../completers/BundleSymbolicNameCompleter.java    | 54 ++++++++++++++++++++++
 3 files changed, 60 insertions(+)

diff --git a/bundle/core/src/main/java/org/apache/karaf/bundle/command/BundleCommand.java b/bundle/core/src/main/java/org/apache/karaf/bundle/command/BundleCommand.java
index acca105..aa94600 100644
--- a/bundle/core/src/main/java/org/apache/karaf/bundle/command/BundleCommand.java
+++ b/bundle/core/src/main/java/org/apache/karaf/bundle/command/BundleCommand.java
@@ -16,9 +16,11 @@
  */
 package org.apache.karaf.bundle.command;
 
+import org.apache.karaf.bundle.command.completers.BundleSymbolicNameCompleter;
 import org.apache.karaf.bundle.core.BundleService;
 import org.apache.karaf.shell.api.action.Action;
 import org.apache.karaf.shell.api.action.Argument;
+import org.apache.karaf.shell.api.action.Completion;
 import org.apache.karaf.shell.api.action.Option;
 import org.apache.karaf.shell.api.action.lifecycle.Reference;
 import org.osgi.framework.Bundle;
@@ -33,6 +35,7 @@ public abstract class BundleCommand implements Action {
     String context = "0";
 
     @Argument(index = 0, name = "id", description = "The bundle ID or name or name/version", required = true, multiValued = false)
+    @Completion(BundleSymbolicNameCompleter.class)
     String id;
 
     @Reference
diff --git a/bundle/core/src/main/java/org/apache/karaf/bundle/command/BundlesCommand.java b/bundle/core/src/main/java/org/apache/karaf/bundle/command/BundlesCommand.java
index 029c144..e9c3a9c 100644
--- a/bundle/core/src/main/java/org/apache/karaf/bundle/command/BundlesCommand.java
+++ b/bundle/core/src/main/java/org/apache/karaf/bundle/command/BundlesCommand.java
@@ -19,9 +19,11 @@ package org.apache.karaf.bundle.command;
 import java.util.ArrayList;
 import java.util.List;
 
+import org.apache.karaf.bundle.command.completers.BundleSymbolicNameCompleter;
 import org.apache.karaf.bundle.core.BundleService;
 import org.apache.karaf.shell.api.action.Action;
 import org.apache.karaf.shell.api.action.Argument;
+import org.apache.karaf.shell.api.action.Completion;
 import org.apache.karaf.shell.api.action.Option;
 import org.apache.karaf.shell.api.action.lifecycle.Reference;
 import org.apache.karaf.shell.support.MultiException;
@@ -34,6 +36,7 @@ public abstract class BundlesCommand implements Action {
     String context = "0";
 
     @Argument(index = 0, name = "ids", description = "The list of bundle (identified by IDs or name or name/version) separated by whitespaces", required = false, multiValued = true)
+    @Completion(BundleSymbolicNameCompleter.class)
     List<String> ids;
     
     @Reference
diff --git a/bundle/core/src/main/java/org/apache/karaf/bundle/command/completers/BundleSymbolicNameCompleter.java b/bundle/core/src/main/java/org/apache/karaf/bundle/command/completers/BundleSymbolicNameCompleter.java
new file mode 100644
index 0000000..c0b56f7
--- /dev/null
+++ b/bundle/core/src/main/java/org/apache/karaf/bundle/command/completers/BundleSymbolicNameCompleter.java
@@ -0,0 +1,54 @@
+/*
+ * 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.bundle.command.completers;
+
+import org.apache.karaf.shell.api.action.lifecycle.Reference;
+import org.apache.karaf.shell.api.action.lifecycle.Service;
+import org.apache.karaf.shell.api.console.Candidate;
+import org.apache.karaf.shell.api.console.CommandLine;
+import org.apache.karaf.shell.api.console.Completer;
+import org.apache.karaf.shell.api.console.Session;
+import org.osgi.framework.Bundle;
+import org.osgi.framework.BundleContext;
+
+import java.util.ArrayList;
+import java.util.List;
+
+@Service
+public class BundleSymbolicNameCompleter implements Completer {
+
+    @Reference
+    private BundleContext bundleContext;
+
+    @Override
+    public int complete(Session session, CommandLine commandLine, List<String> candidates) {
+        List<Candidate> cands = new ArrayList<>();
+        completeCandidates(session, commandLine, cands);
+        for (Candidate cand : cands) {
+            candidates.add(cand.value());
+        }
+        return candidates.isEmpty() ? -1 : 0;
+    }
+
+    @Override
+    public void completeCandidates(Session session, CommandLine commandLine, List<Candidate> candidates) {
+        for (Bundle bundle : bundleContext.getBundles()) {
+            candidates.add(new Candidate(bundle.getSymbolicName(), true));
+        }
+    }
+
+}

-- 
To stop receiving notification emails like this one, please contact
['"commits@karaf.apache.org" <co...@karaf.apache.org>'].