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:
Shawn O. Pearce 2009-12-19 13:38:19 -08:00
parent e194e7f6ca
commit 955d00eb81
16 changed files with 80 additions and 120 deletions

1
.gitignore vendored
View File

@ -1,4 +1,3 @@
/.project
/.settings/org.maven.ide.eclipse.prefs
/GerritServer.properties
/test_site

View File

@ -82,9 +82,9 @@ Duplicate the existing `pgm_daemon` launch configuration:
* Modify the name to be unique.
* Switch to Arguments tab.
* Edit the -d flag to match the path used during 'init'. The
template launch configuration resolves to ../test_site since
that is what the documentation recommends.
* Edit the `-d` program argument flag to match the path used during
'init'. The template launch configuration resolves to ../test_site
since that is what the documentation recommends.
* Switch to Common tab.
* Change Save as to be Local file.
@ -93,12 +93,22 @@ Duplicate the existing `pgm_daemon` launch configuration:
Running Hosted Mode
~~~~~~~~~~~~~~~~~~~
* Copy
`gerrit-war/src/main/webapp/WEB-INF/extra/GerritServer.properties_example`
to
`gerrit-parent/GerritServer.properties`.
* Edit to match your database parameters.
* Run the `gwtui_any` or `gwtui_mac` launch configuration.
Duplicate the existing `gwtui_any` (or `gwtui_mac` if on Mac OS X)
launch configuration:
* Run -> Debug Configurations ...
* Java Application -> `gwtui_any`
* Right click, Duplicate
* Modify the name to be unique.
* Switch to Arguments tab.
* Edit the `-Dgerrit.site_path=` VM argument to match the path
used during 'init'. The template launch configuration resolves
to ../test_site since that is what the documentation recommends.
* Switch to Common tab.
* Change Save as to be Local file.
GERRIT

View File

@ -38,11 +38,6 @@ limitations under the License.
<artifactId>log4j</artifactId>
</dependency>
<dependency>
<groupId>commons-dbcp</groupId>
<artifactId>commons-dbcp</artifactId>
</dependency>
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>

View File

@ -14,7 +14,7 @@
package com.google.gerrit.pgm;
import static com.google.gerrit.pgm.util.DataSourceProvider.Context.MULTI_USER;
import static com.google.gerrit.server.schema.DataSourceProvider.Context.MULTI_USER;
import com.google.gerrit.httpd.HttpCanonicalWebUrlProvider;
import com.google.gerrit.httpd.WebModule;

View File

@ -14,7 +14,7 @@
package com.google.gerrit.pgm;
import static com.google.gerrit.pgm.util.DataSourceProvider.Context.SINGLE_USER;
import static com.google.gerrit.server.schema.DataSourceProvider.Context.SINGLE_USER;
import com.google.gerrit.lifecycle.LifecycleManager;
import com.google.gerrit.pgm.util.RuntimeShutdown;

View File

@ -14,7 +14,7 @@
package com.google.gerrit.pgm;
import static com.google.gerrit.pgm.util.DataSourceProvider.Context.SINGLE_USER;
import static com.google.gerrit.server.schema.DataSourceProvider.Context.SINGLE_USER;
import static com.google.inject.Stage.PRODUCTION;
import com.google.gerrit.common.PageLinks;

View File

@ -16,11 +16,11 @@ package com.google.gerrit.pgm.init;
import static com.google.gerrit.pgm.init.InitUtil.die;
import static com.google.gerrit.pgm.init.InitUtil.username;
import static com.google.gerrit.pgm.util.DataSourceProvider.Type.H2;
import static com.google.gerrit.server.schema.DataSourceProvider.Type.H2;
import com.google.gerrit.pgm.util.ConsoleUI;
import com.google.gerrit.pgm.util.DataSourceProvider;
import com.google.gerrit.server.config.SitePaths;
import com.google.gerrit.server.schema.DataSourceProvider;
import com.google.inject.Inject;
import com.google.inject.Singleton;

View File

@ -19,8 +19,8 @@ import static com.google.gerrit.pgm.init.InitUtil.savePublic;
import static com.google.gerrit.pgm.init.InitUtil.saveSecure;
import com.google.gerrit.pgm.util.ConsoleUI;
import com.google.gerrit.pgm.util.DataSourceProvider;
import com.google.gerrit.server.config.SitePaths;
import com.google.gerrit.server.schema.DataSourceProvider;
import com.google.gerrit.server.util.SocketUtil;
import com.google.inject.Inject;
import com.google.inject.Singleton;

View File

@ -21,6 +21,7 @@ import com.google.gerrit.lifecycle.LifecycleModule;
import com.google.gerrit.server.config.DatabaseModule;
import com.google.gerrit.server.config.GerritServerConfigModule;
import com.google.gerrit.server.config.SitePath;
import com.google.gerrit.server.schema.DataSourceProvider;
import com.google.gwtorm.client.OrmException;
import com.google.inject.AbstractModule;
import com.google.inject.CreationException;

View File

@ -48,6 +48,11 @@ limitations under the License.
<artifactId>ehcache-core</artifactId>
</dependency>
<dependency>
<groupId>commons-dbcp</groupId>
<artifactId>commons-dbcp</artifactId>
</dependency>
<dependency>
<groupId>commons-net</groupId>
<artifactId>commons-net</artifactId>

View File

@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.
package com.google.gerrit.pgm.util;
package com.google.gerrit.server.schema;
import com.google.gerrit.lifecycle.LifecycleListener;
import com.google.gerrit.server.config.ConfigUtil;

View File

@ -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");

View File

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

View File

@ -1,32 +0,0 @@
# Any properties starting with "database." will be fed to the JDBC driver,
# after removing the "database." prefix.
#
# The following "special" properties are removed from that set:
#
# database.driver : Class name of the driver to load.
# database.url : The connection URL
#
# H2
# (driver included)
#
# database.driver = org.h2.Driver
# database.url = jdbc:h2:file:ReviewDb
# PostgreSQL
# (driver included)
#
# database.driver = org.postgresql.Driver
# database.url = jdbc:postgresql:reviewdb
# database.user = gerrit2
# database.password = supersecretcode
# MySQL 5.0
# curl -O http://repo1.maven.org/maven2/mysql/mysql-connector-java/5.0.8/mysql-connector-java-5.0.8.jar
#
# database.classpath = mysql-connector-java-5.0.8.jar
# database.driver = com.mysql.jdbc.Driver
# database.url = jdbc:mysql://localhost/reviewdb?user=gerrit2&password=secretcode

View File

@ -32,5 +32,5 @@
<stringAttribute key="org.eclipse.jdt.launching.PROGRAM_ARGUMENTS" value="-startupUrl /&#10;-war ${resource_loc:/gerrit-gwtui/target}/gwt-hosted-mode&#10;-server com.google.gerrit.gwtdebug.GerritDebugLauncher&#10;com.google.gerrit.GerritGwtUI"/>
<stringAttribute key="org.eclipse.jdt.launching.PROJECT_ATTR" value="gerrit-gwtdbug"/>
<stringAttribute key="org.eclipse.jdt.launching.SOURCE_PATH_PROVIDER" value="org.maven.ide.eclipse.launchconfig.sourcepathProvider"/>
<stringAttribute key="org.eclipse.jdt.launching.VM_ARGUMENTS" value="-Xmx256M&#10;-DGerritServer=${resource_loc:/gerrit-parent/GerritServer.properties}&#10;-Dcom.google.gerrit.httpd.auth.become=true"/>
<stringAttribute key="org.eclipse.jdt.launching.VM_ARGUMENTS" value="-Xmx256M&#10;-Dcom.google.gerrit.httpd.auth.become=true&#10;-Dgerrit.site_path=${resource_loc:/gerrit-parent}/../android_codereview"/>
</launchConfiguration>

View File

@ -32,5 +32,5 @@
<stringAttribute key="org.eclipse.jdt.launching.PROGRAM_ARGUMENTS" value="-startupUrl /&#10;-war ${resource_loc:/gerrit-gwtui/target}/gwt-hosted-mode&#10;-server com.google.gerrit.gwtdebug.GerritDebugLauncher&#10;com.google.gerrit.GerritGwtUI"/>
<stringAttribute key="org.eclipse.jdt.launching.PROJECT_ATTR" value="gerrit-gwtdbug"/>
<stringAttribute key="org.eclipse.jdt.launching.SOURCE_PATH_PROVIDER" value="org.maven.ide.eclipse.launchconfig.sourcepathProvider"/>
<stringAttribute key="org.eclipse.jdt.launching.VM_ARGUMENTS" value="-XstartOnFirstThread&#10;-Xmx256M&#10;-DGerritServer=${resource_loc:/gerrit-parent/GerritServer.properties}&#10;-Dcom.google.gerrit.httpd.auth.become=true"/>
<stringAttribute key="org.eclipse.jdt.launching.VM_ARGUMENTS" value="-XstartOnFirstThread&#10;-Xmx256M&#10;-Dcom.google.gerrit.httpd.auth.become=true&#10;-Dgerrit.site_path=${resource_loc:/gerrit-parent}/../test_site"/>
</launchConfiguration>