diff options
Diffstat (limited to 'src/main/java')
-rw-r--r-- | src/main/java/com/gitblit/transport/ssh/SshDaemon.java | 7 | ||||
-rw-r--r-- | src/main/java/com/gitblit/transport/ssh/commands/DispatchCommand.java | 44 |
2 files changed, 35 insertions, 16 deletions
diff --git a/src/main/java/com/gitblit/transport/ssh/SshDaemon.java b/src/main/java/com/gitblit/transport/ssh/SshDaemon.java index 42ee67ab..dd4a2d8e 100644 --- a/src/main/java/com/gitblit/transport/ssh/SshDaemon.java +++ b/src/main/java/com/gitblit/transport/ssh/SshDaemon.java @@ -102,9 +102,12 @@ public class SshDaemon { sshd.setFileSystemFactory(new DisabledFilesystemFactory()); sshd.setForwardingFilter(new NonForwardingFilter()); + DispatchCommand gitblitCmd = new DispatchCommand(); + gitblitCmd.registerCommand(CreateRepository.class); + gitblitCmd.registerCommand(VersionCommand.class); + DispatchCommand dispatcher = new DispatchCommand(); - dispatcher.registerCommand(CreateRepository.class); - dispatcher.registerCommand(VersionCommand.class); + dispatcher.registerDispatcher("gitblit", gitblitCmd); SshCommandFactory commandFactory = new SshCommandFactory( new RepositoryResolver<SshSession>(gitblit), diff --git a/src/main/java/com/gitblit/transport/ssh/commands/DispatchCommand.java b/src/main/java/com/gitblit/transport/ssh/commands/DispatchCommand.java index 0d614a0f..b6944eaf 100644 --- a/src/main/java/com/gitblit/transport/ssh/commands/DispatchCommand.java +++ b/src/main/java/com/gitblit/transport/ssh/commands/DispatchCommand.java @@ -44,11 +44,19 @@ public class DispatchCommand extends BaseCommand { private Set<Class<? extends Command>> commands; private Map<String, Class<? extends Command>> map; + private Map<String, Command> root; public DispatchCommand() { commands = new HashSet<Class<? extends Command>>(); } + public void registerDispatcher(String name, Command cmd) { + if (root == null) { + root = Maps.newHashMap(); + } + root.put(name, cmd); + } + public void registerCommand(Class<? extends Command> cmd) { if (!cmd.isAnnotationPresent(CommandMetaData.class)) { throw new RuntimeException(MessageFormat.format("{0} must be annotated with {1}!", @@ -78,20 +86,7 @@ public class DispatchCommand extends BaseCommand { throw new UnloggedFailure(1, msg.toString()); } - final Class<? extends Command> c = getMap().get(commandName); - if (c == null) { - String msg = - (getName().isEmpty() ? "Gitblit" : getName()) + ": " - + commandName + ": not found"; - throw new UnloggedFailure(1, msg); - } - - Command cmd = null; - try { - cmd = c.newInstance(); - } catch (Exception e) { - throw new UnloggedFailure(1, MessageFormat.format("Failed to instantiate {0} command", commandName)); - } + Command cmd = getCommand(); if (cmd instanceof BaseCommand) { BaseCommand bc = (BaseCommand) cmd; if (getName().isEmpty()) { @@ -119,6 +114,27 @@ public class DispatchCommand extends BaseCommand { } } + private Command getCommand() throws UnloggedFailure { + if (root != null && root.containsKey(commandName)) { + return root.get(commandName); + } + final Class<? extends Command> c = getMap().get(commandName); + if (c == null) { + String msg = + (getName().isEmpty() ? "Gitblit" : getName()) + ": " + + commandName + ": not found"; + throw new UnloggedFailure(1, msg); + } + + Command cmd = null; + try { + cmd = c.newInstance(); + } catch (Exception e) { + throw new UnloggedFailure(1, MessageFormat.format("Failed to instantiate {0} command", commandName)); + } + return cmd; + } + @Override protected String usage() { final StringBuilder usage = new StringBuilder(); |