Register @Listen annotated classes in Http and Ssh modules
Current implementation of Web UI plugins allows auto register them using @Listen annotation. Unfortunately listeners can only be bind in system module. This patch enables binding listeners in Http and Ssh modules. Change-Id: I7569d0e743bd9e1c9bb8aded09a5740bb88c1cca Signed-off-by: Dariusz Luksza <dariusz@luksza.org>
This commit is contained in:
@@ -14,14 +14,20 @@
|
||||
|
||||
package com.google.gerrit.httpd.plugins;
|
||||
|
||||
import static com.google.gerrit.server.plugins.AutoRegisterUtil.calculateBindAnnotation;
|
||||
|
||||
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.Module;
|
||||
import com.google.inject.Scopes;
|
||||
import com.google.inject.TypeLiteral;
|
||||
import com.google.inject.servlet.ServletModule;
|
||||
|
||||
import java.lang.annotation.Annotation;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.servlet.http.HttpServlet;
|
||||
@@ -29,6 +35,7 @@ import javax.servlet.http.HttpServlet;
|
||||
class HttpAutoRegisterModuleGenerator extends ServletModule
|
||||
implements ModuleGenerator {
|
||||
private final Map<String, Class<HttpServlet>> serve = Maps.newHashMap();
|
||||
private final Multimap<TypeLiteral<?>, Class<?>> listeners = LinkedListMultimap.create();
|
||||
|
||||
@Override
|
||||
protected void configureServlets() {
|
||||
@@ -36,6 +43,16 @@ class HttpAutoRegisterModuleGenerator extends ServletModule
|
||||
bind(e.getValue()).in(Scopes.SINGLETON);
|
||||
serve(e.getKey()).with(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);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -62,6 +79,11 @@ class HttpAutoRegisterModuleGenerator extends ServletModule
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void listen(TypeLiteral<?> tl, Class<?> clazz) {
|
||||
listeners.put(tl, clazz);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Module create() throws InvalidPluginException {
|
||||
return this;
|
||||
|
||||
Reference in New Issue
Block a user