Merge "Inject InitStep members again before calling postRun." into stable-2.9

This commit is contained in:
Edwin Kempin 2014-11-11 08:28:44 +00:00 committed by Gerrit Code Review
commit 89e388a13e
3 changed files with 26 additions and 11 deletions

View File

@ -70,6 +70,8 @@ public class BaseInit extends SiteProgram {
protected final PluginsDistribution pluginsDistribution;
private final List<String> pluginsToInstall;
private Injector sysInjector;
protected BaseInit(PluginsDistribution pluginsDistribution,
List<String> 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<Module> modules = new ArrayList<Module>();
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<Module> modules = new ArrayList<Module>();
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) {

View File

@ -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<PluginData> 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();
}
}

View File

@ -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();
}
}