aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorGravatar Liam Miller-Cushon <cushon@google.com>2017-01-10 04:05:58 +0000
committerGravatar Marcel Hlopko <hlopko@google.com>2017-01-10 10:23:32 +0000
commitb603417c0ba3c048cf8ea8d5d2bae04518a5d820 (patch)
treee8e431ac1f5b6fc1152e9f8fccc719bdaa0a0097
parent4878c69e18a09f5d798b8a56349c13624645845c (diff)
google-java-format buildjar
-- PiperOrigin-RevId: 144039394 MOS_MIGRATED_REVID=144039394
-rw-r--r--src/java_tools/buildjar/java/com/google/devtools/build/buildjar/AbstractJavaBuilder.java48
-rw-r--r--src/java_tools/buildjar/java/com/google/devtools/build/buildjar/AbstractLibraryBuilder.java75
-rw-r--r--src/java_tools/buildjar/java/com/google/devtools/build/buildjar/AbstractPostProcessor.java14
-rw-r--r--src/java_tools/buildjar/java/com/google/devtools/build/buildjar/BazelJavaBuilder.java25
-rw-r--r--src/java_tools/buildjar/java/com/google/devtools/build/buildjar/CommonJavaLibraryProcessor.java11
-rw-r--r--src/java_tools/buildjar/java/com/google/devtools/build/buildjar/InvalidCommandLineException.java6
-rw-r--r--src/java_tools/buildjar/java/com/google/devtools/build/buildjar/JavaLibraryBuildRequest.java28
-rw-r--r--src/java_tools/buildjar/java/com/google/devtools/build/buildjar/OptionsParser.java21
-rw-r--r--src/java_tools/buildjar/java/com/google/devtools/build/buildjar/SimpleJavaLibraryBuilder.java23
-rw-r--r--src/java_tools/buildjar/java/com/google/devtools/build/buildjar/genclass/GenClass.java27
-rw-r--r--src/java_tools/buildjar/java/com/google/devtools/build/buildjar/jarhelper/JarCreator.java36
-rw-r--r--src/java_tools/buildjar/java/com/google/devtools/build/buildjar/jarhelper/JarHelper.java37
-rw-r--r--src/java_tools/buildjar/java/com/google/devtools/build/buildjar/javac/BlazeJavaCompiler.java39
-rw-r--r--src/java_tools/buildjar/java/com/google/devtools/build/buildjar/javac/BlazeJavacMain.java52
-rw-r--r--src/java_tools/buildjar/java/com/google/devtools/build/buildjar/javac/JavacOptions.java10
-rw-r--r--src/java_tools/buildjar/java/com/google/devtools/build/buildjar/javac/JavacRunner.java6
-rw-r--r--src/java_tools/buildjar/java/com/google/devtools/build/buildjar/javac/plugins/BlazeJavaCompilerPlugin.java34
-rw-r--r--src/java_tools/buildjar/java/com/google/devtools/build/buildjar/javac/plugins/classloader/ClassLoaderMaskingPlugin.java31
-rw-r--r--src/java_tools/buildjar/java/com/google/devtools/build/buildjar/javac/plugins/dependency/DependencyModule.java71
-rw-r--r--src/java_tools/buildjar/java/com/google/devtools/build/buildjar/javac/plugins/processing/AnnotationProcessingModule.java13
-rw-r--r--src/java_tools/buildjar/java/com/google/devtools/build/buildjar/javac/plugins/processing/AnnotationProcessingPlugin.java7
-rw-r--r--src/java_tools/buildjar/java/com/google/devtools/build/java/bazel/BazelJavaCompiler.java86
-rw-r--r--src/java_tools/buildjar/java/com/google/devtools/build/java/bazel/BazelJavac.java4
-rw-r--r--src/java_tools/buildjar/java/com/google/devtools/build/java/bazel/JavaBuilderConfigGenerator.java16
-rw-r--r--src/java_tools/buildjar/java/com/google/devtools/build/java/bazel/JavaLangtools.java8
-rw-r--r--src/java_tools/buildjar/java/com/google/devtools/build/java/bazel/JavacBootclasspath.java20
-rw-r--r--src/java_tools/buildjar/javatests/com/google/devtools/build/java/bazel/BazelJavaCompilerTest.java41
-rw-r--r--src/java_tools/buildjar/javatests/com/google/devtools/build/java/turbine/javac/TreePrunerTest.java28
28 files changed, 340 insertions, 477 deletions
diff --git a/src/java_tools/buildjar/java/com/google/devtools/build/buildjar/AbstractJavaBuilder.java b/src/java_tools/buildjar/java/com/google/devtools/build/buildjar/AbstractJavaBuilder.java
index 488184966f..fe9df0d761 100644
--- a/src/java_tools/buildjar/java/com/google/devtools/build/buildjar/AbstractJavaBuilder.java
+++ b/src/java_tools/buildjar/java/com/google/devtools/build/buildjar/AbstractJavaBuilder.java
@@ -20,9 +20,7 @@ import com.google.common.io.Files;
import com.google.devtools.build.buildjar.javac.BlazeJavacMain;
import com.google.devtools.build.buildjar.javac.JavacRunner;
import com.google.devtools.build.buildjar.javac.plugins.BlazeJavaCompilerPlugin;
-
import com.sun.tools.javac.main.Main.Result;
-
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileOutputStream;
@@ -33,9 +31,9 @@ import java.util.List;
import java.util.zip.ZipEntry;
/**
- * A command line interface to compile a java_library rule using in-process
- * javac. This allows us to spawn multiple java_library compilations on a
- * single machine or distribute Java compilations to multiple machines.
+ * A command line interface to compile a java_library rule using in-process javac. This allows us to
+ * spawn multiple java_library compilations on a single machine or distribute Java compilations to
+ * multiple machines.
*/
public abstract class AbstractJavaBuilder extends AbstractLibraryBuilder {
@@ -71,14 +69,11 @@ public abstract class AbstractJavaBuilder extends AbstractLibraryBuilder {
return result;
}
- /**
- * Build a jar file containing source files that were generated by an annotation processor.
- */
+ /** Build a jar file containing source files that were generated by an annotation processor. */
public abstract void buildGensrcJar(JavaLibraryBuildRequest build) throws IOException;
@VisibleForTesting
- protected void runClassPostProcessing(JavaLibraryBuildRequest build)
- throws IOException {
+ protected void runClassPostProcessing(JavaLibraryBuildRequest build) throws IOException {
for (AbstractPostProcessor postProcessor : build.getPostProcessors()) {
postProcessor.initialize(build);
postProcessor.processRequest();
@@ -86,22 +81,18 @@ public abstract class AbstractJavaBuilder extends AbstractLibraryBuilder {
}
/**
- * Compiles the java files specified in 'JavaLibraryBuildRequest'.
- * Implementations can try to avoid recompiling the java files. Whenever
- * this function is invoked, it is guaranteed that the build request
- * contains files to compile.
+ * Compiles the java files specified in 'JavaLibraryBuildRequest'. Implementations can try to
+ * avoid recompiling the java files. Whenever this function is invoked, it is guaranteed that the
+ * build request contains files to compile.
*
- * @param build A JavaLibraryBuildRequest request object describing what to
- * compile
+ * @param build A JavaLibraryBuildRequest request object describing what to compile
* @param err PrintWriter for logging any diagnostic output
* @return the exit status of the java compiler.
*/
- abstract Result compileSources(JavaLibraryBuildRequest build, JavacRunner javacRunner,
- PrintWriter err) throws IOException;
+ abstract Result compileSources(
+ JavaLibraryBuildRequest build, JavacRunner javacRunner, PrintWriter err) throws IOException;
- /**
- * Perform the build.
- */
+ /** Perform the build. */
public Result run(JavaLibraryBuildRequest build, PrintWriter err) throws Exception {
Result result = Result.ERROR;
try {
@@ -121,10 +112,7 @@ public abstract class AbstractJavaBuilder extends AbstractLibraryBuilder {
return result;
}
- /**
- * A SourceJarEntryListener that collects protobuf meta data files from the
- * source jar files.
- */
+ /** A SourceJarEntryListener that collects protobuf meta data files from the source jar files. */
private static class ProtoMetaFileCollector implements SourceJarEntryListener {
private final String sourceDir;
@@ -147,8 +135,8 @@ public abstract class AbstractJavaBuilder extends AbstractLibraryBuilder {
}
/**
- * Writes the combined the meta files into the output directory. Delete the
- * stalling meta file if no meta file is collected.
+ * Writes the combined the meta files into the output directory. Delete the stalling meta file
+ * if no meta file is collected.
*/
@Override
public void finish() throws IOException {
@@ -165,11 +153,9 @@ public abstract class AbstractJavaBuilder extends AbstractLibraryBuilder {
}
@Override
- protected List<SourceJarEntryListener> getSourceJarEntryListeners(
- JavaLibraryBuildRequest build) {
+ protected List<SourceJarEntryListener> getSourceJarEntryListeners(JavaLibraryBuildRequest build) {
List<SourceJarEntryListener> result = super.getSourceJarEntryListeners(build);
- result.add(new ProtoMetaFileCollector(
- build.getTempDir(), build.getClassDir()));
+ result.add(new ProtoMetaFileCollector(build.getTempDir(), build.getClassDir()));
return result;
}
}
diff --git a/src/java_tools/buildjar/java/com/google/devtools/build/buildjar/AbstractLibraryBuilder.java b/src/java_tools/buildjar/java/com/google/devtools/build/buildjar/AbstractLibraryBuilder.java
index e3db7574af..86a5b2db22 100644
--- a/src/java_tools/buildjar/java/com/google/devtools/build/buildjar/AbstractLibraryBuilder.java
+++ b/src/java_tools/buildjar/java/com/google/devtools/build/buildjar/AbstractLibraryBuilder.java
@@ -32,8 +32,7 @@ import java.util.zip.ZipFile;
/**
* Base class for java_library builders.
*
- * <p>Implements common functionality like source files preparation and
- * output jar creation.
+ * <p>Implements common functionality like source files preparation and output jar creation.
*/
public abstract class AbstractLibraryBuilder extends CommonJavaLibraryProcessor {
@@ -64,8 +63,8 @@ public abstract class AbstractLibraryBuilder extends CommonJavaLibraryProcessor
// The easiest way to handle resource jars is to unpack them into the class directory, just
// before we start zipping it up.
for (String resourceJar : build.getResourceJars()) {
- setUpSourceJar(new File(resourceJar), build.getClassDir(),
- new ArrayList<SourceJarEntryListener>());
+ setUpSourceJar(
+ new File(resourceJar), build.getClassDir(), new ArrayList<SourceJarEntryListener>());
}
jar.addDirectory(build.getClassDir());
@@ -78,10 +77,10 @@ public abstract class AbstractLibraryBuilder extends CommonJavaLibraryProcessor
}
/**
- * Adds a collection of resource entries. Each entry is a string composed of a
- * pair of parts separated by a colon ':'. The name of the resource comes from
- * the second part, and the path to the resource comes from the whole string
- * with the colon replaced by a slash '/'.
+ * Adds a collection of resource entries. Each entry is a string composed of a pair of parts
+ * separated by a colon ':'. The name of the resource comes from the second part, and the path to
+ * the resource comes from the whole string with the colon replaced by a slash '/'.
+ *
* <pre>
* prefix:name => (name, prefix/name)
* </pre>
@@ -100,8 +99,7 @@ public abstract class AbstractLibraryBuilder extends CommonJavaLibraryProcessor
}
}
- private static void addMessageEntries(JarCreator jar, List<String> messages)
- throws IOException {
+ private static void addMessageEntries(JarCreator jar, List<String> messages) throws IOException {
for (String message : messages) {
int colon = message.indexOf(':');
if (colon < 0) {
@@ -120,8 +118,8 @@ public abstract class AbstractLibraryBuilder extends CommonJavaLibraryProcessor
}
/**
- * Adds an entry to the jar, making sure that all the parent dirs up to the
- * base of {@code entry} are also added.
+ * Adds an entry to the jar, making sure that all the parent dirs up to the base of {@code entry}
+ * are also added.
*
* @param entry the PathFragment of the entry going into the Jar file
* @param file the PathFragment of the input file for the entry
@@ -135,11 +133,12 @@ public abstract class AbstractLibraryBuilder extends CommonJavaLibraryProcessor
}
/**
- * Internal interface which will listen on each entry of the source jar
- * files during the source jar setup process.
+ * Internal interface which will listen on each entry of the source jar files during the source
+ * jar setup process.
*/
protected interface SourceJarEntryListener {
void onEntry(ZipEntry entry) throws IOException;
+
void finish() throws IOException;
}
@@ -150,8 +149,7 @@ public abstract class AbstractLibraryBuilder extends CommonJavaLibraryProcessor
}
/**
- * A SourceJarEntryListener that collects a lists of source Java files from
- * the source jar files.
+ * A SourceJarEntryListener that collects a lists of source Java files from the source jar files.
*/
private static class SourceJavaFileCollector implements SourceJarEntryListener {
private final List<String> sources;
@@ -177,9 +175,8 @@ public abstract class AbstractLibraryBuilder extends CommonJavaLibraryProcessor
}
/**
- * Extracts the all source jars from the build request into the temporary
- * directory specified in the build request. Empties the temporary directory,
- * if it exists.
+ * Extracts the all source jars from the build request into the temporary directory specified in
+ * the build request. Empties the temporary directory, if it exists.
*/
private void setUpSourceJars(JavaLibraryBuildRequest build) throws IOException {
String sourcesDir = build.getTempDir();
@@ -203,12 +200,11 @@ public abstract class AbstractLibraryBuilder extends CommonJavaLibraryProcessor
}
/**
- * Extracts the source jar into the directory sourceDir. Calls each of the
- * SourceJarEntryListeners for each non-directory entry to do additional work.
+ * Extracts the source jar into the directory sourceDir. Calls each of the SourceJarEntryListeners
+ * for each non-directory entry to do additional work.
*/
- private void setUpSourceJar(File sourceJar, String sourceDir,
- List<SourceJarEntryListener> listeners)
- throws IOException {
+ private void setUpSourceJar(
+ File sourceJar, String sourceDir, List<SourceJarEntryListener> listeners) throws IOException {
try (ZipFile zipFile = new ZipFile(sourceJar)) {
Enumeration<? extends ZipEntry> zipEntries = zipFile.entries();
while (zipEntries.hasMoreElements()) {
@@ -223,7 +219,7 @@ public abstract class AbstractLibraryBuilder extends CommonJavaLibraryProcessor
} else {
// Copy the data from the zip file to the output file.
try (InputStream in = zipFile.getInputStream(currentEntry);
- OutputStream out = new FileOutputStream(outputFile)) {
+ OutputStream out = new FileOutputStream(outputFile)) {
ByteStreams.copy(in, out);
}
@@ -236,10 +232,10 @@ public abstract class AbstractLibraryBuilder extends CommonJavaLibraryProcessor
}
/**
- * Recursively cleans up the files beneath the specified output directory.
- * Does not follow symbolic links. Throws IOException if any deletion fails.
+ * Recursively cleans up the files beneath the specified output directory. Does not follow
+ * symbolic links. Throws IOException if any deletion fails.
*
- * Will delete all empty directories.
+ * <p>Will delete all empty directories.
*
* @param dir the directory to clean up.
* @return true if the directory itself was removed as well.
@@ -249,11 +245,10 @@ public abstract class AbstractLibraryBuilder extends CommonJavaLibraryProcessor
}
/**
- * Recursively cleans up the files beneath the specified output directory.
- * Does not follow symbolic links. Throws IOException if any deletion fails.
- * If removeEverything is false, keeps .class files if keepClassFilesDuringCleanup()
- * returns true. If removeEverything is true, removes everything. Will delete all
- * empty directories.
+ * Recursively cleans up the files beneath the specified output directory. Does not follow
+ * symbolic links. Throws IOException if any deletion fails. If removeEverything is false, keeps
+ * .class files if keepClassFilesDuringCleanup() returns true. If removeEverything is true,
+ * removes everything. Will delete all empty directories.
*
* @param dir the directory to clean up.
* @param removeEverything whether to remove all files, or keep flags.xml/.class files.
@@ -262,12 +257,15 @@ public abstract class AbstractLibraryBuilder extends CommonJavaLibraryProcessor
private boolean cleanupDirectory(File dir, boolean removeEverything) throws IOException {
boolean isEmpty = true;
File[] files = dir.listFiles();
- if (files == null) { return false; } // avoid race condition
+ if (files == null) {
+ return false;
+ } // avoid race condition
for (File file : files) {
if (file.isDirectory()) {
isEmpty &= cleanupDirectory(file, removeEverything);
- } else if (!removeEverything && keepClassFilesDuringCleanup() &&
- file.getName().endsWith(".class")) {
+ } else if (!removeEverything
+ && keepClassFilesDuringCleanup()
+ && file.getName().endsWith(".class")) {
isEmpty = false;
} else {
file.delete();
@@ -280,11 +278,10 @@ public abstract class AbstractLibraryBuilder extends CommonJavaLibraryProcessor
}
/**
- * Returns true if cleaning the output directory should remove all
- * .class files in the output directory.
+ * Returns true if cleaning the output directory should remove all .class files in the output
+ * directory.
*/
protected boolean keepClassFilesDuringCleanup() {
return false;
}
-
}
diff --git a/src/java_tools/buildjar/java/com/google/devtools/build/buildjar/AbstractPostProcessor.java b/src/java_tools/buildjar/java/com/google/devtools/build/buildjar/AbstractPostProcessor.java
index 2e2ba471f4..0c7bccf157 100644
--- a/src/java_tools/buildjar/java/com/google/devtools/build/buildjar/AbstractPostProcessor.java
+++ b/src/java_tools/buildjar/java/com/google/devtools/build/buildjar/AbstractPostProcessor.java
@@ -15,7 +15,6 @@
package com.google.devtools.build.buildjar;
import com.google.common.base.Preconditions;
-
import java.io.File;
import java.io.IOException;
import java.util.HashMap;
@@ -46,9 +45,8 @@ public abstract class AbstractPostProcessor {
* Sets the command line arguments for this processor.
*
* @param arguments the list of arguments
- *
* @throws InvalidCommandLineException when the list of arguments for this processors is
- * incorrect.
+ * incorrect.
*/
public abstract void setCommandLineArguments(List<String> arguments)
throws InvalidCommandLineException;
@@ -74,19 +72,17 @@ public abstract class AbstractPostProcessor {
return build.getClassDir();
}
- /**
- * Main interface method of the post processor.
- */
+ /** Main interface method of the post processor. */
public abstract void processRequest() throws IOException;
/**
* Create an {@link AbstractPostProcessor} using reflection.
*
* @param processorName the name of the processor to instantiate. It should exist in the list of
- * post processors added with the {@link #addPostProcessor(String, AbstractPostProcessor)}
- * method.
+ * post processors added with the {@link #addPostProcessor(String, AbstractPostProcessor)}
+ * method.
* @param arguments the list of arguments that should be passed to the processor during
- * instantiation.
+ * instantiation.
* @throws InvalidCommandLineException on error creating the processor
*/
static AbstractPostProcessor create(String processorName, List<String> arguments)
diff --git a/src/java_tools/buildjar/java/com/google/devtools/build/buildjar/BazelJavaBuilder.java b/src/java_tools/buildjar/java/com/google/devtools/build/buildjar/BazelJavaBuilder.java
index 83163030c6..f376592823 100644
--- a/src/java_tools/buildjar/java/com/google/devtools/build/buildjar/BazelJavaBuilder.java
+++ b/src/java_tools/buildjar/java/com/google/devtools/build/buildjar/BazelJavaBuilder.java
@@ -33,16 +33,12 @@ import java.util.Arrays;
import java.util.List;
import java.util.ListIterator;
-/**
- * The JavaBuilder main called by bazel.
- */
+/** The JavaBuilder main called by bazel. */
public abstract class BazelJavaBuilder {
private static final String CMDNAME = "BazelJavaBuilder";
- /**
- * The main method of the BazelJavaBuilder.
- */
+ /** The main method of the BazelJavaBuilder. */
public static void main(String[] args) {
AbstractPostProcessor.addPostProcessor("jacoco", new JacocoInstrumentationProcessor());
if (args.length == 1 && args[0].equals("--persistent_worker")) {
@@ -88,9 +84,10 @@ public abstract class BazelJavaBuilder {
public static int processRequest(List<String> args, PrintWriter err) {
try {
JavaLibraryBuildRequest build = parse(args);
- AbstractJavaBuilder builder = build.getDependencyModule().reduceClasspath()
- ? new ReducedClasspathJavaLibraryBuilder()
- : new SimpleJavaLibraryBuilder();
+ AbstractJavaBuilder builder =
+ build.getDependencyModule().reduceClasspath()
+ ? new ReducedClasspathJavaLibraryBuilder()
+ : new SimpleJavaLibraryBuilder();
return builder.run(build, err).exitCode;
} catch (InvalidCommandLineException e) {
System.err.println(CMDNAME + " threw exception: " + e.getMessage());
@@ -124,16 +121,16 @@ public abstract class BazelJavaBuilder {
}
/**
- * Parses the list of arguments into a {@link JavaLibraryBuildRequest}. The returned
- * {@link JavaLibraryBuildRequest} object can be then used to configure the compilation itself.
+ * Parses the list of arguments into a {@link JavaLibraryBuildRequest}. The returned {@link
+ * JavaLibraryBuildRequest} object can be then used to configure the compilation itself.
*
* @throws IOException if the argument list contains a file (with the @ prefix) and reading that
- * file failed
+ * file failed
* @throws InvalidCommandLineException on any command line error
*/
@VisibleForTesting
- public static JavaLibraryBuildRequest parse(List<String> args) throws IOException,
- InvalidCommandLineException {
+ public static JavaLibraryBuildRequest parse(List<String> args)
+ throws IOException, InvalidCommandLineException {
OptionsParser optionsParser = new OptionsParser(args);
ImmutableList.Builder<BlazeJavaCompilerPlugin> plugins = ImmutableList.builder();
plugins.add(new ClassLoaderMaskingPlugin());
diff --git a/src/java_tools/buildjar/java/com/google/devtools/build/buildjar/CommonJavaLibraryProcessor.java b/src/java_tools/buildjar/java/com/google/devtools/build/buildjar/CommonJavaLibraryProcessor.java
index ee5c727401..5d4dba6246 100644
--- a/src/java_tools/buildjar/java/com/google/devtools/build/buildjar/CommonJavaLibraryProcessor.java
+++ b/src/java_tools/buildjar/java/com/google/devtools/build/buildjar/CommonJavaLibraryProcessor.java
@@ -19,21 +19,18 @@ import java.util.ArrayList;
import java.util.List;
/**
- * Superclass for all JavaBuilder processor classes
- * involved in compiling and processing java code.
+ * Superclass for all JavaBuilder processor classes involved in compiling and processing java code.
*/
public abstract class CommonJavaLibraryProcessor {
/**
- * Creates the initial set of arguments to javac from the Build
- * configuration supplied. This set of arguments should be extended
- * by the code invoking it.
+ * Creates the initial set of arguments to javac from the Build configuration supplied. This set
+ * of arguments should be extended by the code invoking it.
*
* @param build The build request for the initial set of arguments is needed
* @return The list of initial arguments
*/
- protected List<String> createInitialJavacArgs(JavaLibraryBuildRequest build,
- String classPath) {
+ protected List<String> createInitialJavacArgs(JavaLibraryBuildRequest build, String classPath) {
List<String> args = new ArrayList<>();
if (!classPath.isEmpty()) {
args.add("-cp");
diff --git a/src/java_tools/buildjar/java/com/google/devtools/build/buildjar/InvalidCommandLineException.java b/src/java_tools/buildjar/java/com/google/devtools/build/buildjar/InvalidCommandLineException.java
index fac1ed6860..2ecffcf541 100644
--- a/src/java_tools/buildjar/java/com/google/devtools/build/buildjar/InvalidCommandLineException.java
+++ b/src/java_tools/buildjar/java/com/google/devtools/build/buildjar/InvalidCommandLineException.java
@@ -14,9 +14,7 @@
package com.google.devtools.build.buildjar;
-/**
- * Exception to be thrown on command line parsing errors
- */
+/** Exception to be thrown on command line parsing errors */
public class InvalidCommandLineException extends Exception {
public InvalidCommandLineException(String message) {
@@ -26,4 +24,4 @@ public class InvalidCommandLineException extends Exception {
public InvalidCommandLineException(String message, Throwable cause) {
super(message, cause);
}
-} \ No newline at end of file
+}
diff --git a/src/java_tools/buildjar/java/com/google/devtools/build/buildjar/JavaLibraryBuildRequest.java b/src/java_tools/buildjar/java/com/google/devtools/build/buildjar/JavaLibraryBuildRequest.java
index 052b23fbe2..e77617bdd4 100644
--- a/src/java_tools/buildjar/java/com/google/devtools/build/buildjar/JavaLibraryBuildRequest.java
+++ b/src/java_tools/buildjar/java/com/google/devtools/build/buildjar/JavaLibraryBuildRequest.java
@@ -23,25 +23,17 @@ import java.nio.file.Paths;
import java.util.List;
import java.util.Map.Entry;
-/**
- * All the information needed to perform a single Java library build operation.
- */
+/** All the information needed to perform a single Java library build operation. */
public final class JavaLibraryBuildRequest {
private ImmutableList<String> javacOpts;
- /**
- * Where to store source files generated by annotation processors.
- */
+ /** Where to store source files generated by annotation processors. */
private final String sourceGenDir;
- /**
- * The path to an output jar for source files generated by annotation processors.
- */
+ /** The path to an output jar for source files generated by annotation processors. */
private final String generatedSourcesOutputJar;
- /**
- * The path to an output jar for classfiles generated by annotation processors.
- */
+ /** The path to an output jar for classfiles generated by annotation processors. */
private final String generatedClassOutputJar;
private final List<String> sourceFiles;
@@ -69,19 +61,13 @@ public final class JavaLibraryBuildRequest {
private final boolean compressJar;
- /**
- * Repository for all dependency-related information.
- */
+ /** Repository for all dependency-related information. */
private final DependencyModule dependencyModule;
- /**
- * Repository for information about annotation processor-generated symbols.
- */
+ /** Repository for information about annotation processor-generated symbols. */
private final AnnotationProcessingModule processingModule;
- /**
- * List of plugins that are given to javac.
- */
+ /** List of plugins that are given to javac. */
private final ImmutableList<BlazeJavaCompilerPlugin> plugins;
/**
diff --git a/src/java_tools/buildjar/java/com/google/devtools/build/buildjar/OptionsParser.java b/src/java_tools/buildjar/java/com/google/devtools/build/buildjar/OptionsParser.java
index 5b0a10d1c1..fecbf3c6b0 100644
--- a/src/java_tools/buildjar/java/com/google/devtools/build/buildjar/OptionsParser.java
+++ b/src/java_tools/buildjar/java/com/google/devtools/build/buildjar/OptionsParser.java
@@ -83,8 +83,8 @@ public final class OptionsParser {
private String targetLabel;
/**
- * Constructs an {@code OptionsParser} from a list of command args. Sets the same
- * JavacRunner for both compilation and annotation processing.
+ * Constructs an {@code OptionsParser} from a list of command args. Sets the same JavacRunner for
+ * both compilation and annotation processing.
*
* @param args the list of command line args.
* @throws InvalidCommandLineException on any command line error.
@@ -220,8 +220,8 @@ public final class OptionsParser {
}
/**
- * Pre-processes an argument list, expanding options @filename to read in
- * the content of the file and add it to the list of arguments.
+ * Pre-processes an argument list, expanding options @filename to read in the content of the file
+ * and add it to the list of arguments.
*
* @param args the List of arguments to pre-process.
* @return the List of pre-processed arguments.
@@ -236,8 +236,8 @@ public final class OptionsParser {
}
/**
- * Expands a single argument, expanding options @filename to read in the content of the file
- * and add it to the list of processed arguments. The @ itself can be escaped with @@.
+ * Expands a single argument, expanding options @filename to read in the content of the file and
+ * add it to the list of processed arguments. The @ itself can be escaped with @@.
*
* @param expanded the list of processed arguments.
* @param arg the argument to pre-process.
@@ -275,15 +275,16 @@ public final class OptionsParser {
}
/**
- * Collects the arguments for the --processors command line flag until it finds a flag that
- * starts with the terminatorPrefix.
+ * Collects the arguments for the --processors command line flag until it finds a flag that starts
+ * with the terminatorPrefix.
*
* @param output where to put the collected flag arguments.
* @param args
* @param terminatorPrefix the terminator prefix to stop collecting of argument flags.
*/
- private static void collectProcessorArguments(List<String> output, Deque<String> args,
- String terminatorPrefix) throws InvalidCommandLineException {
+ private static void collectProcessorArguments(
+ List<String> output, Deque<String> args, String terminatorPrefix)
+ throws InvalidCommandLineException {
for (String arg = args.pollFirst(); arg != null; arg = args.pollFirst()) {
if (arg.startsWith(terminatorPrefix)) {
args.addFirst(arg);
diff --git a/src/java_tools/buildjar/java/com/google/devtools/build/buildjar/SimpleJavaLibraryBuilder.java b/src/java_tools/buildjar/java/com/google/devtools/build/buildjar/SimpleJavaLibraryBuilder.java
index e5b135365e..13939ad187 100644
--- a/src/java_tools/buildjar/java/com/google/devtools/build/buildjar/SimpleJavaLibraryBuilder.java
+++ b/src/java_tools/buildjar/java/com/google/devtools/build/buildjar/SimpleJavaLibraryBuilder.java
@@ -18,18 +18,14 @@ import com.google.common.base.Joiner;
import com.google.common.collect.ImmutableSet;
import com.google.devtools.build.buildjar.jarhelper.JarCreator;
import com.google.devtools.build.buildjar.javac.JavacRunner;
-
import com.sun.tools.javac.main.Main.Result;
-
import java.io.File;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.List;
-/**
- * An implementation of the JavaBuilder that uses in-process javac to compile java files.
- */
+/** An implementation of the JavaBuilder that uses in-process javac to compile java files. */
public class SimpleJavaLibraryBuilder extends AbstractJavaBuilder {
@Override
@@ -58,16 +54,16 @@ public class SimpleJavaLibraryBuilder extends AbstractJavaBuilder {
}
/**
- * For the build configuration 'build', construct a command line that
- * can be used for a javac invocation.
+ * For the build configuration 'build', construct a command line that can be used for a javac
+ * invocation.
*/
protected String[] makeJavacArguments(JavaLibraryBuildRequest build) {
return makeJavacArguments(build, build.getClassPath());
}
/**
- * For the build configuration 'build', construct a command line that
- * can be used for a javac invocation.
+ * For the build configuration 'build', construct a command line that can be used for a javac
+ * invocation.
*/
protected String[] makeJavacArguments(JavaLibraryBuildRequest build, String classPath) {
List<String> javacArguments = createInitialJavacArgs(build, classPath);
@@ -80,8 +76,10 @@ public class SimpleJavaLibraryBuilder extends AbstractJavaBuilder {
}
if (option.equals("-processor") || option.equals("-processorpath")) {
throw new IllegalStateException(
- "Using " + option + " in javacopts is no longer supported."
- + " Use a java_plugin() rule instead.");
+ "Using "
+ + option
+ + " in javacopts is no longer supported."
+ + " Use a java_plugin() rule instead.");
}
javacArguments.add(option);
}
@@ -101,8 +99,7 @@ public class SimpleJavaLibraryBuilder extends AbstractJavaBuilder {
// whereas omitting the option is treated as not having a processor path (which causes
// processor path searches to fallback to the class path).
args.add("-processorpath");
- args.add(
- build.getProcessorPath().isEmpty() ? "" : build.getProcessorPath());
+ args.add(build.getProcessorPath().isEmpty() ? "" : build.getProcessorPath());
if (!build.getProcessors().isEmpty() && !build.getSourceFiles().isEmpty()) {
// ImmutableSet.copyOf maintains order
diff --git a/src/java_tools/buildjar/java/com/google/devtools/build/buildjar/genclass/GenClass.java b/src/java_tools/buildjar/java/com/google/devtools/build/buildjar/genclass/GenClass.java
index 3a1c941b74..1aed0f9779 100644
--- a/src/java_tools/buildjar/java/com/google/devtools/build/buildjar/genclass/GenClass.java
+++ b/src/java_tools/buildjar/java/com/google/devtools/build/buildjar/genclass/GenClass.java
@@ -19,7 +19,6 @@ import com.google.common.collect.ImmutableSet;
import com.google.devtools.build.buildjar.jarhelper.JarCreator;
import com.google.devtools.build.buildjar.proto.JavaCompilation.CompilationUnit;
import com.google.devtools.build.buildjar.proto.JavaCompilation.Manifest;
-
import java.io.IOException;
import java.io.InputStream;
import java.nio.file.FileVisitResult;
@@ -33,15 +32,12 @@ import java.util.jar.JarEntry;
import java.util.jar.JarFile;
/**
- * GenClass post-processes the output of a Java compilation, and produces
- * a jar containing only the class files for sources that were generated
- * by annotation processors.
+ * GenClass post-processes the output of a Java compilation, and produces a jar containing only the
+ * class files for sources that were generated by annotation processors.
*/
public class GenClass {
- /**
- * Recursively delete a directory.
- */
+ /** Recursively delete a directory. */
private static void deleteTree(Path directory) throws IOException {
if (directory.toFile().exists()) {
Files.walkFileTree(
@@ -72,9 +68,7 @@ public class GenClass {
writeOutputJar(options);
}
- /**
- * Reads the compilation manifest.
- */
+ /** Reads the compilation manifest. */
private static Manifest readManifest(Path path) throws IOException {
Manifest manifest;
try (InputStream inputStream = Files.newInputStream(path)) {
@@ -84,12 +78,11 @@ public class GenClass {
}
/**
- * For each top-level class in the compilation, determine the path prefix
- * of classes corresponding to that compilation unit.
+ * For each top-level class in the compilation, determine the path prefix of classes corresponding
+ * to that compilation unit.
*
- * <p>Prefixes are used to correctly handle inner classes, e.g. the top-level
- * class "c.g.Foo" may correspond to "c/g/Foo.class" and also
- * "c/g/Foo$Inner.class" or "c/g/Foo$0.class".
+ * <p>Prefixes are used to correctly handle inner classes, e.g. the top-level class "c.g.Foo" may
+ * correspond to "c/g/Foo.class" and also "c/g/Foo$Inner.class" or "c/g/Foo$0.class".
*/
@VisibleForTesting
static ImmutableSet<String> getGeneratedPrefixes(Manifest manifest) {
@@ -112,8 +105,8 @@ public class GenClass {
}
/**
- * Unzip all the class files that correspond to annotation processor-
- * generated sources into the temporary directory.
+ * Unzip all the class files that correspond to annotation processor- generated sources into the
+ * temporary directory.
*/
private static void extractGeneratedClasses(Path classJar, Manifest manifest, Path tempDir)
throws IOException {
diff --git a/src/java_tools/buildjar/java/com/google/devtools/build/buildjar/jarhelper/JarCreator.java b/src/java_tools/buildjar/java/com/google/devtools/build/buildjar/jarhelper/JarCreator.java
index dbebaeb6e7..5f081f7dff 100644
--- a/src/java_tools/buildjar/java/com/google/devtools/build/buildjar/jarhelper/JarCreator.java
+++ b/src/java_tools/buildjar/java/com/google/devtools/build/buildjar/jarhelper/JarCreator.java
@@ -60,9 +60,8 @@ public class JarCreator extends JarHelper {
}
/**
- * Adds the contents of a directory to the Jar file. All files below this
- * directory will be added to the Jar file using the name relative to the
- * directory as the name for the Jar entry.
+ * Adds the contents of a directory to the Jar file. All files below this directory will be added
+ * to the Jar file using the name relative to the directory as the name for the Jar entry.
*
* @param directory the directory to add to the jar
*/
@@ -71,13 +70,11 @@ public class JarCreator extends JarHelper {
}
/**
- * Adds the contents of a directory to the Jar file. All files below this
- * directory will be added to the Jar file using the prefix and the name
- * relative to the directory as the name for the Jar entry. Always uses '/' as
- * the separator char for the Jar entries.
+ * Adds the contents of a directory to the Jar file. All files below this directory will be added
+ * to the Jar file using the prefix and the name relative to the directory as the name for the Jar
+ * entry. Always uses '/' as the separator char for the Jar entries.
*
- * @param prefix the prefix to prepend to every Jar entry name found below the
- * directory
+ * @param prefix the prefix to prepend to every Jar entry name found below the directory
* @param directory the directory to add to the Jar
*/
private void addDirectory(String prefix, File directory) {
@@ -94,8 +91,9 @@ public class JarCreator extends JarHelper {
}
/**
- * Adds a collection of entries to the jar, each with a given source path, and with
- * the resulting file in the root of the jar.
+ * Adds a collection of entries to the jar, each with a given source path, and with the resulting
+ * file in the root of the jar.
+ *
* <pre>
* some/long/path.foo => (path.foo, some/long/path.foo)
* </pre>
@@ -107,8 +105,8 @@ public class JarCreator extends JarHelper {
}
/**
- * Sets the main.class entry for the manifest. A value of <code>null</code>
- * (the default) will omit the entry.
+ * Sets the main.class entry for the manifest. A value of <code>null</code> (the default) will
+ * omit the entry.
*
* @param mainClass the fully qualified name of the main class
*/
@@ -117,9 +115,8 @@ public class JarCreator extends JarHelper {
}
/**
- * Sets filename for the manifest content. If this is set the manifest will be
- * read from this file otherwise the manifest content will get generated on
- * the fly.
+ * Sets filename for the manifest content. If this is set the manifest will be read from this file
+ * otherwise the manifest content will get generated on the fly.
*
* @param manifestFile the filename of the manifest file.
*/
@@ -152,8 +149,7 @@ public class JarCreator extends JarHelper {
/**
* Executes the creation of the Jar file.
*
- * @throws IOException if the Jar cannot be written or any of the entries
- * cannot be read.
+ * @throws IOException if the Jar cannot be written or any of the entries cannot be read.
*/
public void execute() throws IOException {
out = new JarOutputStream(new BufferedOutputStream(new FileOutputStream(jarFile)));
@@ -170,9 +166,7 @@ public class JarCreator extends JarHelper {
}
}
- /**
- * A simple way to create Jar file using the JarCreator class.
- */
+ /** A simple way to create Jar file using the JarCreator class. */
public static void main(String[] args) {
if (args.length < 1) {
System.err.println("usage: CreateJar output [root directories]");
diff --git a/src/java_tools/buildjar/java/com/google/devtools/build/buildjar/jarhelper/JarHelper.java b/src/java_tools/buildjar/java/com/google/devtools/build/buildjar/jarhelper/JarHelper.java
index 8c8d48d94d..48525fc738 100644
--- a/src/java_tools/buildjar/java/com/google/devtools/build/buildjar/jarhelper/JarHelper.java
+++ b/src/java_tools/buildjar/java/com/google/devtools/build/buildjar/jarhelper/JarHelper.java
@@ -63,8 +63,7 @@ public class JarHelper {
/**
* Enables or disables the Jar entry normalization.
*
- * @param normalize If true the timestamps of Jar entries will be set to the
- * DOS epoch.
+ * @param normalize If true the timestamps of Jar entries will be set to the DOS epoch.
*/
public void setNormalize(boolean normalize) {
this.normalize = normalize;
@@ -89,13 +88,12 @@ public class JarHelper {
}
/**
- * Returns the normalized timestamp for a jar entry based on its name.
- * This is necessary since javac will, when loading a class X, prefer a
- * source file to a class file, if both files have the same timestamp.
- * Therefore, we need to adjust the timestamp for class files to slightly
+ * Returns the normalized timestamp for a jar entry based on its name. This is necessary since
+ * javac will, when loading a class X, prefer a source file to a class file, if both files have
+ * the same timestamp. Therefore, we need to adjust the timestamp for class files to slightly
* after the normalized time.
- * @param name The name of the file for which we should return the
- * normalized timestamp.
+ *
+ * @param name The name of the file for which we should return the normalized timestamp.
* @return the time for a new Jar file entry in milliseconds since the epoch.
*/
private long normalizedTimestamp(String name) {
@@ -107,9 +105,9 @@ public class JarHelper {
}
/**
- * Returns the time for a new Jar file entry in milliseconds since the epoch.
- * Uses {@link JarCreator#DOS_EPOCH_IN_JAVA_TIME} for normalized entries,
- * {@link System#currentTimeMillis()} otherwise.
+ * Returns the time for a new Jar file entry in milliseconds since the epoch. Uses {@link
+ * JarCreator#DOS_EPOCH_IN_JAVA_TIME} for normalized entries, {@link System#currentTimeMillis()}
+ * otherwise.
*
* @param filename The name of the file for which we are entering the time
* @return the time for a new Jar file entry in milliseconds since the epoch.
@@ -119,8 +117,8 @@ public class JarHelper {
}
/**
- * Writes an entry with specific contents to the jar. Directory entries must
- * include the trailing '/'.
+ * Writes an entry with specific contents to the jar. Directory entries must include the trailing
+ * '/'.
*/
protected void writeEntry(JarOutputStream out, String name, byte[] content) throws IOException {
if (names.add(name)) {
@@ -148,8 +146,8 @@ public class JarHelper {
}
/**
- * Writes a standard Java manifest entry into the JarOutputStream. This
- * includes the directory entry for the "META-INF" directory
+ * Writes a standard Java manifest entry into the JarOutputStream. This includes the directory
+ * entry for the "META-INF" directory
*
* @param content the Manifest content to write to the manifest entry.
* @throws IOException
@@ -162,7 +160,7 @@ public class JarHelper {
storageMethod = JarEntry.STORED;
}
try {
- writeEntry(out, MANIFEST_DIR, new byte[]{});
+ writeEntry(out, MANIFEST_DIR, new byte[] {});
writeEntry(out, MANIFEST_NAME, content);
} finally {
storageMethod = oldStorageMethod;
@@ -170,9 +168,8 @@ public class JarHelper {
}
/**
- * Copies file or directory entries from the file system into the jar.
- * Directory entries will be detected and their names automatically '/'
- * suffixed.
+ * Copies file or directory entries from the file system into the jar. Directory entries will be
+ * detected and their names automatically '/' suffixed.
*/
protected void copyEntry(String name, File file) throws IOException {
if (!names.contains(name)) {
@@ -181,7 +178,7 @@ public class JarHelper {
}
boolean isDirectory = file.isDirectory();
if (isDirectory && !name.endsWith("/")) {
- name = name + '/'; // always normalize directory names before checking set
+ name = name + '/'; // always normalize directory names before checking set
}
if (names.add(name)) {
if (verbose) {
diff --git a/src/java_tools/buildjar/java/com/google/devtools/build/buildjar/javac/BlazeJavaCompiler.java b/src/java_tools/buildjar/java/com/google/devtools/build/buildjar/javac/BlazeJavaCompiler.java
index 665a8fcaf6..7cee54b0f8 100644
--- a/src/java_tools/buildjar/java/com/google/devtools/build/buildjar/javac/BlazeJavaCompiler.java
+++ b/src/java_tools/buildjar/java/com/google/devtools/build/buildjar/javac/BlazeJavaCompiler.java
@@ -16,34 +16,27 @@ package com.google.devtools.build.buildjar.javac;
import com.google.common.base.Function;
import com.google.devtools.build.buildjar.javac.plugins.BlazeJavaCompilerPlugin;
-
import com.sun.tools.javac.comp.AttrContext;
import com.sun.tools.javac.comp.CompileStates.CompileState;
import com.sun.tools.javac.comp.Env;
import com.sun.tools.javac.main.JavaCompiler;
import com.sun.tools.javac.util.Context;
-
import java.util.ArrayList;
import java.util.List;
import java.util.Queue;
-
import javax.annotation.Nullable;
/**
- * An extended version of the javac compiler, providing support for
- * composable static analyses via a plugin mechanism. BlazeJavaCompiler
- * keeps a list of plugins and calls callback methods in those plugins
- * after certain compiler phases. The plugins perform the actual static
- * analyses.
+ * An extended version of the javac compiler, providing support for composable static analyses via a
+ * plugin mechanism. BlazeJavaCompiler keeps a list of plugins and calls callback methods in those
+ * plugins after certain compiler phases. The plugins perform the actual static analyses.
*/
public class BlazeJavaCompiler extends JavaCompiler {
private int skippedFlowEvents = 0;
private int flowEvents = 0;
- /**
- * A list of plugins to run at particular points in the compile
- */
+ /** A list of plugins to run at particular points in the compile */
private final List<BlazeJavaCompilerPlugin> plugins = new ArrayList<>();
private BlazeJavaCompiler(Context context, Iterable<BlazeJavaCompilerPlugin> plugins) {
@@ -57,19 +50,17 @@ public class BlazeJavaCompiler extends JavaCompiler {
}
/**
- * Adds an initialization hook to the Context, such that requests for a
- * JavaCompiler (i.e., a lookup for 'compilerKey' of our superclass,
- * JavaCompiler) will actually construct and return BlazeJavaCompiler.
+ * Adds an initialization hook to the Context, such that requests for a JavaCompiler (i.e., a
+ * lookup for 'compilerKey' of our superclass, JavaCompiler) will actually construct and return
+ * BlazeJavaCompiler.
*
- * This is the preferred way for extending behavior within javac,
- * per the documentation in {@link Context}.
+ * <p>This is the preferred way for extending behavior within javac, per the documentation in
+ * {@link Context}.
*
- * Prior to JDK-8038455 additional JavaCompilers were created for
- * annotation processing rounds, but we now expect a single
- * compiler instance per compilation. The factory is still seems
- * to be necessary to avoid context-ordering issues, but we
- * assert that the factory is only called once, and save the
- * output after its call for introspection.
+ * <p>Prior to JDK-8038455 additional JavaCompilers were created for annotation processing rounds,
+ * but we now expect a single compiler instance per compilation. The factory is still seems to be
+ * necessary to avoid context-ordering issues, but we assert that the factory is only called once,
+ * and save the output after its call for introspection.
*/
public static void preRegister(
final Context context,
@@ -155,8 +146,8 @@ public class BlazeJavaCompiler extends JavaCompiler {
}
/**
- * Testing purposes only. Returns true if the collection of plugins in
- * this instance contains one of the provided type.
+ * Testing purposes only. Returns true if the collection of plugins in this instance contains one
+ * of the provided type.
*/
boolean pluginsContain(Class<? extends BlazeJavaCompilerPlugin> klass) {
for (BlazeJavaCompilerPlugin plugin : plugins) {
diff --git a/src/java_tools/buildjar/java/com/google/devtools/build/buildjar/javac/BlazeJavacMain.java b/src/java_tools/buildjar/java/com/google/devtools/build/buildjar/javac/BlazeJavacMain.java
index 173a1e81b3..de6f0816cb 100644
--- a/src/java_tools/buildjar/java/com/google/devtools/build/buildjar/javac/BlazeJavacMain.java
+++ b/src/java_tools/buildjar/java/com/google/devtools/build/buildjar/javac/BlazeJavacMain.java
@@ -23,7 +23,6 @@ import com.google.common.base.Verify;
import com.google.devtools.build.buildjar.InvalidCommandLineException;
import com.google.devtools.build.buildjar.javac.plugins.BlazeJavaCompilerPlugin;
import com.google.devtools.build.buildjar.javac.plugins.BlazeJavaCompilerPlugin.PluginException;
-
import com.sun.source.util.TaskEvent;
import com.sun.source.util.TaskListener;
import com.sun.tools.javac.api.JavacTaskImpl;
@@ -34,11 +33,9 @@ import com.sun.tools.javac.main.Main.Result;
import com.sun.tools.javac.util.Context;
import com.sun.tools.javac.util.Options;
import com.sun.tools.javac.util.PropagatedException;
-
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.List;
-
import javax.annotation.processing.Processor;
import javax.tools.DiagnosticListener;
import javax.tools.JavaFileManager;
@@ -47,21 +44,22 @@ import javax.tools.JavaFileObject;
/**
* Main class for our custom patched javac.
*
- * <p> This main class tweaks the standard javac log class by changing the
- * compiler's context to use our custom log class. This custom log class
- * modifies javac's output to list all errors after all warnings.
+ * <p>This main class tweaks the standard javac log class by changing the compiler's context to use
+ * our custom log class. This custom log class modifies javac's output to list all errors after all
+ * warnings.
*/
public class BlazeJavacMain {
/**
- * Compose {@link com.sun.tools.javac.main.Main} and perform custom setup before deferring to
- * its compile() method.
+ * Compose {@link com.sun.tools.javac.main.Main} and perform custom setup before deferring to its
+ * compile() method.
*
* <p>Historically BlazeJavacMain extended javac's Main and overrode methods to get the desired
* custom behaviour. That approach created incompatibilities when upgrading to newer versions of
* javac, so composition is preferred.
*/
private List<BlazeJavaCompilerPlugin> plugins;
+
private final PrintWriter errOutput;
private final String compilerName;
private BlazeJavaCompiler compiler = null;
@@ -73,8 +71,8 @@ public class BlazeJavacMain {
}
/**
- * Installs the BlazeJavaCompiler within the provided context. Enables
- * plugins based on field values.
+ * Installs the BlazeJavaCompiler within the provided context. Enables plugins based on field
+ * values.
*
* @param context JavaCompiler's associated Context
*/
@@ -182,14 +180,16 @@ public class BlazeJavacMain {
Iterable<? extends Processor> processors) {
JavacTool tool = JavacTool.create();
- JavacTaskImpl task = (JavacTaskImpl) tool.getTask(
- errOutput,
- fileManager,
- diagnosticListener,
- Arrays.asList(argv),
- null,
- javaFileObjects,
- context);
+ JavacTaskImpl task =
+ (JavacTaskImpl)
+ tool.getTask(
+ errOutput,
+ fileManager,
+ diagnosticListener,
+ Arrays.asList(argv),
+ null,
+ javaFileObjects,
+ context);
if (processors != null) {
task.setProcessors(processors);
}
@@ -202,10 +202,14 @@ public class BlazeJavacMain {
}
}
- private static final TaskListener EMPTY_LISTENER = new TaskListener() {
- @Override public void started(TaskEvent e) {}
- @Override public void finished(TaskEvent e) {}
- };
+ private static final TaskListener EMPTY_LISTENER =
+ new TaskListener() {
+ @Override
+ public void started(TaskEvent e) {}
+
+ @Override
+ public void finished(TaskEvent e) {}
+ };
/**
* Convinces javac to run in 'API mode', and collect end position information needed by
@@ -215,9 +219,7 @@ public class BlazeJavacMain {
MultiTaskListener.instance(context).add(EMPTY_LISTENER);
}
- /**
- * Processes Plugin-specific arguments and removes them from the args array.
- */
+ /** Processes Plugin-specific arguments and removes them from the args array. */
@VisibleForTesting
String[] processPluginArgs(String[] args) throws InvalidCommandLineException {
List<String> processedArgs = Arrays.asList(args);
diff --git a/src/java_tools/buildjar/java/com/google/devtools/build/buildjar/javac/JavacOptions.java b/src/java_tools/buildjar/java/com/google/devtools/build/buildjar/javac/JavacOptions.java
index 4f7e749c7e..2363162b4c 100644
--- a/src/java_tools/buildjar/java/com/google/devtools/build/buildjar/javac/JavacOptions.java
+++ b/src/java_tools/buildjar/java/com/google/devtools/build/buildjar/javac/JavacOptions.java
@@ -104,7 +104,7 @@ public final class JavacOptions {
/**
* Add the normalized versions of the options handled by {@link #processOption(String)} to the
* {@code normalized} list
- **/
+ */
void normalize(List<String> normalized);
}
@@ -120,8 +120,8 @@ public final class JavacOptions {
/**
* This type models a starting selection from which lint options can be added or removed. E.g.,
- * {@code -Xlint} indicates we start with the set of recommended checks enabled, and
- * {@code -Xlint:none} means we start without any checks enabled.
+ * {@code -Xlint} indicates we start with the set of recommended checks enabled, and {@code
+ * -Xlint:none} means we start without any checks enabled.
*/
private static enum BasisXlintSelection {
/** {@code -Xlint:none} */
@@ -234,8 +234,8 @@ public final class JavacOptions {
* @param normalizers the list of normalizers to apply
* @return a new cleaned up javac option list
*/
- public static List<String> normalizeOptionsWithNormalizers(List<String> javacopts,
- JavacOptionNormalizer... normalizers) {
+ public static List<String> normalizeOptionsWithNormalizers(
+ List<String> javacopts, JavacOptionNormalizer... normalizers) {
List<String> normalized = new ArrayList<>();
for (JavacOptionNormalizer normalizer : normalizers) {
diff --git a/src/java_tools/buildjar/java/com/google/devtools/build/buildjar/javac/JavacRunner.java b/src/java_tools/buildjar/java/com/google/devtools/build/buildjar/javac/JavacRunner.java
index 799ff9fd3a..992ddf689d 100644
--- a/src/java_tools/buildjar/java/com/google/devtools/build/buildjar/javac/JavacRunner.java
+++ b/src/java_tools/buildjar/java/com/google/devtools/build/buildjar/javac/JavacRunner.java
@@ -16,14 +16,12 @@ package com.google.devtools.build.buildjar.javac;
import com.google.common.collect.ImmutableList;
import com.google.devtools.build.buildjar.javac.plugins.BlazeJavaCompilerPlugin;
-
import com.sun.tools.javac.main.Main.Result;
-
import java.io.PrintWriter;
/**
- * The JavacRunner is a type that can be used to invoke
- * javac and provides a convenient hook for modifications.
+ * The JavacRunner is a type that can be used to invoke javac and provides a convenient hook for
+ * modifications.
*/
public interface JavacRunner {
diff --git a/src/java_tools/buildjar/java/com/google/devtools/build/buildjar/javac/plugins/BlazeJavaCompilerPlugin.java b/src/java_tools/buildjar/java/com/google/devtools/build/buildjar/javac/plugins/BlazeJavaCompilerPlugin.java
index f269858124..febbd06ee6 100644
--- a/src/java_tools/buildjar/java/com/google/devtools/build/buildjar/javac/plugins/BlazeJavaCompilerPlugin.java
+++ b/src/java_tools/buildjar/java/com/google/devtools/build/buildjar/javac/plugins/BlazeJavaCompilerPlugin.java
@@ -14,7 +14,6 @@
package com.google.devtools.build.buildjar.javac.plugins;
import com.google.devtools.build.buildjar.InvalidCommandLineException;
-
import com.sun.tools.javac.comp.AttrContext;
import com.sun.tools.javac.comp.Env;
import com.sun.tools.javac.main.JavaCompiler;
@@ -22,7 +21,6 @@ import com.sun.tools.javac.main.Main.Result;
import com.sun.tools.javac.util.Context;
import com.sun.tools.javac.util.Log;
import com.sun.tools.javac.util.PropagatedException;
-
import java.util.List;
/**
@@ -30,9 +28,8 @@ import java.util.List;
* specific points in the compilation process. This class provides callbacks after the attribute and
* flow phases of the javac compilation process. A static analysis may be implemented by subclassing
* this abstract class and performing the analysis in the callback methods. The analysis may then be
- * registered with the BlazeJavaCompiler to be run during the compilation process. See
- * {@link com.google.devtools.build.buildjar.javac.plugins.dependency.StrictJavaDepsPlugin} for an
- * example.
+ * registered with the BlazeJavaCompiler to be run during the compilation process. See {@link
+ * com.google.devtools.build.buildjar.javac.plugins.dependency.StrictJavaDepsPlugin} for an example.
*/
public abstract class BlazeJavaCompilerPlugin {
@@ -61,9 +58,7 @@ public abstract class BlazeJavaCompilerPlugin {
}
}
- /**
- * Pass an error through javac.Main to BlazeJavacMain and cleanly shut down the compiler.
- */
+ /** Pass an error through javac.Main to BlazeJavacMain and cleanly shut down the compiler. */
protected static Exception throwError(Result result, String message) {
// Javac re-throws exceptions wrapped by PropagatedException.
throw new PropagatedException(new PluginException(result, message));
@@ -74,8 +69,8 @@ public abstract class BlazeJavaCompilerPlugin {
protected JavaCompiler compiler;
/**
- * Preprocess the command-line flags that were passed to javac. This is called before
- * {@link #init(Context, Log, JavaCompiler)} and {@link #initializeContext(Context)}.
+ * Preprocess the command-line flags that were passed to javac. This is called before {@link
+ * #init(Context, Log, JavaCompiler)} and {@link #initializeContext(Context)}.
*
* @param args The command-line flags that javac was invoked with.
* @throws InvalidCommandLineException if the arguments are invalid
@@ -92,33 +87,32 @@ public abstract class BlazeJavaCompilerPlugin {
public void initializeContext(Context context) {
this.context = context;
}
-
+
/**
- * Performs analysis actions after the attribute phase of the javac compiler.
- * The attribute phase performs symbol resolution on the parse tree.
+ * Performs analysis actions after the attribute phase of the javac compiler. The attribute phase
+ * performs symbol resolution on the parse tree.
*
* @param env The attributed parse tree (after symbol resolution)
*/
public void postAttribute(Env<AttrContext> env) {}
/**
- * Performs analysis actions after the flow phase of the javac compiler.
- * The flow phase performs dataflow checks, such as finding unreachable
- * statements.
+ * Performs analysis actions after the flow phase of the javac compiler. The flow phase performs
+ * dataflow checks, such as finding unreachable statements.
*
* @param env The attributed parse tree (after symbol resolution)
*/
public void postFlow(Env<AttrContext> env) {}
/**
- * Performs analysis actions when the compiler is done and is about to wipe
- * clean its internal data structures (such as the symbol table).
+ * Performs analysis actions when the compiler is done and is about to wipe clean its internal
+ * data structures (such as the symbol table).
*/
public void finish() {}
/**
- * Initializes the plugin. Called by
- * {@link com.google.devtools.build.buildjar.javac.BlazeJavaCompiler}'s constructor.
+ * Initializes the plugin. Called by {@link
+ * com.google.devtools.build.buildjar.javac.BlazeJavaCompiler}'s constructor.
*
* @param context The Context object from the enclosing BlazeJavaCompiler instance
* @param log The Log object from the enclosing BlazeJavaCompiler instance
diff --git a/src/java_tools/buildjar/java/com/google/devtools/build/buildjar/javac/plugins/classloader/ClassLoaderMaskingPlugin.java b/src/java_tools/buildjar/java/com/google/devtools/build/buildjar/javac/plugins/classloader/ClassLoaderMaskingPlugin.java
index 59e2b9ec90..d77ea8bc6d 100644
--- a/src/java_tools/buildjar/java/com/google/devtools/build/buildjar/javac/plugins/classloader/ClassLoaderMaskingPlugin.java
+++ b/src/java_tools/buildjar/java/com/google/devtools/build/buildjar/javac/plugins/classloader/ClassLoaderMaskingPlugin.java
@@ -13,15 +13,12 @@
// limitations under the License.
package com.google.devtools.build.buildjar.javac.plugins.classloader;
-
-import com.google.devtools.build.buildjar.javac.plugins.BlazeJavaCompilerPlugin;
+import com.google.devtools.build.buildjar.javac.plugins.BlazeJavaCompilerPlugin;
import com.sun.tools.javac.file.JavacFileManager;
import com.sun.tools.javac.util.Context;
-
import java.net.URL;
import java.net.URLClassLoader;
-
import javax.tools.JavaFileManager;
/** A plugin that customizes the Java compiler for the Error Prone plugin. */
@@ -29,25 +26,27 @@ public final class ClassLoaderMaskingPlugin extends BlazeJavaCompilerPlugin {
@Override
public void initializeContext(Context context) {
- context.put(JavaFileManager.class, new Context.Factory<JavaFileManager>() {
- @Override
- public JavaFileManager make(Context c) {
- return new JavacFileManager(c, true, null) {
+ context.put(
+ JavaFileManager.class,
+ new Context.Factory<JavaFileManager>() {
@Override
- protected ClassLoader getClassLoader(URL[] urls) {
- return new URLClassLoader(urls, makeMaskedClassLoader());
+ public JavaFileManager make(Context c) {
+ return new JavacFileManager(c, true, null) {
+ @Override
+ protected ClassLoader getClassLoader(URL[] urls) {
+ return new URLClassLoader(urls, makeMaskedClassLoader());
+ }
+ };
}
- };
- }
- });
+ });
super.initializeContext(context);
}
/**
* When Bazel invokes JavaBuilder, it puts javac.jar on the bootstrap class path and
- * JavaBuilder_deploy.jar on the user class path. We need Error Prone to be
- * available on the annotation processor path, but we want to mask out any other
- * classes to minimize class version skew.
+ * JavaBuilder_deploy.jar on the user class path. We need Error Prone to be available on the
+ * annotation processor path, but we want to mask out any other classes to minimize class version
+ * skew.
*/
private ClassLoader makeMaskedClassLoader() {
return new ClassLoader(JavacFileManager.class.getClassLoader()) {
diff --git a/src/java_tools/buildjar/java/com/google/devtools/build/buildjar/javac/plugins/dependency/DependencyModule.java b/src/java_tools/buildjar/java/com/google/devtools/build/buildjar/javac/plugins/dependency/DependencyModule.java
index 80ea962836..c35d0d756c 100644
--- a/src/java_tools/buildjar/java/com/google/devtools/build/buildjar/javac/plugins/dependency/DependencyModule.java
+++ b/src/java_tools/buildjar/java/com/google/devtools/build/buildjar/javac/plugins/dependency/DependencyModule.java
@@ -41,13 +41,13 @@ import java.util.Map;
import java.util.Set;
/**
- * Wrapper class for managing dependencies on top of
- * {@link com.google.devtools.build.buildjar.javac.BlazeJavaCompiler}. If strict_java_deps is
- * enabled, it keeps two maps between jar names (as they appear on the classpath) and their
- * originating targets, one for direct dependencies and the other for transitive (indirect)
- * dependencies, and enables the {@link StrictJavaDepsPlugin} to perform the actual checks. The
- * plugin also collects dependency information during compilation, and DependencyModule generates a
- * .jdeps artifact summarizing the discovered dependencies.
+ * Wrapper class for managing dependencies on top of {@link
+ * com.google.devtools.build.buildjar.javac.BlazeJavaCompiler}. If strict_java_deps is enabled, it
+ * keeps two maps between jar names (as they appear on the classpath) and their originating targets,
+ * one for direct dependencies and the other for transitive (indirect) dependencies, and enables the
+ * {@link StrictJavaDepsPlugin} to perform the actual checks. The plugin also collects dependency
+ * information during compilation, and DependencyModule generates a .jdeps artifact summarizing the
+ * discovered dependencies.
*/
public final class DependencyModule {
@@ -114,9 +114,7 @@ public final class DependencyModule {
this.packages = new HashSet<>();
}
- /**
- * Returns a plugin to be enabled in the compiler.
- */
+ /** Returns a plugin to be enabled in the compiler. */
public BlazeJavaCompilerPlugin getPlugin() {
return new StrictJavaDepsPlugin(this);
}
@@ -133,7 +131,7 @@ public final class DependencyModule {
}
try (BufferedOutputStream out =
- new BufferedOutputStream(new FileOutputStream(outputDepsProtoFile))) {
+ new BufferedOutputStream(new FileOutputStream(outputDepsProtoFile))) {
buildDependenciesProto(classpath, successful).writeTo(out);
} catch (IOException ex) {
throw new IOException("Cannot write dependencies to " + outputDepsProtoFile, ex);
@@ -170,9 +168,7 @@ public final class DependencyModule {
return deps.build();
}
- /**
- * Returns whether strict dependency checks (strictJavaDeps) are enabled.
- */
+ /** Returns whether strict dependency checks (strictJavaDeps) are enabled. */
public boolean isStrictDepsEnabled() {
return strictJavaDeps.isEnabled();
}
@@ -193,23 +189,17 @@ public final class DependencyModule {
return indirectJarsToTargets;
}
- /**
- * Returns the strict dependency checking (strictJavaDeps) setting.
- */
+ /** Returns the strict dependency checking (strictJavaDeps) setting. */
public StrictJavaDeps getStrictJavaDeps() {
return strictJavaDeps;
}
- /**
- * Returns the map collecting precise explicit dependency information.
- */
+ /** Returns the map collecting precise explicit dependency information. */
public Map<String, Deps.Dependency> getExplicitDependenciesMap() {
return explicitDependenciesMap;
}
- /**
- * Returns the map collecting precise implicit dependency information.
- */
+ /** Returns the map collecting precise implicit dependency information. */
public Map<String, Deps.Dependency> getImplicitDependenciesMap() {
return implicitDependenciesMap;
}
@@ -219,23 +209,17 @@ public final class DependencyModule {
return packages.add(packge);
}
- /**
- * Returns the type (rule kind) of the originating target.
- */
+ /** Returns the type (rule kind) of the originating target. */
public String getRuleKind() {
return ruleKind;
}
- /**
- * Returns the name (label) of the originating target.
- */
+ /** Returns the name (label) of the originating target. */
public String getTargetLabel() {
return targetLabel;
}
- /**
- * Returns the file name collecting dependency information.
- */
+ /** Returns the file name collecting dependency information. */
public String getOutputDepsProtoFile() {
return outputDepsProtoFile;
}
@@ -250,16 +234,12 @@ public final class DependencyModule {
return fixMessage;
}
- /**
- * Return a set of generator values that are exempt from strict dependencies.
- */
+ /** Return a set of generator values that are exempt from strict dependencies. */
public Set<String> getExemptGenerators() {
return exemptGenerators;
}
- /**
- * Returns whether classpath reduction is enabled for this invocation.
- */
+ /** Returns whether classpath reduction is enabled for this invocation. */
public boolean reduceClasspath() {
return strictClasspathMode;
}
@@ -292,7 +272,7 @@ public final class DependencyModule {
requiredClasspath = new HashSet<>(directJarsToTargets.keySet());
for (String depsArtifact : depsArtifacts) {
- collectDependenciesFromArtifact(depsArtifact);
+ collectDependenciesFromArtifact(depsArtifact);
}
// Filter the initial classpath and keep the original order
@@ -310,9 +290,7 @@ public final class DependencyModule {
this.requiredClasspath = strictClasspath;
}
- /**
- * Updates {@link #requiredClasspath} to include dependencies from the given output artifact.
- */
+ /** Updates {@link #requiredClasspath} to include dependencies from the given output artifact. */
private void collectDependenciesFromArtifact(String path) throws IOException {
try (BufferedInputStream bis = new BufferedInputStream(new FileInputStream(path))) {
Deps.Dependencies deps = Deps.Dependencies.parseFrom(bis);
@@ -340,9 +318,7 @@ public final class DependencyModule {
String get(Iterable<JarOwner> missing, String recipient, boolean useColor);
}
- /**
- * Builder for {@link DependencyModule}.
- */
+ /** Builder for {@link DependencyModule}. */
public static class Builder {
private StrictJavaDeps strictJavaDeps = StrictJavaDeps.OFF;
@@ -375,9 +351,8 @@ public final class DependencyModule {
}
/**
- * Constructs the DependencyModule, guaranteeing that the maps are
- * never null (they may be empty), and the default strictJavaDeps setting
- * is OFF.
+ * Constructs the DependencyModule, guaranteeing that the maps are never null (they may be
+ * empty), and the default strictJavaDeps setting is OFF.
*
* @return an instance of DependencyModule
*/
diff --git a/src/java_tools/buildjar/java/com/google/devtools/build/buildjar/javac/plugins/processing/AnnotationProcessingModule.java b/src/java_tools/buildjar/java/com/google/devtools/build/buildjar/javac/plugins/processing/AnnotationProcessingModule.java
index 04861477f5..ea9415c609 100644
--- a/src/java_tools/buildjar/java/com/google/devtools/build/buildjar/javac/plugins/processing/AnnotationProcessingModule.java
+++ b/src/java_tools/buildjar/java/com/google/devtools/build/buildjar/javac/plugins/processing/AnnotationProcessingModule.java
@@ -19,7 +19,6 @@ import com.google.common.collect.ImmutableSet;
import com.google.devtools.build.buildjar.javac.plugins.BlazeJavaCompilerPlugin;
import com.google.devtools.build.buildjar.proto.JavaCompilation.CompilationUnit;
import com.google.devtools.build.buildjar.proto.JavaCompilation.Manifest;
-
import java.io.IOException;
import java.io.OutputStream;
import java.nio.file.Files;
@@ -32,14 +31,10 @@ import java.util.List;
import java.util.Map;
import java.util.Set;
-/**
- * A module for information about the compilation's annotation processing.
- */
+/** A module for information about the compilation's annotation processing. */
public class AnnotationProcessingModule {
- /**
- * A builder for {@link AnnotationProcessingModule}s.
- */
+ /** A builder for {@link AnnotationProcessingModule}s. */
public static class Builder {
private Path sourceGenDir;
private Path manifestProto;
@@ -55,8 +50,8 @@ public class AnnotationProcessingModule {
/**
* Verify that source roots do not contain other source roots.
*
- * <p>If one source root is an ancestor of another, the source path to
- * use in the manifest will be ambiguous.
+ * <p>If one source root is an ancestor of another, the source path to use in the manifest will
+ * be ambiguous.
*/
private ImmutableSet<Path> validateSourceRoots(ImmutableSet<Path> roots) {
// It's sad that this is quadratic, but the number of source roots
diff --git a/src/java_tools/buildjar/java/com/google/devtools/build/buildjar/javac/plugins/processing/AnnotationProcessingPlugin.java b/src/java_tools/buildjar/java/com/google/devtools/build/buildjar/javac/plugins/processing/AnnotationProcessingPlugin.java
index bc2982e42a..a16ac46408 100644
--- a/src/java_tools/buildjar/java/com/google/devtools/build/buildjar/javac/plugins/processing/AnnotationProcessingPlugin.java
+++ b/src/java_tools/buildjar/java/com/google/devtools/build/buildjar/javac/plugins/processing/AnnotationProcessingPlugin.java
@@ -16,21 +16,16 @@ package com.google.devtools.build.buildjar.javac.plugins.processing;
import com.google.devtools.build.buildjar.javac.plugins.BlazeJavaCompilerPlugin;
import com.google.devtools.build.buildjar.proto.JavaCompilation.CompilationUnit;
-
import com.sun.tools.javac.comp.AttrContext;
import com.sun.tools.javac.comp.Env;
import com.sun.tools.javac.tree.JCTree;
import com.sun.tools.javac.tree.JCTree.JCClassDecl;
import com.sun.tools.javac.tree.JCTree.JCCompilationUnit;
-
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.HashSet;
-/**
- * A plugin that records information about sources generated during annotation
- * processing.
- */
+/** A plugin that records information about sources generated during annotation processing. */
public class AnnotationProcessingPlugin extends BlazeJavaCompilerPlugin {
private final HashSet<JCCompilationUnit> toplevels = new HashSet<>();
diff --git a/src/java_tools/buildjar/java/com/google/devtools/build/java/bazel/BazelJavaCompiler.java b/src/java_tools/buildjar/java/com/google/devtools/build/java/bazel/BazelJavaCompiler.java
index 4ca4676685..cecf2e0a50 100644
--- a/src/java_tools/buildjar/java/com/google/devtools/build/java/bazel/BazelJavaCompiler.java
+++ b/src/java_tools/buildjar/java/com/google/devtools/build/java/bazel/BazelJavaCompiler.java
@@ -36,14 +36,14 @@ import javax.tools.StandardJavaFileManager;
import javax.tools.StandardLocation;
/**
- * Provides a {@link JavaCompiler} that has behavior as similar as possible
- * to the java compiler provided by default by Bazel.
- * Replace calls to {@link javax.tools.ToolProvider#getSystemJavaCompiler}
- * with calls to {@link BazelJavaCompiler#newInstance}.
+ * Provides a {@link JavaCompiler} that has behavior as similar as possible to the java compiler
+ * provided by default by Bazel. Replace calls to {@link
+ * javax.tools.ToolProvider#getSystemJavaCompiler} with calls to {@link
+ * BazelJavaCompiler#newInstance}.
*
- * <p>This class is typically used only from a host build tool or in tests.
- * When using this in production, langtools.jar and the bootclasspath jars
- * are deployed as separate jar files within the runfiles directory.
+ * <p>This class is typically used only from a host build tool or in tests. When using this in
+ * production, langtools.jar and the bootclasspath jars are deployed as separate jar files within
+ * the runfiles directory.
*/
public class BazelJavaCompiler {
@@ -66,7 +66,8 @@ public class BazelJavaCompiler {
private static class LangtoolsClassLoader extends URLClassLoader {
public LangtoolsClassLoader() throws MalformedURLException {
- super(new URL[] { getLangtoolsJar().toURI().toURL() },
+ super(
+ new URL[] {getLangtoolsJar().toURI().toURL()},
// We use the bootstrap classloader (null) as the parent classloader
// instead of the default "system" class loader; we intentionally do
// not consult the classpath. This way the class path is not
@@ -93,9 +94,7 @@ public class BazelJavaCompiler {
.asSubclass(JavaCompiler.class);
}
- /**
- * Returns the langtools jar.
- */
+ /** Returns the langtools jar. */
public static File getLangtoolsJar() {
return JavaLangtools.file();
}
@@ -106,36 +105,31 @@ public class BazelJavaCompiler {
}
/**
- * Returns a new {@link JavaCompiler} that has behavior as similar as
- * possible to the java compiler provided by default by the bazel build
- * system, independent of the user-specified {@code JAVABASE}.
+ * Returns a new {@link JavaCompiler} that has behavior as similar as possible to the java
+ * compiler provided by default by the bazel build system, independent of the user-specified
+ * {@code JAVABASE}.
*
* <p>More precisely, this method works analogously to {@link
- * javax.tools.ToolProvider#getSystemJavaCompiler}, but returns a {@code
- * JavaCompiler} that differs in these details:
+ * javax.tools.ToolProvider#getSystemJavaCompiler}, but returns a {@code JavaCompiler} that
+ * differs in these details:
*
* <ul>
- *
- * <li> uses the blessed javac implementation: {@code //tools/defaults:java_langtools},
- * as defined by bazel's --java_langtools flag.
- *
- * <li> uses the blessed boot class path: {@code //tools/defaults:javac_bootclasspath},
- * as defined by bazel's --javac_bootclasspath flag.
- *
- * <li> uses the blessed default values for javac options such as {@code -source}
- *
+ * <li> uses the blessed javac implementation: {@code //tools/defaults:java_langtools}, as
+ * defined by bazel's --java_langtools flag.
+ * <li> uses the blessed boot class path: {@code //tools/defaults:javac_bootclasspath}, as
+ * defined by bazel's --javac_bootclasspath flag.
+ * <li> uses the blessed default values for javac options such as {@code -source}
* </ul>
*
- * <p>This class ensures that (by default) the {@code -source}, {@code
- * -target} and {@code -bootclasspath} flags all agree and specify the same
- * (blessed) JDK version, for language and API compatibility.
+ * <p>This class ensures that (by default) the {@code -source}, {@code -target} and {@code
+ * -bootclasspath} flags all agree and specify the same (blessed) JDK version, for language and
+ * API compatibility.
*
- * <p>This method finds the javac implementation using a custom classloader
- * that does not consult the user's classpath. This works well, unless the
- * return value is cast to a javac-implementation class like {@code
- * JavacTask}, in which case the dreaded classloader error "can't cast
- * JavacTaskImpl to JavacTask" raises its ugly head, in which case you should
- * use {@link #newInstance(ClassLoader)} instead.
+ * <p>This method finds the javac implementation using a custom classloader that does not consult
+ * the user's classpath. This works well, unless the return value is cast to a
+ * javac-implementation class like {@code JavacTask}, in which case the dreaded classloader error
+ * "can't cast JavacTaskImpl to JavacTask" raises its ugly head, in which case you should use
+ * {@link #newInstance(ClassLoader)} instead.
*/
public static JavaCompiler newInstance() {
try {
@@ -146,22 +140,20 @@ public class BazelJavaCompiler {
}
/**
- * Returns a new {@link JavaCompiler} that has behavior as similar as
- * possible to the java compiler provided by default by bazel,
- * independent of the user-specified {@code JAVABASE}.
+ * Returns a new {@link JavaCompiler} that has behavior as similar as possible to the java
+ * compiler provided by default by bazel, independent of the user-specified {@code JAVABASE}.
*
- * <p>This method has effect identical to {@link #newInstance()} (and that
- * method is generally preferred to this one), except that the javac
- * implementation is found via the provided classloader instead of defining a
- * custom classloader that knows the standard location of the blessed javac
- * implementation.
+ * <p>This method has effect identical to {@link #newInstance()} (and that method is generally
+ * preferred to this one), except that the javac implementation is found via the provided
+ * classloader instead of defining a custom classloader that knows the standard location of the
+ * blessed javac implementation.
*
- * <p>This method is needed when the return value is cast to a
- * javac-implementation class like {@code JavacTask}, to avoid the dreaded
- * multiple classloader error "can't cast JavacTaskImpl to JavacTask".
+ * <p>This method is needed when the return value is cast to a javac-implementation class like
+ * {@code JavacTask}, to avoid the dreaded multiple classloader error "can't cast JavacTaskImpl to
+ * JavacTask".
*
- * <p>Typically, users should pass {@code ClassLoader.getSystemClassLoader()}
- * as the argument to this method.
+ * <p>Typically, users should pass {@code ClassLoader.getSystemClassLoader()} as the argument to
+ * this method.
*/
public static JavaCompiler newInstance(ClassLoader cl) {
try {
diff --git a/src/java_tools/buildjar/java/com/google/devtools/build/java/bazel/BazelJavac.java b/src/java_tools/buildjar/java/com/google/devtools/build/java/bazel/BazelJavac.java
index 5b9dcfc23b..11d4440067 100644
--- a/src/java_tools/buildjar/java/com/google/devtools/build/java/bazel/BazelJavac.java
+++ b/src/java_tools/buildjar/java/com/google/devtools/build/java/bazel/BazelJavac.java
@@ -17,8 +17,8 @@ package com.google.devtools.build.java.bazel;
import javax.tools.JavaCompiler;
/**
- * Command line version of {@link BazelJavaCompiler}, interface-compatible
- * with the {@code javac} command, for use with {@code ant}, for example.
+ * Command line version of {@link BazelJavaCompiler}, interface-compatible with the {@code javac}
+ * command, for use with {@code ant}, for example.
*/
public class BazelJavac {
public static void main(String[] args) {
diff --git a/src/java_tools/buildjar/java/com/google/devtools/build/java/bazel/JavaBuilderConfigGenerator.java b/src/java_tools/buildjar/java/com/google/devtools/build/java/bazel/JavaBuilderConfigGenerator.java
index d169a0dc8d..0353d582b7 100644
--- a/src/java_tools/buildjar/java/com/google/devtools/build/java/bazel/JavaBuilderConfigGenerator.java
+++ b/src/java_tools/buildjar/java/com/google/devtools/build/java/bazel/JavaBuilderConfigGenerator.java
@@ -18,23 +18,21 @@ import com.google.common.base.Joiner;
import com.google.common.collect.ImmutableMap;
import com.google.devtools.build.lib.rules.java.JavaToolchainData;
import com.google.devtools.build.lib.rules.java.JavaToolchainDataParser;
-
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
-/**
- * Utility class to generate {@link JavaBuilderConfig}.
- */
+/** Utility class to generate {@link JavaBuilderConfig}. */
public class JavaBuilderConfigGenerator {
-
+
private static void die(String message) {
System.err.println(message);
System.err.println("\nThis program is expecting the protocol buffer output of a bazel query");
System.err.println("containing exactly one java_toolchain target. An example of such output");
System.err.println("can be obtained by:");
- System.err.println("\bazel query --output=proto "
- + "'kind(java_toolchain, deps(//tools/defaults:java_toolchain))'");
+ System.err.println(
+ "\bazel query --output=proto "
+ + "'kind(java_toolchain, deps(//tools/defaults:java_toolchain))'");
System.exit(-1);
}
@@ -52,8 +50,8 @@ public class JavaBuilderConfigGenerator {
String optsString = Joiner.on("\", \"").join(first.getJavacOptions());
System.out.println("package com.google.devtools.build.java.bazel;");
System.out.println("public class JavaBuilderJavacOpts {");
- System.out.println("public static final String[] DEFAULT_JAVACOPTS = {\""
- + optsString + "\"};");
+ System.out.println(
+ "public static final String[] DEFAULT_JAVACOPTS = {\"" + optsString + "\"};");
System.out.println("}");
} catch (IOException e) {
die("Cannot load input file: " + e.getMessage());
diff --git a/src/java_tools/buildjar/java/com/google/devtools/build/java/bazel/JavaLangtools.java b/src/java_tools/buildjar/java/com/google/devtools/build/java/bazel/JavaLangtools.java
index 53c1d75d9c..ce4d3556cc 100644
--- a/src/java_tools/buildjar/java/com/google/devtools/build/java/bazel/JavaLangtools.java
+++ b/src/java_tools/buildjar/java/com/google/devtools/build/java/bazel/JavaLangtools.java
@@ -20,8 +20,8 @@ import java.io.IOError;
import java.nio.file.AccessDeniedException;
/**
- * Utility class to provide java-level access to the blessed langtools jar path:
- * {@code //third_party/java/jdk:langtools}, as defined by bazel's --java_langtools flag.
+ * Utility class to provide java-level access to the blessed langtools jar path: {@code
+ * //third_party/java/jdk:langtools}, as defined by bazel's --java_langtools flag.
*/
public class JavaLangtools {
@@ -49,9 +49,7 @@ public class JavaLangtools {
FILE = file;
}
- /**
- * Returns the blessed langtools jar path.
- */
+ /** Returns the blessed langtools jar path. */
public static File file() {
return FILE;
}
diff --git a/src/java_tools/buildjar/java/com/google/devtools/build/java/bazel/JavacBootclasspath.java b/src/java_tools/buildjar/java/com/google/devtools/build/java/bazel/JavacBootclasspath.java
index 726443064f..327b9a9f9b 100644
--- a/src/java_tools/buildjar/java/com/google/devtools/build/java/bazel/JavacBootclasspath.java
+++ b/src/java_tools/buildjar/java/com/google/devtools/build/java/bazel/JavacBootclasspath.java
@@ -21,12 +21,11 @@ import java.util.ArrayList;
import java.util.List;
/**
- * Utility class to provide java-level access to the blessed javac boot class path:
- * {@code //tools/defaults:javac_bootclasspath}, as defined by bazel's --javac_bootclasspath flag.
+ * Utility class to provide java-level access to the blessed javac boot class path: {@code
+ * //tools/defaults:javac_bootclasspath}, as defined by bazel's --javac_bootclasspath flag.
*
- * <p>This class is typically used only from a host build tool or in
- * tests. When using this in production, the bootclasspath is
- * deployed as separate jar files within the runfiles directory.
+ * <p>This class is typically used only from a host build tool or in tests. When using this in
+ * production, the bootclasspath is deployed as separate jar files within the runfiles directory.
*/
public class JavacBootclasspath {
@@ -54,8 +53,7 @@ public class JavacBootclasspath {
File file = new File(runfilesRoot, location);
if (!file.isFile()) {
throw new IOError(
- new FileNotFoundException(
- "Can't find boot class path element: " + file.getPath()));
+ new FileNotFoundException("Can't find boot class path element: " + file.getPath()));
}
files.add(file);
if (str.length() > 0) {
@@ -70,8 +68,8 @@ public class JavacBootclasspath {
/**
* Returns the blessed boot class path as a colon-separated string.
*
- * Suitable for passing as the value of a {@code -bootclasspath} flag.
- * Valid while the current build action or test is executing.
+ * <p>Suitable for passing as the value of a {@code -bootclasspath} flag. Valid while the current
+ * build action or test is executing.
*/
public static String asString() {
return AS_STRING;
@@ -80,8 +78,8 @@ public class JavacBootclasspath {
/**
* Returns the blessed boot class path as a list of {@code File} objects.
*
- * Each {@code File} will represent a jar file that will exist while the
- * current build action or test is executing.
+ * <p>Each {@code File} will represent a jar file that will exist while the current build action
+ * or test is executing.
*/
public static List<File> asFiles() {
return new ArrayList<>(AS_FILES);
diff --git a/src/java_tools/buildjar/javatests/com/google/devtools/build/java/bazel/BazelJavaCompilerTest.java b/src/java_tools/buildjar/javatests/com/google/devtools/build/java/bazel/BazelJavaCompilerTest.java
index 78ec60e48e..53f1ecc463 100644
--- a/src/java_tools/buildjar/javatests/com/google/devtools/build/java/bazel/BazelJavaCompilerTest.java
+++ b/src/java_tools/buildjar/javatests/com/google/devtools/build/java/bazel/BazelJavaCompilerTest.java
@@ -18,31 +18,27 @@ import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.junit.runners.JUnit4;
-
import java.io.File;
import java.net.URI;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
-
import javax.tools.DiagnosticCollector;
import javax.tools.JavaCompiler;
import javax.tools.JavaFileObject;
import javax.tools.SimpleJavaFileObject;
import javax.tools.StandardJavaFileManager;
import javax.tools.StandardLocation;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.JUnit4;
-/**
- * Sanity checks: make sure we can instantiate a working javac compiler.
- */
+/** Sanity checks: make sure we can instantiate a working javac compiler. */
@RunWith(JUnit4.class)
public class BazelJavaCompilerTest {
private static File getTmpDir() {
- String tmpdir = System.getenv("TEST_TMPDIR");
+ String tmpdir = System.getenv("TEST_TMPDIR");
if (tmpdir == null) {
// Fall back on the system temporary directory
tmpdir = System.getProperty("java.io.tmpdir");
@@ -68,7 +64,8 @@ public class BazelJavaCompilerTest {
@Test
public void testAllowsJava7LanguageFeatures() throws Exception {
- assertCompileSucceeds("string://Test.java",
+ assertCompileSucceeds(
+ "string://Test.java",
"class Test {"
+ " void foo(String s) {"
+ " switch (s) {"
@@ -80,10 +77,8 @@ public class BazelJavaCompilerTest {
}
@Test
- public void testAllowsJava7APIs() throws Exception {
- assertCompileSucceeds("string://Test.java",
- "import java.nio.file.Files;"
- + "class Test {}");
+ public void testAllowsJava7APIs() throws Exception {
+ assertCompileSucceeds("string://Test.java", "import java.nio.file.Files;" + "class Test {}");
}
@Test
@@ -99,19 +94,19 @@ public class BazelJavaCompilerTest {
private void assertCompileSucceeds(final String uri, final String content) throws Exception {
JavaCompiler javac = BazelJavaCompiler.newInstance();
- JavaFileObject source = new SimpleJavaFileObject(
- URI.create(uri), JavaFileObject.Kind.SOURCE) {
- @Override
- public CharSequence getCharContent(boolean ignoreEncodingErrors) {
- return content;
- }
- };
+ JavaFileObject source =
+ new SimpleJavaFileObject(URI.create(uri), JavaFileObject.Kind.SOURCE) {
+ @Override
+ public CharSequence getCharContent(boolean ignoreEncodingErrors) {
+ return content;
+ }
+ };
StandardJavaFileManager fileManager = javac.getStandardFileManager(null, null, null);
// setting the output path by passing a flag to getTask is not reliable
fileManager.setLocation(StandardLocation.CLASS_OUTPUT, Arrays.asList(getTmpDir()));
DiagnosticCollector<JavaFileObject> messages = new DiagnosticCollector<>();
- JavaCompiler.CompilationTask task = javac.getTask(
- null, fileManager, messages, null, null, Collections.singletonList(source));
+ JavaCompiler.CompilationTask task =
+ javac.getTask(null, fileManager, messages, null, null, Collections.singletonList(source));
assertTrue(task.call());
assertTrue(messages.getDiagnostics().isEmpty());
}
diff --git a/src/java_tools/buildjar/javatests/com/google/devtools/build/java/turbine/javac/TreePrunerTest.java b/src/java_tools/buildjar/javatests/com/google/devtools/build/java/turbine/javac/TreePrunerTest.java
index 7acb9c959f..992ce70d7a 100644
--- a/src/java_tools/buildjar/javatests/com/google/devtools/build/java/turbine/javac/TreePrunerTest.java
+++ b/src/java_tools/buildjar/javatests/com/google/devtools/build/java/turbine/javac/TreePrunerTest.java
@@ -293,18 +293,12 @@ public class TreePrunerTest {
@Test
public void interfaceDeclaration() {
String[] lines = {
- "interface Intf {",
- " int CONST = 42;",
- " int NONCONST = new Integer(42);",
- "}",
+ "interface Intf {", " int CONST = 42;", " int NONCONST = new Integer(42);", "}",
};
JCCompilationUnit tree = parseLines(lines);
TreePruner.prune(context, tree);
String[] expected = {
- "interface Intf {",
- " int CONST = 42;",
- " int NONCONST;",
- "}",
+ "interface Intf {", " int CONST = 42;", " int NONCONST;", "}",
};
assertThat(prettyPrint(tree)).isEqualTo(Joiner.on('\n').join(expected));
}
@@ -327,15 +321,15 @@ public class TreePrunerTest {
JCCompilationUnit tree = parseLines(lines);
TreePruner.prune(context, tree);
String[] expected = {
- "class Test {",
- " ",
- " class Inner {",
- " ",
- " Inner(OuterInstance outer) {",
- " outer.super();",
- " }",
- " }",
- "}",
+ "class Test {",
+ " ",
+ " class Inner {",
+ " ",
+ " Inner(OuterInstance outer) {",
+ " outer.super();",
+ " }",
+ " }",
+ "}",
};
assertThat(prettyPrint(tree)).isEqualTo(Joiner.on('\n').join(expected));
}