Merge "Expose some BaseCommand's methods to support generic SSH commands"
diff --git a/Documentation/dev-plugins.txt b/Documentation/dev-plugins.txt
index dcf176e..2e74b7c 100644
--- a/Documentation/dev-plugins.txt
+++ b/Documentation/dev-plugins.txt
@@ -403,6 +403,44 @@
$ ssh -p 29418 review.example.com helloworld print
----
+Multiple SSH commands can be bound to the same implementation class. For
+example a Gerrit Shell plugin can bind different shell commands to the same
+implementation class:
+
+[source,java]
+----
+public class SshShellModule extends PluginCommandModule {
+ @Override
+ protected void configureCommands() {
+ command("ls").to(ShellCommand.class);
+ command("ps").to(ShellCommand.class);
+ [...]
+ }
+}
+----
+
+With the possible implementation:
+
+[source,java]
+----
+public class ShellCommand extends SshCommand {
+ @Override
+ protected void run() throws UnloggedFailure {
+ String cmd = getName().substring(getPluginName().length() + 1);
+ ProcessBuilder proc = new ProcessBuilder(cmd);
+ Process cmd = proc.start();
+ [...]
+ }
+}
+----
+
+And the call:
+
+----
+$ ssh -p 29418 review.example.com shell ls
+$ ssh -p 29418 review.example.com shell ps
+----
+
[[configuration]]
Configuration
-------------
diff --git a/gerrit-sshd/src/main/java/com/google/gerrit/sshd/BaseCommand.java b/gerrit-sshd/src/main/java/com/google/gerrit/sshd/BaseCommand.java
index c8b24f7..4ac8f64 100644
--- a/gerrit-sshd/src/main/java/com/google/gerrit/sshd/BaseCommand.java
+++ b/gerrit-sshd/src/main/java/com/google/gerrit/sshd/BaseCommand.java
@@ -128,11 +128,11 @@
}
@Nullable
- String getPluginName() {
+ protected String getPluginName() {
return pluginName;
}
- String getName() {
+ protected String getName() {
return commandName;
}
@@ -140,7 +140,7 @@
this.commandName = prefix;
}
- String[] getArguments() {
+ public String[] getArguments() {
return argv;
}