Enable multiple bindings during auto registration
If a plugin registers more than one implementation of an interface, enable them to all be automatically bound by tracking them inside of a multimap. Change-Id: Ib4e68f454da98be95669111713c8cab56bdc6763
This commit is contained in:
@@ -16,7 +16,8 @@ package com.google.gerrit.server.plugins;
|
|||||||
|
|
||||||
import static com.google.gerrit.server.plugins.PluginGuiceEnvironment.is;
|
import static com.google.gerrit.server.plugins.PluginGuiceEnvironment.is;
|
||||||
|
|
||||||
import com.google.common.collect.Maps;
|
import com.google.common.collect.LinkedListMultimap;
|
||||||
|
import com.google.common.collect.Multimap;
|
||||||
import com.google.common.collect.Sets;
|
import com.google.common.collect.Sets;
|
||||||
import com.google.gerrit.extensions.annotations.Export;
|
import com.google.gerrit.extensions.annotations.Export;
|
||||||
import com.google.gerrit.extensions.annotations.ExtensionPoint;
|
import com.google.gerrit.extensions.annotations.ExtensionPoint;
|
||||||
@@ -58,7 +59,7 @@ class AutoRegisterModules {
|
|||||||
private final ModuleGenerator httpGen;
|
private final ModuleGenerator httpGen;
|
||||||
|
|
||||||
private Set<Class<?>> sysSingletons;
|
private Set<Class<?>> sysSingletons;
|
||||||
private Map<TypeLiteral<?>, Class<?>> sysListen;
|
private Multimap<TypeLiteral<?>, Class<?>> sysListen;
|
||||||
|
|
||||||
Module sysModule;
|
Module sysModule;
|
||||||
Module sshModule;
|
Module sshModule;
|
||||||
@@ -78,7 +79,7 @@ class AutoRegisterModules {
|
|||||||
|
|
||||||
AutoRegisterModules discover() throws InvalidPluginException {
|
AutoRegisterModules discover() throws InvalidPluginException {
|
||||||
sysSingletons = Sets.newHashSet();
|
sysSingletons = Sets.newHashSet();
|
||||||
sysListen = Maps.newHashMap();
|
sysListen = LinkedListMultimap.create();
|
||||||
|
|
||||||
if (sshGen != null) {
|
if (sshGen != null) {
|
||||||
sshGen.setPluginName(pluginName);
|
sshGen.setPluginName(pluginName);
|
||||||
@@ -108,7 +109,7 @@ class AutoRegisterModules {
|
|||||||
for (Class<?> clazz : sysSingletons) {
|
for (Class<?> clazz : sysSingletons) {
|
||||||
bind(clazz).in(Scopes.SINGLETON);
|
bind(clazz).in(Scopes.SINGLETON);
|
||||||
}
|
}
|
||||||
for (Map.Entry<TypeLiteral<?>, Class<?>> e : sysListen.entrySet()) {
|
for (Map.Entry<TypeLiteral<?>, Class<?>> e : sysListen.entries()) {
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
TypeLiteral<Object> type = (TypeLiteral<Object>) e.getKey();
|
TypeLiteral<Object> type = (TypeLiteral<Object>) e.getKey();
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user