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:
Dave Borowitz
2016-11-13 09:56:32 -08:00
committed by David Pursehouse
parent 6723b6d0fa
commit 292fa154c1
2443 changed files with 54816 additions and 57825 deletions

View File

@@ -14,11 +14,10 @@
package com.google.gerrit.pgm.init;
import org.eclipse.jgit.junit.LocalDiskRepositoryTestCase;
import org.junit.Ignore;
import java.io.IOException;
import java.nio.file.Path;
import org.eclipse.jgit.junit.LocalDiskRepositoryTestCase;
import org.junit.Ignore;
@Ignore
public abstract class InitTestCase extends LocalDiskRepositoryTestCase {

View File

@@ -22,11 +22,9 @@ import static org.junit.Assert.assertNotNull;
import com.google.gerrit.pgm.init.api.ConsoleUI;
import com.google.gerrit.server.config.SitePaths;
import com.google.inject.Provider;
import org.junit.Test;
import java.nio.file.Paths;
import java.util.Collections;
import org.junit.Test;
public class LibrariesTest {
@Test
@@ -36,12 +34,16 @@ public class LibrariesTest {
replay(ui);
Libraries lib = new Libraries(new Provider<LibraryDownloader>() {
@Override
public LibraryDownloader get() {
return new LibraryDownloader(ui, site);
}
}, Collections.<String> emptyList(), false);
Libraries lib =
new Libraries(
new Provider<LibraryDownloader>() {
@Override
public LibraryDownloader get() {
return new LibraryDownloader(ui, site);
}
},
Collections.<String>emptyList(),
false);
assertNotNull(lib.bouncyCastleProvider);
assertNotNull(lib.mysqlDriver);

View File

@@ -32,20 +32,17 @@ import com.google.gerrit.pgm.init.api.InitFlags;
import com.google.gerrit.pgm.init.api.Section;
import com.google.gerrit.server.config.SitePaths;
import com.google.gerrit.server.securestore.SecureStore;
import org.eclipse.jgit.errors.ConfigInvalidException;
import org.eclipse.jgit.lib.Config;
import org.eclipse.jgit.storage.file.FileBasedConfig;
import org.eclipse.jgit.util.FS;
import org.junit.Test;
import java.io.IOException;
import java.io.InputStream;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.Collections;
import java.util.List;
import org.eclipse.jgit.errors.ConfigInvalidException;
import org.eclipse.jgit.lib.Config;
import org.eclipse.jgit.storage.file.FileBasedConfig;
import org.eclipse.jgit.util.FS;
import org.junit.Test;
public class UpgradeFrom2_0_xTest extends InitTestCase {
@@ -60,8 +57,7 @@ public class UpgradeFrom2_0_xTest extends InitTestCase {
Files.write(p.resolve(n), ("# " + n + "\n").getBytes(UTF_8));
}
FileBasedConfig old =
new FileBasedConfig(p.resolve("gerrit.config").toFile(), FS.DETECTED);
FileBasedConfig old = new FileBasedConfig(p.resolve("gerrit.config").toFile(), FS.DETECTED);
old.setString("ldap", null, "username", "ldap.user");
old.setString("ldap", null, "password", "ldap.s3kr3t");
@@ -71,21 +67,19 @@ public class UpgradeFrom2_0_xTest extends InitTestCase {
old.save();
final InMemorySecureStore secureStore = new InMemorySecureStore();
final InitFlags flags = new InitFlags(site, secureStore,
Collections.<String> emptyList(), false);
final InitFlags flags =
new InitFlags(site, secureStore, Collections.<String>emptyList(), false);
final ConsoleUI ui = createStrictMock(ConsoleUI.class);
Section.Factory sections = new Section.Factory() {
@Override
public Section get(String name, String subsection) {
return new Section(flags, site, secureStore, ui, name, subsection);
}
};
Section.Factory sections =
new Section.Factory() {
@Override
public Section get(String name, String subsection) {
return new Section(flags, site, secureStore, ui, name, subsection);
}
};
expect(ui.yesno(
eq(true),
eq("Upgrade '%s'"),
eq(p.toAbsolutePath().normalize())))
.andReturn(true);
expect(ui.yesno(eq(true), eq("Upgrade '%s'"), eq(p.toAbsolutePath().normalize())))
.andReturn(true);
replay(ui);
UpgradeFrom2_0_x u = new UpgradeFrom2_0_x(site, flags, ui, sections);
@@ -99,13 +93,11 @@ public class UpgradeFrom2_0_xTest extends InitTestCase {
continue;
}
try (InputStream in = Files.newInputStream(site.etc_dir.resolve(n))) {
assertEquals("# " + n + "\n",
new String(ByteStreams.toByteArray(in), UTF_8));
assertEquals("# " + n + "\n", new String(ByteStreams.toByteArray(in), UTF_8));
}
}
FileBasedConfig cfg =
new FileBasedConfig(site.gerrit_config.toFile(), FS.DETECTED);
FileBasedConfig cfg = new FileBasedConfig(site.gerrit_config.toFile(), FS.DETECTED);
cfg.load();
assertEquals("email.user", cfg.getString("sendemail", null, "smtpUser"));
@@ -128,14 +120,13 @@ public class UpgradeFrom2_0_xTest extends InitTestCase {
}
@Override
public String[] getListForPlugin(String pluginName, String section,
String subsection, String name) {
public String[] getListForPlugin(
String pluginName, String section, String subsection, String name) {
throw new UnsupportedOperationException("not used by tests");
}
@Override
public void setList(String section, String subsection, String name,
List<String> values) {
public void setList(String section, String subsection, String name, List<String> values) {
cfg.setStringList(section, subsection, name, values);
}