]> source.dussan.org Git - gitblit.git/commitdiff
Expose SSH command as plugin extension point
authorDavid Ostrovsky <david@ostrovsky.org>
Tue, 18 Mar 2014 07:33:42 +0000 (08:33 +0100)
committerJames Moger <james.moger@gitblit.com>
Thu, 10 Apr 2014 22:58:09 +0000 (18:58 -0400)
Example plugin is provided [1].

[1] https://github.com/davido/gitblit-cookbook-plugin

src/main/java/com/gitblit/transport/ssh/commands/PluginDispatchCommand.java [new file with mode: 0644]
src/main/java/com/gitblit/transport/ssh/commands/RootDispatcher.java
src/main/java/com/gitblit/transport/ssh/commands/SshCommand.java

diff --git a/src/main/java/com/gitblit/transport/ssh/commands/PluginDispatchCommand.java b/src/main/java/com/gitblit/transport/ssh/commands/PluginDispatchCommand.java
new file mode 100644 (file)
index 0000000..27d437f
--- /dev/null
@@ -0,0 +1,11 @@
+package com.gitblit.transport.ssh.commands;
+
+import com.gitblit.models.UserModel;
+
+public class PluginDispatchCommand extends DispatchCommand {
+
+       @Override
+       protected void registerCommands(UserModel user) {
+               // no op
+       }
+}
index 5d9eb1978dd49356aef6f3aa8df6d81c493676d9..38fbd2c803343f732b1a79e961e6ae4b1353103b 100644 (file)
  */
 package com.gitblit.transport.ssh.commands;
 
+import java.util.List;
+
+import ro.fortsoft.pf4j.PluginWrapper;
+
 import com.gitblit.manager.IGitblit;
 import com.gitblit.models.UserModel;
 import com.gitblit.transport.ssh.SshDaemonClient;
@@ -36,7 +40,14 @@ public class RootDispatcher extends DispatchCommand {
                registerDispatcher(user, GitblitDispatcher.class);
                registerDispatcher(user, GitDispatcher.class);
 
-               // TODO register plugin dispatchers here
+               List<SshCommand> exts = gitblit.getExtensions(SshCommand.class);
+               for (SshCommand sshCommand : exts) {
+                       PluginDispatchCommand pluginCmd = new PluginDispatchCommand();
+                       PluginWrapper wrapper = gitblit.whichPlugin(sshCommand.getClass());
+                       pluginCmd.registerCommand(user, sshCommand.getClass());
+                       // TODO(davido): add dispatcher registration per plugin name
+                       //registerDispatcher(wrapper.getDescriptor().getPluginId(), pluginCmd);
+               }
        }
 
        @Override
index ee464e7c9c09dda3529a3a068643d5814f05492d..3d2c68b793703cd0606e7238008311d52285c1fb 100644 (file)
@@ -19,7 +19,9 @@ import java.io.PrintWriter;
 
 import org.apache.sshd.server.Environment;
 
-public abstract class SshCommand extends BaseCommand {
+import ro.fortsoft.pf4j.ExtensionPoint;
+
+public abstract class SshCommand extends BaseCommand implements ExtensionPoint {
        protected PrintWriter stdout;
        protected PrintWriter stderr;