diff --git a/gerrit-pgm/src/main/java/com/google/gerrit/pgm/BaseInit.java b/gerrit-pgm/src/main/java/com/google/gerrit/pgm/BaseInit.java index 76adadcc5d..5a8cb4fc8b 100644 --- a/gerrit-pgm/src/main/java/com/google/gerrit/pgm/BaseInit.java +++ b/gerrit-pgm/src/main/java/com/google/gerrit/pgm/BaseInit.java @@ -70,6 +70,8 @@ public class BaseInit extends SiteProgram { protected final PluginsDistribution pluginsDistribution; private final List pluginsToInstall; + private Injector sysInjector; + protected BaseInit(PluginsDistribution pluginsDistribution, List pluginsToInstall) { this.standalone = true; @@ -111,7 +113,7 @@ public class BaseInit extends SiteProgram { run = createSiteRun(init); run.upgradeSchema(); - init.initializer.postRun(); + init.initializer.postRun(createSysInjector(init)); } catch (Exception failure) { if (init.flags.deleteOnFailure) { recursiveDelete(getSitePath()); @@ -316,15 +318,18 @@ public class BaseInit extends SiteProgram { } private Injector createSysInjector(final SiteInit init) { - final List modules = new ArrayList(); - modules.add(new AbstractModule() { - @Override - protected void configure() { - bind(ConsoleUI.class).toInstance(init.ui); - bind(InitFlags.class).toInstance(init.flags); - } - }); - return createDbInjector(SINGLE_USER).createChildInjector(modules); + if (sysInjector == null) { + final List modules = new ArrayList(); + modules.add(new AbstractModule() { + @Override + protected void configure() { + bind(ConsoleUI.class).toInstance(init.ui); + bind(InitFlags.class).toInstance(init.flags); + } + }); + sysInjector = createDbInjector(SINGLE_USER).createChildInjector(modules); + } + return sysInjector; } private static void recursiveDelete(File path) { diff --git a/gerrit-pgm/src/main/java/com/google/gerrit/pgm/init/InitPlugins.java b/gerrit-pgm/src/main/java/com/google/gerrit/pgm/init/InitPlugins.java index e5f6f561ed..add5c8d368 100644 --- a/gerrit-pgm/src/main/java/com/google/gerrit/pgm/init/InitPlugins.java +++ b/gerrit-pgm/src/main/java/com/google/gerrit/pgm/init/InitPlugins.java @@ -19,6 +19,7 @@ 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.Inject; +import com.google.inject.Injector; import com.google.inject.Singleton; import java.io.File; @@ -80,6 +81,8 @@ public class InitPlugins implements InitStep { private final InitPluginStepsLoader pluginLoader; private final PluginsDistribution pluginsDistribution; + private Injector postRunInjector; + @Inject InitPlugins(final ConsoleUI ui, final SitePaths site, InitFlags initFlags, InitPluginStepsLoader pluginLoader, @@ -104,6 +107,11 @@ public class InitPlugins implements InitStep { postInitPlugins(); } + @Inject(optional = true) + void setPostRunInjector(Injector injector) { + postRunInjector = injector; + } + private void installPlugins() throws IOException { List plugins = listPlugins(site, pluginsDistribution); for (PluginData plugin : plugins) { @@ -155,6 +163,7 @@ public class InitPlugins implements InitStep { private void postInitPlugins() throws Exception { for (InitStep initStep : pluginLoader.getInitSteps()) { + postRunInjector.injectMembers(initStep); initStep.postRun(); } } diff --git a/gerrit-pgm/src/main/java/com/google/gerrit/pgm/init/SitePathInitializer.java b/gerrit-pgm/src/main/java/com/google/gerrit/pgm/init/SitePathInitializer.java index 82daf8140c..d980c09164 100644 --- a/gerrit-pgm/src/main/java/com/google/gerrit/pgm/init/SitePathInitializer.java +++ b/gerrit-pgm/src/main/java/com/google/gerrit/pgm/init/SitePathInitializer.java @@ -108,12 +108,13 @@ public class SitePathInitializer { } } - public void postRun() throws Exception { + public void postRun(Injector injector) throws Exception { for (InitStep step : steps) { if (step instanceof InitPlugins && flags.skipPlugins) { continue; } + injector.injectMembers(step); step.postRun(); } }