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 2014/02/18 13:50:29 UTC
git commit: [KARAF-2763] Fix demo and manual
Repository: karaf
Updated Branches:
refs/heads/master 698c1398e -> 672159b68
[KARAF-2763] Fix demo and manual
Project: http://git-wip-us.apache.org/repos/asf/karaf/repo
Commit: http://git-wip-us.apache.org/repos/asf/karaf/commit/672159b6
Tree: http://git-wip-us.apache.org/repos/asf/karaf/tree/672159b6
Diff: http://git-wip-us.apache.org/repos/asf/karaf/diff/672159b6
Branch: refs/heads/master
Commit: 672159b6868f3dea5d8a7b95d5ac1567104da5fc
Parents: 698c139
Author: Guillaume Nodet <gn...@gmail.com>
Authored: Tue Feb 18 13:50:48 2014 +0100
Committer: Guillaume Nodet <gn...@gmail.com>
Committed: Tue Feb 18 13:50:48 2014 +0100
----------------------------------------------------------------------
demos/command/pom.xml | 1 +
.../apache/karaf/demos/command/MyCommand.java | 4 ++
.../apache/karaf/demos/command/MyCompleter.java | 2 +
.../resources/OSGI-INF/blueprint/mycommand.xml | 8 ++++
.../main/webapp/developers-guide/extending.conf | 49 +++++++++++++++-----
5 files changed, 52 insertions(+), 12 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/karaf/blob/672159b6/demos/command/pom.xml
----------------------------------------------------------------------
diff --git a/demos/command/pom.xml b/demos/command/pom.xml
index a3ab6d2..e5d9e2b 100644
--- a/demos/command/pom.xml
+++ b/demos/command/pom.xml
@@ -71,6 +71,7 @@
org.apache.felix.service.command,
org.apache.karaf.shell.commands,
org.apache.karaf.shell.console,
+ org.apache.karaf.shell.inject,
*
</Import-Package>
</instructions>
http://git-wip-us.apache.org/repos/asf/karaf/blob/672159b6/demos/command/src/main/java/org/apache/karaf/demos/command/MyCommand.java
----------------------------------------------------------------------
diff --git a/demos/command/src/main/java/org/apache/karaf/demos/command/MyCommand.java b/demos/command/src/main/java/org/apache/karaf/demos/command/MyCommand.java
index 4e143d7..fb37705 100644
--- a/demos/command/src/main/java/org/apache/karaf/demos/command/MyCommand.java
+++ b/demos/command/src/main/java/org/apache/karaf/demos/command/MyCommand.java
@@ -21,12 +21,16 @@ package org.apache.karaf.demos.command;
import org.apache.karaf.shell.commands.Command;
import org.apache.karaf.shell.commands.Argument;
+import org.apache.karaf.shell.commands.Completer;
import org.apache.karaf.shell.console.OsgiCommandSupport;
+import org.apache.karaf.shell.inject.Service;
@Command(scope = "mycommand", name = "hello", description="Says hello")
+@Service
public class MyCommand extends OsgiCommandSupport {
@Argument(index = 0, name = "arg", description = "The command argument", required = false, multiValued = false)
+ @Completer(MyCompleter.class)
String arg = null;
@Override
http://git-wip-us.apache.org/repos/asf/karaf/blob/672159b6/demos/command/src/main/java/org/apache/karaf/demos/command/MyCompleter.java
----------------------------------------------------------------------
diff --git a/demos/command/src/main/java/org/apache/karaf/demos/command/MyCompleter.java b/demos/command/src/main/java/org/apache/karaf/demos/command/MyCompleter.java
index 0c18e01..ba45232 100644
--- a/demos/command/src/main/java/org/apache/karaf/demos/command/MyCompleter.java
+++ b/demos/command/src/main/java/org/apache/karaf/demos/command/MyCompleter.java
@@ -21,6 +21,7 @@ package org.apache.karaf.demos.command;
import org.apache.karaf.shell.console.completer.StringsCompleter;
import org.apache.karaf.shell.console.Completer;
+import org.apache.karaf.shell.inject.Service;
import java.util.List;
@@ -30,6 +31,7 @@ import java.util.List;
* </p>
*/
+@Service
public class MyCompleter implements Completer {
/**
http://git-wip-us.apache.org/repos/asf/karaf/blob/672159b6/demos/command/src/main/resources/OSGI-INF/blueprint/mycommand.xml
----------------------------------------------------------------------
diff --git a/demos/command/src/main/resources/OSGI-INF/blueprint/mycommand.xml b/demos/command/src/main/resources/OSGI-INF/blueprint/mycommand.xml
index b74f6cd..66709b8 100644
--- a/demos/command/src/main/resources/OSGI-INF/blueprint/mycommand.xml
+++ b/demos/command/src/main/resources/OSGI-INF/blueprint/mycommand.xml
@@ -20,6 +20,13 @@
<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0">
+ <command-bundle xmlns="http://karaf.apache.org/xmlns/shell/v1.2.0"
+ scan="org.apache.karaf.demos.command" />
+
+ <!-- Old style way of declaring commands
+ This may be needed for actions that need complicated injections
+ based on blueprint.
+
<command-bundle xmlns="http://karaf.apache.org/xmlns/shell/v1.1.0">
<command>
<action class="org.apache.karaf.demos.command.MyCommand"/>
@@ -31,5 +38,6 @@
</command-bundle>
<bean id="myCompleter" class="org.apache.karaf.demos.command.MyCompleter"/>
+ -->
</blueprint>
http://git-wip-us.apache.org/repos/asf/karaf/blob/672159b6/manual/src/main/webapp/developers-guide/extending.conf
----------------------------------------------------------------------
diff --git a/manual/src/main/webapp/developers-guide/extending.conf b/manual/src/main/webapp/developers-guide/extending.conf
index 8fa46c8..6a762a0 100644
--- a/manual/src/main/webapp/developers-guide/extending.conf
+++ b/manual/src/main/webapp/developers-guide/extending.conf
@@ -140,10 +140,12 @@ We can now create the command class {{HelloShellCommand.java}}
{code:lang=java}
package org.apache.karaf.shell.samples;
-import Command;
+import org.apache.karaf.shell.commands.Command;
import org.apache.karaf.shell.console.OsgiCommandSupport;
+import org.apache.karaf.shell.inject.Service;
@Command(scope = "test", name = "hello", description="Says hello")
+@Service
public class HelloShellCommand extends OsgiCommandSupport {
@Override
@@ -172,10 +174,23 @@ Then, re-generate the IDE project files and reload it so that this folder is now
Inside this directory, create the {{OSGI-INF/blueprint/}} directory and put the following file inside (the name of this file has no impact at all):
+For simple cases as above, or even if you only need to inject an OSGi service, you can use the auto-detecting feature provided by the blueprint namespace handler:
+
+{code:lang=xml}
+<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0">
+
+ <command-bundle xmlns="http://karaf.apache.org/xmlns/shell/v1.2.0"
+ scan="org.apache.karaf.shell.samples" />
+
+</blueprint>
+{code}
+
+Alternatively, if you need more control over the wiring, you can declare the command explicitely:
+
{code:lang=xml}
<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0">
- <command-bundle xmlns="http://karaf.apache.org/xmlns/shell/v1.1.0">
+ <command-bundle xmlns="http://karaf.apache.org/xmlns/shell/v1.2.0">
<command>
<action class="org.apache.karaf.shell.samples.HelloShellCommand"/>
</command>
@@ -228,14 +243,18 @@ We add an argument to the HelloCommand:
{code:lang=java}
package org.apache.karaf.shell.samples;
-import Command;
-import Argument;
+import org.apache.karaf.shell.commands.Argument;
+import org.apache.karaf.shell.commands.Command;
+import org.apache.karaf.shell.commands.Completer;
import org.apache.karaf.shell.console.OsgiCommandSupport;
+import org.apache.karaf.shell.inject.Service;
@Command(scope = "test", name = "hello", description="Says hello")
+@Service
public class HelloShellCommand extends OsgiCommandSupport {
@Argument(index = 0, name = "name", description = "The name that sends the greet.", required = true, multiValued = false)
+ @Completer(SimpleNameCompleter.class)
String name = null;
@Override
@@ -257,12 +276,14 @@ package org.apache.karaf.shell.samples;
import org.apache.karaf.shell.console.completer.StringsCompleter;
import org.apache.karaf.shell.console.Completer;
+import org.apache.karaf.shell.inject.Service;
/**
* <p>
* A very simple completer.
* </p>
*/
+@Service
public class SimpleNameCompleter implements Completer {
/**
@@ -283,12 +304,12 @@ public class SimpleNameCompleter implements Completer {
h3. Blueprint with completer
-Using Blueprint, you can "inject" the completer linked to your command. The same completer could be used for several commands and a command can have several completers:
+If you're not using the scanning feature, you need to "inject" the completer linked to your command. The same completer could be used for several commands and a command can have several completers:
{code:lang=xml}
<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0">
- <command-bundle xmlns="http://karaf.apache.org/xmlns/shell/v1.1.0">
+ <command-bundle xmlns="http://karaf.apache.org/xmlns/shell/v1.2.0">
<command>
<action class="org.apache.karaf.shell.samples.HelloShellCommand"/>
<completers>
@@ -314,17 +335,21 @@ The snippet below shows the HelloShellCommand with an option to specify what the
{code:lang=java}
package org.apache.karaf.shell.samples;
-import Command;
-import Argument;
+import org.apache.karaf.shell.commands.Argument;
+import org.apache.karaf.shell.commands.Command;
import org.apache.karaf.shell.console.OsgiCommandSupport;
+import org.apache.karaf.shell.inject.Service;
@Command(scope = "test", name = "hello", description="Says hello")
+@Service
public class HelloShellCommand extends OsgiCommandSupport {
@Argument(index = 0, name = "name", description = "The name that sends the greet.", required = true, multiValued = false)
+ @Completer(SimpleNameCompleter.class)
String name = null;
@Option(name = "-g", aliases = "--greet", description = "The configuration pid", required = false, multiValued = false)
+ @Completer(GreetCompleter.class)
String greet = "Hello;
@Override
@@ -335,13 +360,13 @@ public class HelloShellCommand extends OsgiCommandSupport {
}
{code}
-We can now specify a completer for the greet option. All that is required is to add an optional-completer element in the
-blueprint configuration that will associate a completer with the -g option or its --greet alias.
+If you're using explicit wiring for the command, you need to specify the completer for the greet option in the blueprint file.
+All that is required is to add an optional-completer element in the blueprint configuration that will associate a completer with the -g option or its --greet alias.
{code:lang=xml}
<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0">
- <command-bundle xmlns="http://karaf.apache.org/xmlns/shell/v1.1.0">
+ <command-bundle xmlns="http://karaf.apache.org/xmlns/shell/v1.2.0">
<command>
<action class="org.apache.karaf.shell.samples.HelloShellCommand"/>
<completers>
@@ -398,6 +423,6 @@ karaf@root> test:hello <tab>
h2. WebConsole
-You can also extend the Apache Karaf WebConsole by providing and installing a webconsole plugin.o
+You can also extend the Apache Karaf WebConsole by providing and installing a webconsole plugin.
A plugin is an OSGi bundle that register a Servlet as an OSGi service with some webconsole properties.