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 2016/05/09 14:48:26 UTC

[07/35] karaf-boot git commit: Add shell command support

Add shell command support


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

Branch: refs/heads/master
Commit: 1683f3c21489fd97eae4c5244cd65fe2f2e55c6a
Parents: 8757712
Author: Jean-Baptiste Onofr� <jb...@apache.org>
Authored: Tue Sep 29 15:38:51 2015 +0200
Committer: Jean-Baptiste Onofr� <jb...@apache.org>
Committed: Tue Sep 29 15:38:51 2015 +0200

----------------------------------------------------------------------
 .../README.md                                   |  5 +-
 .../README.md                                   |  2 +
 .../karaf-boot-sample-shell/README.md           | 38 ++++++++++++++
 .../karaf-boot-sample-shell/pom.xml             | 53 ++++++++++++++++++++
 .../main/java/sample/shell/HelloCommand.java    | 47 +++++++++++++++++
 .../karaf-boot-starter-shell/pom.xml            | 41 +++++++++++++++
 karaf-boot-starters/pom.xml                     |  1 +
 pom.xml                                         |  1 +
 8 files changed, 187 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/karaf-boot/blob/1683f3c2/karaf-boot-samples/karaf-boot-sample-service-consumer-ds/README.md
----------------------------------------------------------------------
diff --git a/karaf-boot-samples/karaf-boot-sample-service-consumer-ds/README.md b/karaf-boot-samples/karaf-boot-sample-service-consumer-ds/README.md
index 93f69f7..f1f6370 100644
--- a/karaf-boot-samples/karaf-boot-sample-service-consumer-ds/README.md
+++ b/karaf-boot-samples/karaf-boot-sample-service-consumer-ds/README.md
@@ -24,7 +24,10 @@ To deploy in Karaf, you have to enable the DS support first. For that, you have
 
   feature:install scr
 
-Once scr feature installed:
+Once scr feature installed, you have to install a hello service provider. Please use any of karaf-boot-sample-service-provider-*
+deployment first.
+
+Once the service provider is installed:
 
 * you can drop the generated jar file (target/karaf-boot-sample-service-consumer-ds-1.0.jar) in the
 Karaf deploy folder

http://git-wip-us.apache.org/repos/asf/karaf-boot/blob/1683f3c2/karaf-boot-samples/karaf-boot-sample-service-consumer-osgi/README.md
----------------------------------------------------------------------
diff --git a/karaf-boot-samples/karaf-boot-sample-service-consumer-osgi/README.md b/karaf-boot-samples/karaf-boot-sample-service-consumer-osgi/README.md
index 1684c81..02523d8 100644
--- a/karaf-boot-samples/karaf-boot-sample-service-consumer-osgi/README.md
+++ b/karaf-boot-samples/karaf-boot-sample-service-consumer-osgi/README.md
@@ -19,6 +19,8 @@ To build, simply do:
 
 = Deploy
 
+You have to install a hello service provider first. Please deploy the karaf-boot-sample-service-provider-osgi first.
+
 To deploy in Karaf:
 
 * you can drop the generated jar file (target/karaf-boot-sample-service-provider-osgi-1.0.jar) in the

http://git-wip-us.apache.org/repos/asf/karaf-boot/blob/1683f3c2/karaf-boot-samples/karaf-boot-sample-shell/README.md
----------------------------------------------------------------------
diff --git a/karaf-boot-samples/karaf-boot-sample-shell/README.md b/karaf-boot-samples/karaf-boot-sample-shell/README.md
new file mode 100644
index 0000000..5c9e40b
--- /dev/null
+++ b/karaf-boot-samples/karaf-boot-sample-shell/README.md
@@ -0,0 +1,38 @@
+== karaf-boot-sample-shell ==
+
+This sample provides new shell command in the Karaf shell console, that uses the hello service, provided by another
+artifact (as karaf-boot-sample-service-provider-ds for instance).
+
+= Design
+
+The shell commands are exposed using the Karaf shell annotations.
+
+A command is basically a class implementing Action interface, and we use @Service, @Command, @Argument, @Option Karaf
+shell annotations.
+
+The @Reference annotation uses the hello service.
+
+= Build
+
+To build, simply do:
+
+  mvn clean install
+
+= Deploy
+
+You have to install a hello service provider first. Please deploy karaf-boot-sample-service-provider-ds first.
+
+To deploy in Karaf:
+
+* you can drop the generated jar file (target/karaf-boot-sample-shell-1.0.jar) in the
+Karaf deploy folder
+* in the Karaf shell console, do:
+
+  bundle:install -s mvn:karaf-boot-samples/karaf-boot-sample-shell/1.0
+
+= Usage
+
+Once deployed, you can use the sample:hello command like:
+
+karaf@root()> sample:hello world
+Hello world !

http://git-wip-us.apache.org/repos/asf/karaf-boot/blob/1683f3c2/karaf-boot-samples/karaf-boot-sample-shell/pom.xml
----------------------------------------------------------------------
diff --git a/karaf-boot-samples/karaf-boot-sample-shell/pom.xml b/karaf-boot-samples/karaf-boot-sample-shell/pom.xml
new file mode 100644
index 0000000..1df8632
--- /dev/null
+++ b/karaf-boot-samples/karaf-boot-sample-shell/pom.xml
@@ -0,0 +1,53 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+
+    <!--
+
+        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.
+    -->
+
+    <modelVersion>4.0.0</modelVersion>
+
+    <groupId>org.apache.karaf.boot</groupId>
+    <artifactId>karaf-boot-sample-shell</artifactId>
+    <version>1.0.0-SNAPSHOT</version>
+
+    <dependencies>
+        <dependency>
+            <groupId>org.apache.karaf.boot</groupId>
+            <artifactId>karaf-boot-starter-shell</artifactId>
+            <version>${project.version}</version>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.karaf.boot</groupId>
+            <artifactId>karaf-boot-sample-service-provider-ds</artifactId>
+            <version>${project.version}</version>
+        </dependency>
+    </dependencies>
+
+    <build>
+        <plugins>
+            <plugin>
+                <groupId>org.apache.karaf.boot</groupId>
+                <artifactId>karaf-boot-maven-plugin</artifactId>
+                <version>${project.version}</version>
+                <inherited>true</inherited>
+                <extensions>true</extensions>
+            </plugin>
+        </plugins>
+    </build>
+
+</project>
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/karaf-boot/blob/1683f3c2/karaf-boot-samples/karaf-boot-sample-shell/src/main/java/sample/shell/HelloCommand.java
----------------------------------------------------------------------
diff --git a/karaf-boot-samples/karaf-boot-sample-shell/src/main/java/sample/shell/HelloCommand.java b/karaf-boot-samples/karaf-boot-sample-shell/src/main/java/sample/shell/HelloCommand.java
new file mode 100644
index 0000000..eb4a730
--- /dev/null
+++ b/karaf-boot-samples/karaf-boot-sample-shell/src/main/java/sample/shell/HelloCommand.java
@@ -0,0 +1,47 @@
+/**
+ *  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 sample.shell;
+
+import org.apache.karaf.shell.api.action.Action;
+import org.apache.karaf.shell.api.action.Argument;
+import org.apache.karaf.shell.api.action.Command;
+import org.apache.karaf.shell.api.action.Option;
+import org.apache.karaf.shell.api.action.lifecycle.Reference;
+import org.apache.karaf.shell.api.action.lifecycle.Service;
+import sample.ds.service.provider.HelloService;
+
+@Service
+@Command(scope = "sample", name = "hello", description = "The hello command")
+public class HelloCommand implements Action {
+
+    @Reference
+    public HelloService helloService;
+
+    @Argument(index = 0, name = "arg", description = "This is the message argument", required = true, multiValued = false)
+    public String arg;
+
+    @Option(name = "opt", description = "This is an option", required = false, multiValued = false)
+    public String opt;
+
+    public Object execute() throws Exception {
+        if (opt != null)
+            System.out.println("Opt is " + opt);
+        System.out.println(helloService.hello(arg));
+        return null;
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/karaf-boot/blob/1683f3c2/karaf-boot-starters/karaf-boot-starter-shell/pom.xml
----------------------------------------------------------------------
diff --git a/karaf-boot-starters/karaf-boot-starter-shell/pom.xml b/karaf-boot-starters/karaf-boot-starter-shell/pom.xml
new file mode 100644
index 0000000..4c413a8
--- /dev/null
+++ b/karaf-boot-starters/karaf-boot-starter-shell/pom.xml
@@ -0,0 +1,41 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+
+    <!--
+
+        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.
+    -->
+
+    <modelVersion>4.0.0</modelVersion>
+
+    <parent>
+        <groupId>org.apache.karaf.boot</groupId>
+        <artifactId>karaf-boot-starters</artifactId>
+        <version>1.0.0-SNAPSHOT</version>
+        <relativePath>../pom.xml</relativePath>
+    </parent>
+
+    <artifactId>karaf-boot-starter-shell</artifactId>
+
+    <dependencies>
+        <dependency>
+            <groupId>org.apache.karaf.shell</groupId>
+            <artifactId>org.apache.karaf.shell.core</artifactId>
+            <version>${karaf.version}</version>
+        </dependency>
+    </dependencies>
+
+</project>
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/karaf-boot/blob/1683f3c2/karaf-boot-starters/pom.xml
----------------------------------------------------------------------
diff --git a/karaf-boot-starters/pom.xml b/karaf-boot-starters/pom.xml
index 04f6ff4..379f140 100644
--- a/karaf-boot-starters/pom.xml
+++ b/karaf-boot-starters/pom.xml
@@ -34,6 +34,7 @@
     <modules>
         <module>karaf-boot-starter</module>
         <module>karaf-boot-starter-ds</module>
+        <module>karaf-boot-starter-shell</module>
     </modules>
 
 </project>
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/karaf-boot/blob/1683f3c2/pom.xml
----------------------------------------------------------------------
diff --git a/pom.xml b/pom.xml
index 3650256..cb5e826 100644
--- a/pom.xml
+++ b/pom.xml
@@ -48,6 +48,7 @@
         <!-- blueprint -->
         <!-- cdi -->
         <!-- shell -->
+        <module>karaf-boot-samples/karaf-boot-sample-shell</module>
         <!-- config -->
         <!-- jpa -->
         <!-- servlet -->