Fix Guice module auto-discover for plugin providers
When a plugin provider was using the AbstractPreloadedPluginScanner
to automatically scan its contents, the Guice modules were incorrectly
detected and wrongly assigned:
- Modules not initialised to null at the beginning of the scan
- SshModule incorrectly assigned to SysModule and the other way around
- Inner modules were clashing with named Guice modules
e.g. install(new Module() { })
This fix brings much more sanity to module detection for plugin
providers (e.g. Groovy, Scala or other pluggable plugin formats).
Change-Id: I4edddd29acd0ff81cd61841bef8d2356ea20e716
diff --git a/gerrit-server/src/main/java/com/google/gerrit/server/plugins/AbstractPreloadedPluginScanner.java b/gerrit-server/src/main/java/com/google/gerrit/server/plugins/AbstractPreloadedPluginScanner.java
index 4a50c21..0b128dd 100644
--- a/gerrit-server/src/main/java/com/google/gerrit/server/plugins/AbstractPreloadedPluginScanner.java
+++ b/gerrit-server/src/main/java/com/google/gerrit/server/plugins/AbstractPreloadedPluginScanner.java
@@ -70,9 +70,9 @@
+ "Implementation-Version: " + pluginVersion + "\n"
+ "Gerrit-ReloadMode: restart\n"
+ "Gerrit-ApiType: " + apiType + "\n");
- appendIfNotNull(manifestString, "Gerrit-Module: ", sshModuleClass);
+ appendIfNotNull(manifestString, "Gerrit-SshModule: ", sshModuleClass);
appendIfNotNull(manifestString, "Gerrit-HttpModule: ", httpModuleClass);
- appendIfNotNull(manifestString, "Gerrit-SshModule: ", sysModuleClass);
+ appendIfNotNull(manifestString, "Gerrit-Module: ", sysModuleClass);
return new Manifest(new ByteArrayInputStream(manifestString.toString()
.getBytes()));
}
@@ -115,8 +115,14 @@
Class.forName("com.google.inject.servlet.ServletModule");
Class<?> sshModuleBaseClass =
Class.forName("com.google.gerrit.sshd.CommandModule");
+ sshModuleClass = null;
+ httpModuleClass = null;
+ sysModuleClass = null;
for (Class<?> clazz : classes) {
+ if (clazz.isLocalClass()) {
+ continue;
+ }
if (sshModuleBaseClass.isAssignableFrom(clazz)) {
sshModuleClass =