Format all Java files with google-java-format
Having a standard tool for formatting saves reviewers' valuable time. google-java-format is Google's standard formatter and is somewhat inspired by gofmt[1]. This commit formats everything using google-java-format version 1.2. The downside of this one-off formatting is breaking blame. This can be somewhat hacked around with a tool like git-hyper-blame[2], but it's definitely not optimal until/unless this kind of feature makes its way to git core. Not in this change: * Tool support, e.g. Eclipse. The command must be run manually [3]. * Documentation of best practice, e.g. new 100-column default. [1] https://talks.golang.org/2015/gofmt-en.slide#3 [2] https://commondatastorage.googleapis.com/chrome-infra-docs/flat/depot_tools/docs/html/git-hyper-blame.html [3] git ls-files | grep java$ | xargs google-java-format -i Change-Id: Id5f3c6de95ce0b68b41f0a478b5c99a93675aaa3 Signed-off-by: David Pursehouse <dpursehouse@collab.net>
This commit is contained in:
committed by
David Pursehouse
parent
6723b6d0fa
commit
292fa154c1
@@ -18,15 +18,13 @@ import com.google.gerrit.extensions.events.LifecycleListener;
|
||||
import com.google.inject.Provider;
|
||||
import com.google.inject.ProvisionException;
|
||||
import com.google.inject.Singleton;
|
||||
|
||||
import javax.naming.InitialContext;
|
||||
import javax.naming.NamingException;
|
||||
import javax.sql.DataSource;
|
||||
|
||||
/** Provides access to the {@code ReviewDb} DataSource. */
|
||||
@Singleton
|
||||
final class ReviewDbDataSourceProvider implements Provider<DataSource>,
|
||||
LifecycleListener {
|
||||
final class ReviewDbDataSourceProvider implements Provider<DataSource>, LifecycleListener {
|
||||
private DataSource ds;
|
||||
|
||||
@Override
|
||||
@@ -38,8 +36,7 @@ final class ReviewDbDataSourceProvider implements Provider<DataSource>,
|
||||
}
|
||||
|
||||
@Override
|
||||
public void start() {
|
||||
}
|
||||
public void start() {}
|
||||
|
||||
@Override
|
||||
public synchronized void stop() {
|
||||
|
||||
@@ -16,10 +16,6 @@ package com.google.gerrit.httpd;
|
||||
|
||||
import com.google.gerrit.pgm.init.BaseInit;
|
||||
import com.google.gerrit.pgm.init.PluginsDistribution;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
import java.sql.Connection;
|
||||
@@ -27,18 +23,22 @@ import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.sql.Statement;
|
||||
import java.util.List;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
public final class SiteInitializer {
|
||||
private static final Logger LOG = LoggerFactory
|
||||
.getLogger(SiteInitializer.class);
|
||||
private static final Logger LOG = LoggerFactory.getLogger(SiteInitializer.class);
|
||||
|
||||
private final String sitePath;
|
||||
private final String initPath;
|
||||
private final PluginsDistribution pluginsDistribution;
|
||||
private final List<String> pluginsToInstall;
|
||||
|
||||
SiteInitializer(String sitePath, String initPath,
|
||||
PluginsDistribution pluginsDistribution, List<String> pluginsToInstall) {
|
||||
SiteInitializer(
|
||||
String sitePath,
|
||||
String initPath,
|
||||
PluginsDistribution pluginsDistribution,
|
||||
List<String> pluginsToInstall) {
|
||||
this.sitePath = sitePath;
|
||||
this.initPath = initPath;
|
||||
this.pluginsDistribution = pluginsDistribution;
|
||||
@@ -61,8 +61,14 @@ public final class SiteInitializer {
|
||||
}
|
||||
if (site != null) {
|
||||
LOG.info("Initializing site at " + site.toRealPath().normalize());
|
||||
new BaseInit(site, new ReviewDbDataSourceProvider(), false, false,
|
||||
pluginsDistribution, pluginsToInstall).run();
|
||||
new BaseInit(
|
||||
site,
|
||||
new ReviewDbDataSourceProvider(),
|
||||
false,
|
||||
false,
|
||||
pluginsDistribution,
|
||||
pluginsToInstall)
|
||||
.run();
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
@@ -77,8 +83,7 @@ public final class SiteInitializer {
|
||||
|
||||
private Path getSiteFromReviewDb(Connection conn) {
|
||||
try (Statement stmt = conn.createStatement();
|
||||
ResultSet rs = stmt.executeQuery(
|
||||
"SELECT site_path FROM system_config")) {
|
||||
ResultSet rs = stmt.executeQuery("SELECT site_path FROM system_config")) {
|
||||
if (rs.next()) {
|
||||
return Paths.get(rs.getString(1));
|
||||
}
|
||||
|
||||
@@ -21,7 +21,6 @@ import com.google.gwtorm.server.OrmException;
|
||||
import com.google.gwtorm.server.SchemaFactory;
|
||||
import com.google.inject.Inject;
|
||||
import com.google.inject.Provider;
|
||||
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.List;
|
||||
@@ -31,8 +30,7 @@ class SitePathFromSystemConfigProvider implements Provider<Path> {
|
||||
private final Path path;
|
||||
|
||||
@Inject
|
||||
SitePathFromSystemConfigProvider(SchemaFactory<ReviewDb> schemaFactory)
|
||||
throws OrmException {
|
||||
SitePathFromSystemConfigProvider(SchemaFactory<ReviewDb> schemaFactory) throws OrmException {
|
||||
path = read(schemaFactory);
|
||||
}
|
||||
|
||||
@@ -41,8 +39,7 @@ class SitePathFromSystemConfigProvider implements Provider<Path> {
|
||||
return path;
|
||||
}
|
||||
|
||||
private static Path read(SchemaFactory<ReviewDb> schemaFactory)
|
||||
throws OrmException {
|
||||
private static Path read(SchemaFactory<ReviewDb> schemaFactory) throws OrmException {
|
||||
try (ReviewDb db = schemaFactory.open()) {
|
||||
List<SystemConfig> all = db.systemConfig().all().toList();
|
||||
switch (all.size()) {
|
||||
@@ -51,8 +48,8 @@ class SitePathFromSystemConfigProvider implements Provider<Path> {
|
||||
case 0:
|
||||
throw new OrmException("system_config table is empty");
|
||||
default:
|
||||
throw new OrmException("system_config must have exactly 1 row;"
|
||||
+ " found " + all.size() + " rows instead");
|
||||
throw new OrmException(
|
||||
"system_config must have exactly 1 row;" + " found " + all.size() + " rows instead");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,7 +19,6 @@ import static com.google.gerrit.pgm.init.InitPlugins.PLUGIN_DIR;
|
||||
|
||||
import com.google.gerrit.pgm.init.PluginsDistribution;
|
||||
import com.google.inject.Singleton;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileNotFoundException;
|
||||
@@ -27,7 +26,6 @@ import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import javax.servlet.ServletContext;
|
||||
|
||||
@Singleton
|
||||
@@ -46,8 +44,7 @@ class UnzippedDistribution implements PluginsDistribution {
|
||||
if (list != null) {
|
||||
for (File p : list) {
|
||||
String pluginJarName = p.getName();
|
||||
String pluginName = pluginJarName.substring(0,
|
||||
pluginJarName.length() - JAR.length());
|
||||
String pluginName = pluginJarName.substring(0, pluginJarName.length() - JAR.length());
|
||||
try (InputStream in = new FileInputStream(p)) {
|
||||
processor.process(pluginName, in);
|
||||
}
|
||||
@@ -61,8 +58,7 @@ class UnzippedDistribution implements PluginsDistribution {
|
||||
String[] list = getPluginsDir().list();
|
||||
if (list != null) {
|
||||
for (String pluginJarName : list) {
|
||||
String pluginName = pluginJarName.substring(0,
|
||||
pluginJarName.length() - JAR.length());
|
||||
String pluginName = pluginJarName.substring(0, pluginJarName.length() - JAR.length());
|
||||
names.add(pluginName);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -90,18 +90,12 @@ import com.google.inject.servlet.GuiceFilter;
|
||||
import com.google.inject.servlet.GuiceServletContextListener;
|
||||
import com.google.inject.spi.Message;
|
||||
import com.google.inject.util.Providers;
|
||||
|
||||
import org.eclipse.jgit.lib.Config;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import javax.servlet.Filter;
|
||||
import javax.servlet.FilterChain;
|
||||
import javax.servlet.FilterConfig;
|
||||
@@ -112,12 +106,13 @@ import javax.servlet.ServletRequest;
|
||||
import javax.servlet.ServletResponse;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.sql.DataSource;
|
||||
import org.eclipse.jgit.lib.Config;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
/** Configures the web application environment for Gerrit Code Review. */
|
||||
public class WebAppInitializer extends GuiceServletContextListener
|
||||
implements Filter {
|
||||
private static final Logger log =
|
||||
LoggerFactory.getLogger(WebAppInitializer.class);
|
||||
public class WebAppInitializer extends GuiceServletContextListener implements Filter {
|
||||
private static final Logger log = LoggerFactory.getLogger(WebAppInitializer.class);
|
||||
|
||||
private Path sitePath;
|
||||
private Injector dbInjector;
|
||||
@@ -133,8 +128,8 @@ public class WebAppInitializer extends GuiceServletContextListener
|
||||
private IndexType indexType;
|
||||
|
||||
@Override
|
||||
public void doFilter(ServletRequest req, ServletResponse res,
|
||||
FilterChain chain) throws IOException, ServletException {
|
||||
public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain)
|
||||
throws IOException, ServletException {
|
||||
filter.doFilter(req, res, chain);
|
||||
}
|
||||
|
||||
@@ -151,11 +146,15 @@ public class WebAppInitializer extends GuiceServletContextListener
|
||||
if (installPlugins == null) {
|
||||
pluginsToInstall = null;
|
||||
} else {
|
||||
pluginsToInstall = Splitter.on(",").trimResults().omitEmptyStrings()
|
||||
.splitToList(installPlugins);
|
||||
pluginsToInstall =
|
||||
Splitter.on(",").trimResults().omitEmptyStrings().splitToList(installPlugins);
|
||||
}
|
||||
new SiteInitializer(path, System.getProperty("gerrit.init_path"),
|
||||
new UnzippedDistribution(servletContext), pluginsToInstall).init();
|
||||
new SiteInitializer(
|
||||
path,
|
||||
System.getProperty("gerrit.init_path"),
|
||||
new UnzippedDistribution(servletContext),
|
||||
pluginsToInstall)
|
||||
.init();
|
||||
}
|
||||
|
||||
try {
|
||||
@@ -181,8 +180,7 @@ public class WebAppInitializer extends GuiceServletContextListener
|
||||
|
||||
cfgInjector = createCfgInjector();
|
||||
initIndexType();
|
||||
config = cfgInjector.getInstance(
|
||||
Key.get(Config.class, GerritServerConfig.class));
|
||||
config = cfgInjector.getInstance(Key.get(Config.class, GerritServerConfig.class));
|
||||
sysInjector = createSysInjector();
|
||||
if (!sshdOff()) {
|
||||
sshInjector = createSshInjector();
|
||||
@@ -205,9 +203,9 @@ public class WebAppInitializer extends GuiceServletContextListener
|
||||
// injection here because the HTTP environment is not visible
|
||||
// to the core server modules.
|
||||
//
|
||||
sysInjector.getInstance(HttpCanonicalWebUrlProvider.class)
|
||||
.setHttpServletRequest(
|
||||
webInjector.getProvider(HttpServletRequest.class));
|
||||
sysInjector
|
||||
.getInstance(HttpCanonicalWebUrlProvider.class)
|
||||
.setHttpServletRequest(webInjector.getProvider(HttpServletRequest.class));
|
||||
|
||||
filter = webInjector.getInstance(GuiceFilter.class);
|
||||
manager = new LifecycleManager();
|
||||
@@ -230,46 +228,50 @@ public class WebAppInitializer extends GuiceServletContextListener
|
||||
AbstractModule secureStore = createSecureStoreModule();
|
||||
modules.add(secureStore);
|
||||
if (sitePath != null) {
|
||||
Module sitePathModule = new AbstractModule() {
|
||||
@Override
|
||||
protected void configure() {
|
||||
bind(Path.class).annotatedWith(SitePath.class).toInstance(sitePath);
|
||||
}
|
||||
};
|
||||
Module sitePathModule =
|
||||
new AbstractModule() {
|
||||
@Override
|
||||
protected void configure() {
|
||||
bind(Path.class).annotatedWith(SitePath.class).toInstance(sitePath);
|
||||
}
|
||||
};
|
||||
modules.add(sitePathModule);
|
||||
|
||||
Module configModule = new GerritServerConfigModule();
|
||||
modules.add(configModule);
|
||||
|
||||
Injector cfgInjector = Guice.createInjector(sitePathModule, configModule, secureStore);
|
||||
Config cfg = cfgInjector.getInstance(Key.get(Config.class,
|
||||
GerritServerConfig.class));
|
||||
Config cfg = cfgInjector.getInstance(Key.get(Config.class, GerritServerConfig.class));
|
||||
String dbType = cfg.getString("database", null, "type");
|
||||
|
||||
final DataSourceType dst = Guice.createInjector(new DataSourceModule(),
|
||||
configModule, sitePathModule, secureStore).getInstance(
|
||||
Key.get(DataSourceType.class, Names.named(dbType.toLowerCase())));
|
||||
modules.add(new LifecycleModule() {
|
||||
@Override
|
||||
protected void configure() {
|
||||
bind(DataSourceType.class).toInstance(dst);
|
||||
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);
|
||||
}
|
||||
});
|
||||
final DataSourceType dst =
|
||||
Guice.createInjector(new DataSourceModule(), configModule, sitePathModule, secureStore)
|
||||
.getInstance(Key.get(DataSourceType.class, Names.named(dbType.toLowerCase())));
|
||||
modules.add(
|
||||
new LifecycleModule() {
|
||||
@Override
|
||||
protected void configure() {
|
||||
bind(DataSourceType.class).toInstance(dst);
|
||||
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);
|
||||
}
|
||||
});
|
||||
|
||||
} 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 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());
|
||||
modules.add(new DropWizardMetricMaker.ApiModule());
|
||||
@@ -283,13 +285,16 @@ public class WebAppInitializer extends GuiceServletContextListener
|
||||
// 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(Path.class).annotatedWith(SitePath.class).toProvider(
|
||||
SitePathFromSystemConfigProvider.class).in(SINGLETON);
|
||||
}
|
||||
});
|
||||
modules.add(
|
||||
new AbstractModule() {
|
||||
@Override
|
||||
protected void configure() {
|
||||
bind(Path.class)
|
||||
.annotatedWith(SitePath.class)
|
||||
.toProvider(SitePathFromSystemConfigProvider.class)
|
||||
.in(SINGLETON);
|
||||
}
|
||||
});
|
||||
modules.add(new GerritServerConfigModule());
|
||||
}
|
||||
modules.add(new SchemaModule());
|
||||
@@ -327,20 +332,21 @@ public class WebAppInitializer extends GuiceServletContextListener
|
||||
modules.add(createIndexModule());
|
||||
|
||||
modules.add(new WorkQueue.Module());
|
||||
modules.add(new CanonicalWebUrlModule() {
|
||||
@Override
|
||||
protected Class<? extends Provider<String>> provider() {
|
||||
return HttpCanonicalWebUrlProvider.class;
|
||||
}
|
||||
});
|
||||
modules.add(
|
||||
new CanonicalWebUrlModule() {
|
||||
@Override
|
||||
protected Class<? extends Provider<String>> provider() {
|
||||
return HttpCanonicalWebUrlProvider.class;
|
||||
}
|
||||
});
|
||||
modules.add(SshKeyCacheImpl.module());
|
||||
modules.add(new AbstractModule() {
|
||||
@Override
|
||||
protected void configure() {
|
||||
bind(GerritOptions.class)
|
||||
.toInstance(new GerritOptions(config, false, false, false));
|
||||
}
|
||||
});
|
||||
modules.add(
|
||||
new AbstractModule() {
|
||||
@Override
|
||||
protected void configure() {
|
||||
bind(GerritOptions.class).toInstance(new GerritOptions(config, false, false, false));
|
||||
}
|
||||
});
|
||||
modules.add(new GarbageCollectionModule());
|
||||
modules.add(new ChangeCleanupRunner.Module());
|
||||
modules.addAll(LibModuleLoader.loadModules(cfgInjector));
|
||||
@@ -366,9 +372,11 @@ public class WebAppInitializer extends GuiceServletContextListener
|
||||
final List<Module> modules = new ArrayList<>();
|
||||
modules.add(sysInjector.getInstance(SshModule.class));
|
||||
modules.add(new SshHostKeyModule());
|
||||
modules.add(new DefaultCommandModule(false,
|
||||
sysInjector.getInstance(DownloadConfig.class),
|
||||
sysInjector.getInstance(LfsPluginAuthCommand.Module.class)));
|
||||
modules.add(
|
||||
new DefaultCommandModule(
|
||||
false,
|
||||
sysInjector.getInstance(DownloadConfig.class),
|
||||
sysInjector.getInstance(LfsPluginAuthCommand.Module.class)));
|
||||
if (indexType == IndexType.LUCENE) {
|
||||
modules.add(new IndexCommandsModule());
|
||||
}
|
||||
@@ -431,10 +439,10 @@ public class WebAppInitializer extends GuiceServletContextListener
|
||||
return new AbstractModule() {
|
||||
@Override
|
||||
public void configure() {
|
||||
String secureStoreClassName =
|
||||
GerritServerConfigModule.getSecureStoreClassName(sitePath);
|
||||
bind(String.class).annotatedWith(SecureStoreClassName.class).toProvider(
|
||||
Providers.of(secureStoreClassName));
|
||||
String secureStoreClassName = GerritServerConfigModule.getSecureStoreClassName(sitePath);
|
||||
bind(String.class)
|
||||
.annotatedWith(SecureStoreClassName.class)
|
||||
.toProvider(Providers.of(secureStoreClassName));
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user