diff options
Diffstat (limited to 'gerrit-sshd/src/main/java/com/google/gerrit/sshd/DispatchCommandProvider.java')
-rw-r--r-- | gerrit-sshd/src/main/java/com/google/gerrit/sshd/DispatchCommandProvider.java | 25 |
1 files changed, 16 insertions, 9 deletions
diff --git a/gerrit-sshd/src/main/java/com/google/gerrit/sshd/DispatchCommandProvider.java b/gerrit-sshd/src/main/java/com/google/gerrit/sshd/DispatchCommandProvider.java index b76ff71e78..e9a31c9285 100644 --- a/gerrit-sshd/src/main/java/com/google/gerrit/sshd/DispatchCommandProvider.java +++ b/gerrit-sshd/src/main/java/com/google/gerrit/sshd/DispatchCommandProvider.java @@ -39,7 +39,7 @@ public class DispatchCommandProvider implements Provider<DispatchCommand> { private DispatchCommand.Factory factory; private final CommandName parent; - private volatile ConcurrentMap<String, Provider<Command>> map; + private volatile ConcurrentMap<String, CommandProvider> map; public DispatchCommandProvider(final CommandName cn) { this.parent = cn; @@ -52,8 +52,8 @@ public class DispatchCommandProvider implements Provider<DispatchCommand> { public RegistrationHandle register(final CommandName name, final Provider<Command> cmd) { - final ConcurrentMap<String, Provider<Command>> m = getMap(); - if (m.putIfAbsent(name.value(), cmd) != null) { + final ConcurrentMap<String, CommandProvider> m = getMap(); + if (m.putIfAbsent(name.value(), new CommandProvider(cmd, null)) != null) { throw new IllegalArgumentException(name.value() + " exists"); } return new RegistrationHandle() { @@ -66,8 +66,8 @@ public class DispatchCommandProvider implements Provider<DispatchCommand> { public RegistrationHandle replace(final CommandName name, final Provider<Command> cmd) { - final ConcurrentMap<String, Provider<Command>> m = getMap(); - m.put(name.value(), cmd); + final ConcurrentMap<String, CommandProvider> m = getMap(); + m.put(name.value(), new CommandProvider(cmd, null)); return new RegistrationHandle() { @Override public void remove() { @@ -76,7 +76,7 @@ public class DispatchCommandProvider implements Provider<DispatchCommand> { }; } - ConcurrentMap<String, Provider<Command>> getMap() { + ConcurrentMap<String, CommandProvider> getMap() { if (map == null) { synchronized (this) { if (map == null) { @@ -88,14 +88,21 @@ public class DispatchCommandProvider implements Provider<DispatchCommand> { } @SuppressWarnings("unchecked") - private ConcurrentMap<String, Provider<Command>> createMap() { - ConcurrentMap<String, Provider<Command>> m = Maps.newConcurrentMap(); + private ConcurrentMap<String, CommandProvider> createMap() { + ConcurrentMap<String, CommandProvider> m = Maps.newConcurrentMap(); for (final Binding<?> b : allCommands()) { final Annotation annotation = b.getKey().getAnnotation(); if (annotation instanceof CommandName) { final CommandName n = (CommandName) annotation; if (!Commands.CMD_ROOT.equals(n) && Commands.isChild(parent, n)) { - m.put(n.value(), (Provider<Command>) b.getProvider()); + String descr = null; + if (annotation instanceof Commands.NestedCommandNameImpl) { + Commands.NestedCommandNameImpl impl = + ((Commands.NestedCommandNameImpl) annotation); + descr = impl.descr(); + } + m.put(n.value(), + new CommandProvider((Provider<Command>) b.getProvider(), descr)); } } } |