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
@@ -110,8 +110,7 @@ public final class GerritLauncher {
|
||||
|
||||
public static void daemonStart(final String[] argv) throws Exception {
|
||||
if (daemonClassLoader != null) {
|
||||
throw new IllegalStateException(
|
||||
"daemonStart can be called only once per JVM instance");
|
||||
throw new IllegalStateException("daemonStart can be called only once per JVM instance");
|
||||
}
|
||||
final ClassLoader cl = libClassLoader(false);
|
||||
Thread.currentThread().setContextClassLoader(cl);
|
||||
@@ -131,8 +130,7 @@ public final class GerritLauncher {
|
||||
|
||||
public static void daemonStop(final String[] argv) throws Exception {
|
||||
if (daemonClassLoader == null) {
|
||||
throw new IllegalStateException(
|
||||
"daemonStop can be called only after call to daemonStop");
|
||||
throw new IllegalStateException("daemonStop can be called only after call to daemonStop");
|
||||
}
|
||||
String[] daemonArgv = new String[argv.length + 2];
|
||||
daemonArgv[0] = "daemon";
|
||||
@@ -165,8 +163,8 @@ public final class GerritLauncher {
|
||||
}
|
||||
}
|
||||
|
||||
private static int invokeProgram(final ClassLoader loader,
|
||||
final String[] origArgv) throws Exception {
|
||||
private static int invokeProgram(final ClassLoader loader, final String[] origArgv)
|
||||
throws Exception {
|
||||
String name = origArgv[0];
|
||||
final String[] argv = new String[origArgv.length - 1];
|
||||
System.arraycopy(origArgv, 1, argv, 0, argv.length);
|
||||
@@ -236,8 +234,7 @@ public final class GerritLauncher {
|
||||
return cn;
|
||||
}
|
||||
|
||||
private static ClassLoader libClassLoader(boolean prologCompiler)
|
||||
throws IOException {
|
||||
private static ClassLoader libClassLoader(boolean prologCompiler) throws IOException {
|
||||
final File path;
|
||||
try {
|
||||
path = getDistributionArchive();
|
||||
@@ -287,17 +284,13 @@ public final class GerritLauncher {
|
||||
|
||||
ClassLoader parent = ClassLoader.getSystemClassLoader();
|
||||
if (!extapi.isEmpty()) {
|
||||
parent = new URLClassLoader(
|
||||
extapi.toArray(new URL[extapi.size()]),
|
||||
parent);
|
||||
parent = new URLClassLoader(extapi.toArray(new URL[extapi.size()]), parent);
|
||||
}
|
||||
return new URLClassLoader(
|
||||
jars.values().toArray(new URL[jars.size()]),
|
||||
parent);
|
||||
return new URLClassLoader(jars.values().toArray(new URL[jars.size()]), parent);
|
||||
}
|
||||
|
||||
private static void extractJar(ZipFile zf, ZipEntry ze,
|
||||
SortedMap<String, URL> jars) throws IOException {
|
||||
private static void extractJar(ZipFile zf, ZipEntry ze, SortedMap<String, URL> jars)
|
||||
throws IOException {
|
||||
File tmp = createTempFile(safeName(ze), ".jar");
|
||||
try (FileOutputStream out = new FileOutputStream(tmp);
|
||||
InputStream in = zf.getInputStream(ze)) {
|
||||
@@ -309,14 +302,10 @@ public final class GerritLauncher {
|
||||
}
|
||||
|
||||
String name = ze.getName();
|
||||
jars.put(
|
||||
name.substring(name.lastIndexOf('/'), name.length()),
|
||||
tmp.toURI().toURL());
|
||||
jars.put(name.substring(name.lastIndexOf('/'), name.length()), tmp.toURI().toURL());
|
||||
}
|
||||
|
||||
private static void move(SortedMap<String, URL> jars,
|
||||
String prefix,
|
||||
List<URL> extapi) {
|
||||
private static void move(SortedMap<String, URL> jars, String prefix, List<URL> extapi) {
|
||||
SortedMap<String, URL> matches = jars.tailMap(prefix);
|
||||
if (!matches.isEmpty()) {
|
||||
String first = matches.firstKey();
|
||||
@@ -355,8 +344,7 @@ public final class GerritLauncher {
|
||||
* @return local path of the Gerrit WAR file.
|
||||
* @throws FileNotFoundException if the code cannot guess the location.
|
||||
*/
|
||||
public static File getDistributionArchive()
|
||||
throws FileNotFoundException, IOException {
|
||||
public static File getDistributionArchive() throws FileNotFoundException, IOException {
|
||||
File result = myArchive;
|
||||
if (result == null) {
|
||||
synchronized (GerritLauncher.class) {
|
||||
@@ -371,8 +359,7 @@ public final class GerritLauncher {
|
||||
return result;
|
||||
}
|
||||
|
||||
public static synchronized FileSystem getZipFileSystem(Path zip)
|
||||
throws IOException {
|
||||
public static synchronized FileSystem getZipFileSystem(Path zip) throws IOException {
|
||||
// FileSystems canonicalizes the path, so we should too.
|
||||
zip = zip.toRealPath();
|
||||
FileSystem zipFs = zipFileSystems.get(zip);
|
||||
@@ -385,14 +372,12 @@ public final class GerritLauncher {
|
||||
|
||||
public static FileSystem newZipFileSystem(Path zip) throws IOException {
|
||||
return FileSystems.newFileSystem(
|
||||
URI.create("jar:" + zip.toUri()),
|
||||
Collections.<String, String> emptyMap());
|
||||
URI.create("jar:" + zip.toUri()), Collections.<String, String>emptyMap());
|
||||
}
|
||||
|
||||
private static File locateMyArchive() throws FileNotFoundException {
|
||||
final ClassLoader myCL = GerritLauncher.class.getClassLoader();
|
||||
final String myName =
|
||||
GerritLauncher.class.getName().replace('.', '/') + ".class";
|
||||
final String myName = GerritLauncher.class.getName().replace('.', '/') + ".class";
|
||||
|
||||
final URL myClazz = myCL.getResource(myName);
|
||||
if (myClazz == null) {
|
||||
@@ -424,8 +409,7 @@ public final class GerritLauncher {
|
||||
// The CodeSource might be able to give us the source as a stream.
|
||||
// If so, copy it to a local file so we have random access to it.
|
||||
//
|
||||
final CodeSource src =
|
||||
GerritLauncher.class.getProtectionDomain().getCodeSource();
|
||||
final CodeSource src = GerritLauncher.class.getProtectionDomain().getCodeSource();
|
||||
if (src != null) {
|
||||
try (InputStream in = src.getLocation().openStream()) {
|
||||
final File tmp = createTempFile("gerrit_", ".zip");
|
||||
@@ -451,35 +435,30 @@ public final class GerritLauncher {
|
||||
|
||||
/**
|
||||
* Creates a temporary file within the application's unpack location.
|
||||
* <p>
|
||||
* The launcher unpacks the nested JAR files into a temporary directory,
|
||||
* allowing the classes to be loaded from local disk with standard Java APIs.
|
||||
* This method constructs a new temporary file in the same directory.
|
||||
* <p>
|
||||
* The method first tries to create {@code prefix + suffix} within the
|
||||
* directory under the assumption that a given {@code prefix + suffix}
|
||||
* combination is made at most once per JVM execution. If this fails (e.g. the
|
||||
* named file already exists) a mangled unique name is used and returned
|
||||
* instead, with the unique string appearing between the prefix and suffix.
|
||||
* <p>
|
||||
* Files created by this method will be automatically deleted by the JVM when
|
||||
* it terminates. If the returned file is converted into a directory by the
|
||||
* caller, the caller must arrange for the contents to be deleted before the
|
||||
* directory is.
|
||||
* <p>
|
||||
* If supported by the underlying operating system, the temporary directory
|
||||
* which contains these temporary files is accessible only by the user running
|
||||
* the JVM.
|
||||
*
|
||||
* <p>The launcher unpacks the nested JAR files into a temporary directory, allowing the classes
|
||||
* to be loaded from local disk with standard Java APIs. This method constructs a new temporary
|
||||
* file in the same directory.
|
||||
*
|
||||
* <p>The method first tries to create {@code prefix + suffix} within the directory under the
|
||||
* assumption that a given {@code prefix + suffix} combination is made at most once per JVM
|
||||
* execution. If this fails (e.g. the named file already exists) a mangled unique name is used and
|
||||
* returned instead, with the unique string appearing between the prefix and suffix.
|
||||
*
|
||||
* <p>Files created by this method will be automatically deleted by the JVM when it terminates. If
|
||||
* the returned file is converted into a directory by the caller, the caller must arrange for the
|
||||
* contents to be deleted before the directory is.
|
||||
*
|
||||
* <p>If supported by the underlying operating system, the temporary directory which contains
|
||||
* these temporary files is accessible only by the user running the JVM.
|
||||
*
|
||||
* @param prefix prefix of the file name.
|
||||
* @param suffix suffix of the file name.
|
||||
* @return the path of the temporary file. The returned object exists in the
|
||||
* filesystem as a file; caller may need to delete and recreate as a
|
||||
* directory if a directory was preferred.
|
||||
* @return the path of the temporary file. The returned object exists in the filesystem as a file;
|
||||
* caller may need to delete and recreate as a directory if a directory was preferred.
|
||||
* @throws IOException the file could not be created.
|
||||
*/
|
||||
public static synchronized File createTempFile(String prefix, String suffix)
|
||||
throws IOException {
|
||||
public static synchronized File createTempFile(String prefix, String suffix) throws IOException {
|
||||
if (!temporaryDirectoryFound) {
|
||||
final File d = File.createTempFile("gerrit_", "_app", tmproot());
|
||||
if (d.delete() && d.mkdir()) {
|
||||
@@ -533,7 +512,6 @@ public final class GerritLauncher {
|
||||
return myHome;
|
||||
}
|
||||
|
||||
|
||||
private static File tmproot() {
|
||||
File tmp;
|
||||
String gerritTemp = System.getenv("GERRIT_TMP");
|
||||
@@ -634,8 +612,7 @@ public final class GerritLauncher {
|
||||
* @return local path of the {@code name} directory in a source tree.
|
||||
* @throws FileNotFoundException if the directory cannot be found.
|
||||
*/
|
||||
public static Path resolveInSourceRoot(String name)
|
||||
throws FileNotFoundException {
|
||||
public static Path resolveInSourceRoot(String name) throws FileNotFoundException {
|
||||
|
||||
// Find ourselves in the classpath, as a loose class file or jar.
|
||||
Class<GerritLauncher> self = GerritLauncher.class;
|
||||
@@ -644,13 +621,11 @@ public final class GerritLauncher {
|
||||
try (InputStream stream = self.getResourceAsStream(SOURCE_ROOT_RESOURCE)) {
|
||||
System.err.println("URL: " + stream);
|
||||
if (stream != null) {
|
||||
try (Scanner scan =
|
||||
new Scanner(stream, UTF_8.name()).useDelimiter("\n")) {
|
||||
try (Scanner scan = new Scanner(stream, UTF_8.name()).useDelimiter("\n")) {
|
||||
if (scan.hasNext()) {
|
||||
Path p = Paths.get(scan.next());
|
||||
if (!Files.exists(p)) {
|
||||
throw new FileNotFoundException(
|
||||
"source root not found: " + p);
|
||||
throw new FileNotFoundException("source root not found: " + p);
|
||||
}
|
||||
return p;
|
||||
}
|
||||
@@ -668,8 +643,7 @@ public final class GerritLauncher {
|
||||
try {
|
||||
u = new URL(p.substring(0, p.indexOf('!')));
|
||||
} catch (MalformedURLException e) {
|
||||
FileNotFoundException fnfe =
|
||||
new FileNotFoundException("Not a valid jar file: " + u);
|
||||
FileNotFoundException fnfe = new FileNotFoundException("Not a valid jar file: " + u);
|
||||
fnfe.initCause(e);
|
||||
throw fnfe;
|
||||
}
|
||||
@@ -690,14 +664,12 @@ public final class GerritLauncher {
|
||||
|
||||
Path ret = dir.resolve(name);
|
||||
if (!Files.exists(ret)) {
|
||||
throw new FileNotFoundException(
|
||||
name + " not found in source root " + dir);
|
||||
throw new FileNotFoundException(name + " not found in source root " + dir);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
private static ClassLoader useDevClasspath()
|
||||
throws MalformedURLException, FileNotFoundException {
|
||||
private static ClassLoader useDevClasspath() throws MalformedURLException, FileNotFoundException {
|
||||
Path out = resolveInSourceRoot("eclipse-out");
|
||||
List<URL> dirs = new ArrayList<>();
|
||||
dirs.add(out.resolve("classes").toUri().toURL());
|
||||
@@ -708,8 +680,7 @@ public final class GerritLauncher {
|
||||
}
|
||||
}
|
||||
return new URLClassLoader(
|
||||
dirs.toArray(new URL[dirs.size()]),
|
||||
ClassLoader.getSystemClassLoader().getParent());
|
||||
dirs.toArray(new URL[dirs.size()]), ClassLoader.getSystemClassLoader().getParent());
|
||||
}
|
||||
|
||||
private static boolean includeJar(URL u) {
|
||||
@@ -719,6 +690,5 @@ public final class GerritLauncher {
|
||||
&& !path.contains("/buck-out/gen/lib/gwt/");
|
||||
}
|
||||
|
||||
private GerritLauncher() {
|
||||
}
|
||||
private GerritLauncher() {}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user