Add error-prone support

Add support for compiling java sources with the error-prone tool.

Test: m -j checkbuild
Change-Id: Ieb4ee0e05f8f34a52ed7bcf1c7cbacf1c9c4d0b5
diff --git a/java/java.go b/java/java.go
index ac88020..e2e15d4 100644
--- a/java/java.go
+++ b/java/java.go
@@ -330,6 +330,8 @@
 
 	srcFileLists = append(srcFileLists, j.ExtraSrcLists...)
 
+	var extraJarDeps android.Paths
+
 	if len(srcFiles) > 0 {
 		// Compile java sources into .class files
 		classes := TransformJavaToClasses(ctx, srcFiles, srcFileLists, flags, deps)
@@ -337,6 +339,17 @@
 			return
 		}
 
+		if ctx.AConfig().IsEnvTrue("RUN_ERROR_PRONE") {
+			// If error-prone is enabled, add an additional rule to compile the java files into
+			// a separate set of classes (so that they don't overwrite the normal ones and require
+			// a rebuild when error-prone is turned off).  Add the classes as a dependency to
+			// the jar command so the two compiles can run in parallel.
+			// TODO(ccross): Once we always compile with javac9 we may be able to conditionally
+			//    enable error-prone without affecting the output class files.
+			errorprone := RunErrorProne(ctx, srcFiles, srcFileLists, flags, deps)
+			extraJarDeps = append(extraJarDeps, errorprone)
+		}
+
 		classJarSpecs = append([]jarSpec{classes}, classJarSpecs...)
 	}
 
@@ -349,7 +362,7 @@
 	allJarSpecs = append(allJarSpecs, resourceJarSpecs...)
 
 	// Combine classes + resources into classes-full-debug.jar
-	outputFile := TransformClassesToJar(ctx, allJarSpecs, manifest)
+	outputFile := TransformClassesToJar(ctx, allJarSpecs, manifest, extraJarDeps)
 	if ctx.Failed() {
 		return
 	}
@@ -575,7 +588,7 @@
 		j.resourceJarSpecs = append(j.resourceJarSpecs, resourceJarSpec)
 	}
 
-	j.combinedClasspathFile = TransformClassesToJar(ctx, j.classJarSpecs, android.OptionalPath{})
+	j.combinedClasspathFile = TransformClassesToJar(ctx, j.classJarSpecs, android.OptionalPath{}, nil)
 
 	ctx.InstallFileName(android.PathForModuleInstall(ctx, "framework"),
 		ctx.ModuleName()+".jar", j.combinedClasspathFile)