Inject right plugin name @PluginName in init step
@PluginName is injected to the plugin environment. Since plugin can provide
their own names, the right name is injected. During init step the wrong plugin
name was bound, ignoring the plugin name that was defined in MANIFEST file.
Change-Id: I5411c6d796cbb25457df357c173274b27ab909db
diff --git a/gerrit-pgm/src/main/java/com/google/gerrit/pgm/init/InitPluginStepsLoader.java b/gerrit-pgm/src/main/java/com/google/gerrit/pgm/init/InitPluginStepsLoader.java
index 7658701..6b4cedf 100644
--- a/gerrit-pgm/src/main/java/com/google/gerrit/pgm/init/InitPluginStepsLoader.java
+++ b/gerrit-pgm/src/main/java/com/google/gerrit/pgm/init/InitPluginStepsLoader.java
@@ -14,9 +14,11 @@
package com.google.gerrit.pgm.init;
+import com.google.common.base.Objects;
import com.google.gerrit.extensions.annotations.PluginName;
import com.google.gerrit.pgm.util.ConsoleUI;
import com.google.gerrit.server.config.SitePaths;
+import com.google.gerrit.server.plugins.PluginLoader;
import com.google.inject.AbstractModule;
import com.google.inject.Inject;
import com.google.inject.Injector;
@@ -24,6 +26,7 @@
import java.io.File;
import java.io.FileFilter;
+import java.io.IOException;
import java.net.URL;
import java.net.URLClassLoader;
import java.util.ArrayList;
@@ -90,10 +93,10 @@
}
}
- private Injector getPluginInjector(File jarFile) {
- String jarFileName = jarFile.getName();
+ private Injector getPluginInjector(File jarFile) throws IOException {
final String pluginName =
- jarFileName.substring(0, jarFileName.lastIndexOf('.'));
+ Objects.firstNonNull(PluginLoader.getGerritPluginName(jarFile),
+ PluginLoader.nameOf(jarFile));
return initInjector.createChildInjector(new AbstractModule() {
@Override
protected void configure() {
diff --git a/gerrit-server/src/main/java/com/google/gerrit/server/plugins/PluginLoader.java b/gerrit-server/src/main/java/com/google/gerrit/server/plugins/PluginLoader.java
index bbd6eb9..7569744 100644
--- a/gerrit-server/src/main/java/com/google/gerrit/server/plugins/PluginLoader.java
+++ b/gerrit-server/src/main/java/com/google/gerrit/server/plugins/PluginLoader.java
@@ -460,7 +460,7 @@
}
}
- private static String nameOf(File jar) {
+ public static String nameOf(File jar) {
return nameOf(jar.getName());
}
@@ -653,7 +653,7 @@
});
}
- private static String getGerritPluginName(File srcFile) throws IOException {
+ public static String getGerritPluginName(File srcFile) throws IOException {
JarFile jarFile = new JarFile(srcFile);
try {
return jarFile.getManifest().getMainAttributes()