Fix plugin loading when running as hosted WAR or GWT DevMode.

Loading of plugins was failing when running Gerrit in a servlet
container (Tomcat, for example) or in GWT DevMode. The reason was
duplicated Guice bindings created inside the PluginGuiceEnvironment for
the child injectors of the dbInjector.

Bug: issue 1471
Change-Id: I7be020dd3e489df4b6099b482a925ecb155e85c6
Signed-off-by: Sasa Zivkov <sasa.zivkov@sap.com>
This commit is contained in:
Sasa Zivkov
2012-10-15 14:46:54 +02:00
parent f77e9a9109
commit 13b7035885

View File

@@ -31,6 +31,7 @@ import com.google.gerrit.extensions.registration.ReloadableRegistrationHandle;
import com.google.gerrit.extensions.systemstatus.ServerInformation;
import com.google.inject.AbstractModule;
import com.google.inject.Binding;
import com.google.inject.Guice;
import com.google.inject.Injector;
import com.google.inject.Key;
import com.google.inject.Module;
@@ -62,6 +63,7 @@ public class PluginGuiceEnvironment {
private final Injector sysInjector;
private final ServerInformation srvInfo;
private final CopyConfigModule copyConfigModule;
private final Set<Key<?>> copyConfigKeys;
private final List<StartPluginListener> onStart;
private final List<ReloadPluginListener> onReload;
@@ -88,6 +90,7 @@ public class PluginGuiceEnvironment {
this.sysInjector = sysInjector;
this.srvInfo = srvInfo;
this.copyConfigModule = ccm;
this.copyConfigKeys = Guice.createInjector(ccm).getAllBindings().keySet();
onStart = new CopyOnWriteArrayList<StartPluginListener>();
onStart.addAll(listeners(sysInjector, StartPluginListener.class));
@@ -372,7 +375,7 @@ public class PluginGuiceEnvironment {
return src.findBindingsByType(type);
}
private static Module copy(Injector src) {
private Module copy(Injector src) {
Set<TypeLiteral<?>> dynamicTypes = Sets.newHashSet();
for (Map.Entry<Key<?>, Binding<?>> e : src.getBindings().entrySet()) {
TypeLiteral<?> type = e.getKey().getTypeLiteral();
@@ -413,7 +416,10 @@ public class PluginGuiceEnvironment {
};
}
private static boolean shouldCopy(Key<?> key) {
private boolean shouldCopy(Key<?> key) {
if (copyConfigKeys.contains(key)) {
return false;
}
Class<?> type = key.getTypeLiteral().getRawType();
if (LifecycleListener.class.isAssignableFrom(type)) {
return false;