use of com.google.gerrit.server.plugins.PluginGuiceEnvironment in project gerrit by GerritCodeReview.
the class WebAppInitializer method init.
private synchronized void init() {
if (manager == null) {
String path = System.getProperty(GERRIT_SITE_PATH);
if (path != null) {
sitePath = Paths.get(path);
} else {
throw new ProvisionException(GERRIT_SITE_PATH + " must be defined");
}
if (System.getProperty("gerrit.init") != null) {
List<String> pluginsToInstall;
String installPlugins = System.getProperty("gerrit.install_plugins");
if (installPlugins == null) {
pluginsToInstall = null;
} else {
pluginsToInstall = Splitter.on(",").trimResults().omitEmptyStrings().splitToList(installPlugins);
}
new SiteInitializer(path, System.getProperty(GERRIT_SITE_PATH), new UnzippedDistribution(servletContext), pluginsToInstall).init();
}
try {
cfgInjector = createCfgInjector();
} catch (CreationException ce) {
final Message first = ce.getErrorMessages().iterator().next();
final StringBuilder buf = new StringBuilder();
buf.append(first.getMessage());
Throwable why = first.getCause();
while (why != null) {
buf.append("\n caused by ");
buf.append(why.toString());
why = why.getCause();
}
if (first.getCause() != null) {
buf.append("\n");
buf.append("\nResolve above errors before continuing.");
buf.append("\nComplete stack trace follows:");
}
logger.atSevere().withCause(first.getCause()).log(buf.toString());
throw new CreationException(Collections.singleton(first));
}
dbInjector = createDbInjector();
initIndexType();
config = cfgInjector.getInstance(Key.get(Config.class, GerritServerConfig.class));
sysInjector = createSysInjector();
if (!sshdOff()) {
sshInjector = createSshInjector();
}
webInjector = createWebInjector();
PluginGuiceEnvironment env = sysInjector.getInstance(PluginGuiceEnvironment.class);
env.setDbCfgInjector(dbInjector, cfgInjector);
if (sshInjector != null) {
env.setSshInjector(sshInjector);
}
env.setHttpInjector(webInjector);
// Push the Provider<HttpServletRequest> down into the canonical
// URL provider. Its optional for that provider, but since we can
// supply one we should do so, in case the administrator has not
// setup the canonical URL in the configuration file.
//
// Note we have to do this manually as Guice failed to do the
// injection here because the HTTP environment is not visible
// to the core server modules.
//
sysInjector.getInstance(HttpCanonicalWebUrlProvider.class).setHttpServletRequest(webInjector.getProvider(HttpServletRequest.class));
filter = webInjector.getInstance(GuiceFilter.class);
manager = new LifecycleManager();
manager.add(dbInjector);
manager.add(cfgInjector);
manager.add(sysInjector);
if (sshInjector != null) {
manager.add(sshInjector);
}
manager.add(webInjector);
}
}
use of com.google.gerrit.server.plugins.PluginGuiceEnvironment in project gerrit by GerritCodeReview.
the class WebAppInitializer method init.
private synchronized void init() {
if (manager == null) {
final String path = System.getProperty("gerrit.site_path");
if (path != null) {
sitePath = Paths.get(path);
}
if (System.getProperty("gerrit.init") != null) {
List<String> pluginsToInstall;
String installPlugins = System.getProperty("gerrit.install_plugins");
if (installPlugins == null) {
pluginsToInstall = null;
} else {
pluginsToInstall = Splitter.on(",").trimResults().omitEmptyStrings().splitToList(installPlugins);
}
new SiteInitializer(path, System.getProperty("gerrit.init_path"), new UnzippedDistribution(servletContext), pluginsToInstall).init();
}
try {
dbInjector = createDbInjector();
} catch (CreationException ce) {
final Message first = ce.getErrorMessages().iterator().next();
final StringBuilder buf = new StringBuilder();
buf.append(first.getMessage());
Throwable why = first.getCause();
while (why != null) {
buf.append("\n caused by ");
buf.append(why.toString());
why = why.getCause();
}
if (first.getCause() != null) {
buf.append("\n");
buf.append("\nResolve above errors before continuing.");
buf.append("\nComplete stack trace follows:");
}
log.error(buf.toString(), first.getCause());
throw new CreationException(Collections.singleton(first));
}
cfgInjector = createCfgInjector();
initIndexType();
config = cfgInjector.getInstance(Key.get(Config.class, GerritServerConfig.class));
sysInjector = createSysInjector();
if (!sshdOff()) {
sshInjector = createSshInjector();
}
webInjector = createWebInjector();
PluginGuiceEnvironment env = sysInjector.getInstance(PluginGuiceEnvironment.class);
env.setDbCfgInjector(dbInjector, cfgInjector);
if (sshInjector != null) {
env.setSshInjector(sshInjector);
}
env.setHttpInjector(webInjector);
// Push the Provider<HttpServletRequest> down into the canonical
// URL provider. Its optional for that provider, but since we can
// supply one we should do so, in case the administrator has not
// setup the canonical URL in the configuration file.
//
// Note we have to do this manually as Guice failed to do the
// injection here because the HTTP environment is not visible
// to the core server modules.
//
sysInjector.getInstance(HttpCanonicalWebUrlProvider.class).setHttpServletRequest(webInjector.getProvider(HttpServletRequest.class));
filter = webInjector.getInstance(GuiceFilter.class);
manager = new LifecycleManager();
manager.add(dbInjector);
manager.add(cfgInjector);
manager.add(sysInjector);
if (sshInjector != null) {
manager.add(sshInjector);
}
manager.add(webInjector);
}
}
Aggregations