Completely remove GerritServer.properties
We now load our database settings in hosted development mode from the $site_path/etc/gerrit.config, just like we would under daemon. This reduces the number of weird configurations that are supported. Change-Id: I0a13f16dd74bdb034d05650eadd5e36771109f3e Signed-off-by: Shawn O. Pearce <sop@google.com>
This commit is contained in:
@@ -15,18 +15,10 @@
|
||||
package com.google.gerrit.httpd;
|
||||
|
||||
import com.google.gerrit.lifecycle.LifecycleListener;
|
||||
import com.google.gwtorm.jdbc.SimpleDataSource;
|
||||
import com.google.inject.Provider;
|
||||
import com.google.inject.ProvisionException;
|
||||
import com.google.inject.Singleton;
|
||||
|
||||
import java.io.FileInputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.sql.SQLException;
|
||||
import java.util.Map;
|
||||
import java.util.Properties;
|
||||
|
||||
import javax.naming.InitialContext;
|
||||
import javax.naming.NamingException;
|
||||
import javax.sql.DataSource;
|
||||
@@ -61,49 +53,10 @@ final class ReviewDbDataSourceProvider implements Provider<DataSource>,
|
||||
try {
|
||||
return (DataSource) new InitialContext().lookup(dsName);
|
||||
} catch (NamingException namingErr) {
|
||||
final Properties p = readGerritDataSource();
|
||||
if (p == null) {
|
||||
throw new ProvisionException("Initialization error:\n"
|
||||
+ " * No DataSource " + dsName + "\n"
|
||||
+ " * No -DGerritServer=GerritServer.properties"
|
||||
+ " on Java command line", namingErr);
|
||||
}
|
||||
|
||||
try {
|
||||
return new SimpleDataSource(p);
|
||||
} catch (SQLException se) {
|
||||
throw new ProvisionException("Database unavailable", se);
|
||||
}
|
||||
throw new ProvisionException("No DataSource " + dsName, namingErr);
|
||||
}
|
||||
}
|
||||
|
||||
private static Properties readGerritDataSource() throws ProvisionException {
|
||||
final Properties srvprop = new Properties();
|
||||
String name = System.getProperty("GerritServer");
|
||||
if (name == null) {
|
||||
name = "GerritServer.properties";
|
||||
}
|
||||
try {
|
||||
final InputStream in = new FileInputStream(name);
|
||||
try {
|
||||
srvprop.load(in);
|
||||
} finally {
|
||||
in.close();
|
||||
}
|
||||
} catch (IOException e) {
|
||||
throw new ProvisionException("Cannot read " + name, e);
|
||||
}
|
||||
|
||||
final Properties dbprop = new Properties();
|
||||
for (final Map.Entry<Object, Object> e : srvprop.entrySet()) {
|
||||
final String key = (String) e.getKey();
|
||||
if (key.startsWith("database.")) {
|
||||
dbprop.put(key.substring("database.".length()), e.getValue());
|
||||
}
|
||||
}
|
||||
return dbprop;
|
||||
}
|
||||
|
||||
private void closeDataSource(final DataSource ds) {
|
||||
try {
|
||||
Class<?> type = Class.forName("org.apache.commons.dbcp.BasicDataSource");
|
||||
|
@@ -27,6 +27,7 @@ import com.google.gerrit.server.config.GerritServerConfigModule;
|
||||
import com.google.gerrit.server.config.MasterNodeStartup;
|
||||
import com.google.gerrit.server.config.SitePath;
|
||||
import com.google.gerrit.server.config.SitePathFromSystemConfigProvider;
|
||||
import com.google.gerrit.server.schema.DataSourceProvider;
|
||||
import com.google.gerrit.sshd.SshModule;
|
||||
import com.google.gerrit.sshd.commands.MasterCommandModule;
|
||||
import com.google.inject.AbstractModule;
|
||||
@@ -57,6 +58,7 @@ public class WebAppInitializer extends GuiceServletContextListener {
|
||||
private static final Logger log =
|
||||
LoggerFactory.getLogger(WebAppInitializer.class);
|
||||
|
||||
private File sitePath;
|
||||
private Injector dbInjector;
|
||||
private Injector cfgInjector;
|
||||
private Injector sysInjector;
|
||||
@@ -66,6 +68,11 @@ public class WebAppInitializer extends GuiceServletContextListener {
|
||||
|
||||
private synchronized void init() {
|
||||
if (manager == null) {
|
||||
final String path = System.getProperty("gerrit.site_path");
|
||||
if (path != null) {
|
||||
sitePath = new File(path);
|
||||
}
|
||||
|
||||
try {
|
||||
dbInjector = createDbInjector();
|
||||
} catch (CreationException ce) {
|
||||
@@ -115,28 +122,50 @@ public class WebAppInitializer extends GuiceServletContextListener {
|
||||
|
||||
private Injector createDbInjector() {
|
||||
final List<Module> modules = new ArrayList<Module>();
|
||||
modules.add(new LifecycleModule() {
|
||||
@Override
|
||||
protected void configure() {
|
||||
bind(Key.get(DataSource.class, Names.named("ReviewDb"))).toProvider(
|
||||
ReviewDbDataSourceProvider.class).in(SINGLETON);
|
||||
listener().to(ReviewDbDataSourceProvider.class);
|
||||
}
|
||||
});
|
||||
if (sitePath != null) {
|
||||
modules.add(new LifecycleModule() {
|
||||
@Override
|
||||
protected void configure() {
|
||||
bind(File.class).annotatedWith(SitePath.class).toInstance(sitePath);
|
||||
bind(DataSourceProvider.Context.class).toInstance(
|
||||
DataSourceProvider.Context.MULTI_USER);
|
||||
bind(Key.get(DataSource.class, Names.named("ReviewDb"))).toProvider(
|
||||
DataSourceProvider.class).in(SINGLETON);
|
||||
listener().to(DataSourceProvider.class);
|
||||
}
|
||||
});
|
||||
modules.add(new GerritServerConfigModule());
|
||||
|
||||
} else {
|
||||
modules.add(new LifecycleModule() {
|
||||
@Override
|
||||
protected void configure() {
|
||||
bind(Key.get(DataSource.class, Names.named("ReviewDb"))).toProvider(
|
||||
ReviewDbDataSourceProvider.class).in(SINGLETON);
|
||||
listener().to(ReviewDbDataSourceProvider.class);
|
||||
}
|
||||
});
|
||||
}
|
||||
modules.add(new DatabaseModule());
|
||||
return Guice.createInjector(PRODUCTION, modules);
|
||||
}
|
||||
|
||||
private Injector createCfgInjector() {
|
||||
final List<Module> modules = new ArrayList<Module>();
|
||||
modules.add(new AbstractModule() {
|
||||
@Override
|
||||
protected void configure() {
|
||||
bind(File.class).annotatedWith(SitePath.class).toProvider(
|
||||
SitePathFromSystemConfigProvider.class).in(SINGLETON);
|
||||
}
|
||||
});
|
||||
modules.add(new GerritServerConfigModule());
|
||||
if (sitePath == null) {
|
||||
// If we didn't get the site path from the system property
|
||||
// we need to get it from the database, as that's our old
|
||||
// method of locating the site path on disk.
|
||||
//
|
||||
modules.add(new AbstractModule() {
|
||||
@Override
|
||||
protected void configure() {
|
||||
bind(File.class).annotatedWith(SitePath.class).toProvider(
|
||||
SitePathFromSystemConfigProvider.class).in(SINGLETON);
|
||||
}
|
||||
});
|
||||
modules.add(new GerritServerConfigModule());
|
||||
}
|
||||
modules.add(new AuthConfigModule());
|
||||
return dbInjector.createChildInjector(modules);
|
||||
}
|
||||
|
Reference in New Issue
Block a user