Skip to content

Commit 9fa72ed

Browse files
msridh2raviagarwal7
authored andcommitted
Changes to Bazel's java_tools to enable Error Prone auto-patching
Summary: This diff contains the changes in bazelbuild#21640, ported to the uber/java/7.0.2.001 branch. We also commit a modified version of the Error Prone check_api jar. The modifications in that jar are those changes in google/error-prone#4318 applied to Error Prone 2.22.0 (the version used in our branch). Probably, rather than committing the modified jar, we could upload the modified jar to artifactory and change the version we depend on here. I have tested that these changes work locally on a devpod. `IN_PLACE` patching will most likely not work under stronger sandboxes, as it relies on modifying the source files in the sandbox (which, by default on a devpod, are just symlinks to the original source files). Also, there seem to be some weird interactions with the Bazel cache, such that when I tried to run the same autopatch twice (after undoing the initial changes), I had to blow away my local `~/.bazelcache` directory to make it work. Test Plan: Tested locally by copying over the built java_tools jars and running: ``` EP_PATCH_CHECK=MissingOverride EP_PATCH_CHECK_PATH_ONLY=a/b/c tools/bazel build //a/b/c:src ``` It would be good to write an integration test for this at some point, since it hasn't been upstreamed. Reviewers: cjk Subscribers: ravirajj, ravi Revert Plan: n/a JIRA Issues: JAVADEVX-8326 Differential Revision: https://code.uberinternal.com/D13309409 Update Error Prone jar in Bazel java_tools with further fix Summary: Jar now includes the fix in https://code.uberinternal.com/D13331711?vs=37208341&id=37966971 JIRA Issues: JAVADEVX-8326 Differential Revision: https://code.uberinternal.com/D13628673
1 parent 94bad9f commit 9fa72ed

File tree

4 files changed

+16
-2
lines changed

4 files changed

+16
-2
lines changed

src/java_tools/buildjar/java/com/google/devtools/build/buildjar/javac/plugins/BUILD

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ java_library(
5050
name = "errorprone",
5151
srcs = glob(["errorprone/*.java"]),
5252
javacopts = [
53+
"--add-exports=jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED",
5354
"--add-exports=jdk.compiler/com.sun.tools.javac.code=ALL-UNNAMED",
5455
"--add-exports=jdk.compiler/com.sun.tools.javac.comp=ALL-UNNAMED",
5556
"--add-exports=jdk.compiler/com.sun.tools.javac.main=ALL-UNNAMED",

src/java_tools/buildjar/java/com/google/devtools/build/buildjar/javac/plugins/errorprone/ErrorPronePlugin.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,12 @@
2525
import com.google.errorprone.ErrorProneOptions;
2626
import com.google.errorprone.ErrorProneTimings;
2727
import com.google.errorprone.InvalidCommandLineOptionException;
28+
import com.google.errorprone.RefactoringCollection;
2829
import com.google.errorprone.scanner.BuiltInCheckerSuppliers;
2930
import com.google.errorprone.scanner.ScannerSupplier;
3031
import com.sun.source.util.TaskEvent;
3132
import com.sun.source.util.TaskEvent.Kind;
33+
import com.sun.tools.javac.api.MultiTaskListener;
3234
import com.sun.tools.javac.code.DeferredCompletionFailureHandler;
3335
import com.sun.tools.javac.comp.AttrContext;
3436
import com.sun.tools.javac.comp.Env;
@@ -106,8 +108,14 @@ public void init(
106108
if (epOptions == null) {
107109
epOptions = ErrorProneOptions.empty();
108110
}
111+
RefactoringCollection[] refactoringCollection = {null};
109112
errorProneAnalyzer =
110-
ErrorProneAnalyzer.createByScanningForPlugins(scannerSupplier, epOptions, context);
113+
ErrorProneAnalyzer.createAnalyzer(scannerSupplier, epOptions, context, refactoringCollection);
114+
if (refactoringCollection[0] != null) {
115+
ErrorProneAnalyzer.RefactoringTask refactoringTask =
116+
new ErrorProneAnalyzer.RefactoringTask(context, refactoringCollection[0]);
117+
MultiTaskListener.instance(context).add(refactoringTask);
118+
}
111119
timings = ErrorProneTimings.instance(context);
112120
deferredCompletionFailureHandler = DeferredCompletionFailureHandler.instance(context);
113121
}

third_party/BUILD

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -310,11 +310,16 @@ distrib_jar_filegroup(
310310
enable_distributions = ["debian"],
311311
)
312312

313+
java_import(
314+
name = "error_prone_check_api_patched",
315+
jars = ["error_prone_check_api_patched/error_prone_check_api-2.22.0.jar"],
316+
)
317+
313318
java_library(
314319
name = "error_prone",
315320
exports = [
316321
":error_prone_annotations",
317-
"@maven//:com_google_errorprone_error_prone_check_api",
322+
":error_prone_check_api_patched",
318323
"@maven//:com_google_errorprone_error_prone_core",
319324
],
320325
)
Binary file not shown.

0 commit comments

Comments
 (0)