Merge "Register @Listen annotated classes in Http and Ssh modules" into stable-2.6
This commit is contained in:
@@ -14,22 +14,29 @@
|
||||
|
||||
package com.google.gerrit.sshd;
|
||||
|
||||
import static com.google.gerrit.server.plugins.AutoRegisterUtil.calculateBindAnnotation;
|
||||
|
||||
import com.google.common.base.Preconditions;
|
||||
import com.google.common.collect.LinkedListMultimap;
|
||||
import com.google.common.collect.Maps;
|
||||
import com.google.common.collect.Multimap;
|
||||
import com.google.gerrit.extensions.annotations.Export;
|
||||
import com.google.gerrit.server.plugins.InvalidPluginException;
|
||||
import com.google.gerrit.server.plugins.ModuleGenerator;
|
||||
import com.google.inject.AbstractModule;
|
||||
import com.google.inject.Module;
|
||||
import com.google.inject.TypeLiteral;
|
||||
|
||||
import org.apache.sshd.server.Command;
|
||||
|
||||
import java.lang.annotation.Annotation;
|
||||
import java.util.Map;
|
||||
|
||||
class SshAutoRegisterModuleGenerator
|
||||
extends AbstractModule
|
||||
implements ModuleGenerator {
|
||||
private final Map<String, Class<Command>> commands = Maps.newHashMap();
|
||||
private final Multimap<TypeLiteral<?>, Class<?>> listeners = LinkedListMultimap.create();
|
||||
private CommandName command;
|
||||
|
||||
@Override
|
||||
@@ -39,6 +46,16 @@ class SshAutoRegisterModuleGenerator
|
||||
for (Map.Entry<String, Class<Command>> e : commands.entrySet()) {
|
||||
bind(Commands.key(command, e.getKey())).to(e.getValue());
|
||||
}
|
||||
for (Map.Entry<TypeLiteral<?>, Class<?>> e : listeners.entries()) {
|
||||
@SuppressWarnings("unchecked")
|
||||
TypeLiteral<Object> type = (TypeLiteral<Object>) e.getKey();
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
Class<Object> impl = (Class<Object>) e.getValue();
|
||||
|
||||
Annotation n = calculateBindAnnotation(impl);
|
||||
bind(type).annotatedWith(n).to(impl);
|
||||
}
|
||||
}
|
||||
|
||||
public void setPluginName(String name) {
|
||||
@@ -66,6 +83,12 @@ class SshAutoRegisterModuleGenerator
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void listen(TypeLiteral<?> tl, Class<?> clazz) {
|
||||
listeners.put(tl, clazz);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Module create() throws InvalidPluginException {
|
||||
Preconditions.checkState(command != null, "pluginName must be provided");
|
||||
|
Reference in New Issue
Block a user