diff options
author | Liam Miller-Cushon <cushon@google.com> | 2015-05-18 19:50:00 +0000 |
---|---|---|
committer | Damien Martin-Guillerez <dmarting@google.com> | 2015-05-18 22:03:43 +0200 |
commit | 29e46b23143eaeeda1d43e72d0a69131490e6bde (patch) | |
tree | 531380b1ae26af8942f3f9426e6179fb744de6f5 | |
parent | 9e3cc2e608184e9f3ff9eea5a97116e61c6cee23 (diff) |
Add a plugin to drop Error Prone-specific javacopts
--
MOS_MIGRATED_REVID=93915666
-rwxr-xr-x | compile.sh | 2 | ||||
-rw-r--r-- | src/java_tools/buildjar/BUILD | 1 | ||||
-rw-r--r-- | src/java_tools/buildjar/java/com/google/devtools/build/buildjar/BazelJavaBuilder.java | 7 | ||||
-rw-r--r-- | src/java_tools/buildjar/java/com/google/devtools/build/buildjar/javac/plugins/errorprone/ErrorProneOptionsPlugin.java | 64 | ||||
-rw-r--r-- | src/java_tools/buildjar/java/com/google/devtools/build/buildjar/javac/plugins/filemanager/FileManagerInitializationPlugin.java (renamed from src/java_tools/buildjar/java/com/google/devtools/build/buildjar/javac/plugins/dependency/FileManagerInitializationPlugin.java) | 2 | ||||
-rw-r--r-- | third_party/BUILD | 5 | ||||
-rw-r--r-- | third_party/README.md | 5 | ||||
-rw-r--r-- | third_party/error_prone/error_prone_core-2.0.2.jar | bin | 0 -> 3107395 bytes |
8 files changed, 82 insertions, 4 deletions
diff --git a/compile.sh b/compile.sh index 4bafe268cb..b38763fa98 100755 --- a/compile.sh +++ b/compile.sh @@ -50,7 +50,7 @@ DIRS=$(echo src/{main/java,tools/xcode-common/java/com/google/devtools/build/xco SINGLEJAR_DIRS="src/java_tools/singlejar/java src/main/java/com/google/devtools/build/lib/shell" SINGLEJAR_LIBRARIES="third_party/guava/guava-18.0.jar third_party/jsr305/jsr-305.jar" BUILDJAR_DIRS="src/java_tools/buildjar/java/com/google/devtools/build/buildjar output/src/com/google/devtools/build/lib/view/proto" -BUILDJAR_LIBRARIES="third_party/guava/guava-18.0.jar third_party/protobuf/protobuf-2.5.0.jar third_party/jsr305/jsr-305.jar" +BUILDJAR_LIBRARIES="third_party/error_prone/error_prone_core-2.0.2.jar third_party/guava/guava-18.0.jar third_party/protobuf/protobuf-2.5.0.jar third_party/jsr305/jsr-305.jar" MSYS_DLLS="" PATHSEP=":" diff --git a/src/java_tools/buildjar/BUILD b/src/java_tools/buildjar/BUILD index 98c2afef24..f8cfd4a625 100644 --- a/src/java_tools/buildjar/BUILD +++ b/src/java_tools/buildjar/BUILD @@ -6,6 +6,7 @@ java_binary( main_class = "com.google.devtools.build.buildjar.BazelJavaBuilder", deps = [ "//src/main/protobuf:proto_deps", + "//third_party:error_prone", "//third_party:guava", "//third_party:jsr305", "//third_party:protobuf", 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 0441e91fcb..4531098a77 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 @@ -18,7 +18,8 @@ import com.google.common.collect.ImmutableList; import com.google.devtools.build.buildjar.javac.JavacOptions; import com.google.devtools.build.buildjar.javac.plugins.BlazeJavaCompilerPlugin; import com.google.devtools.build.buildjar.javac.plugins.dependency.DependencyModule; -import com.google.devtools.build.buildjar.javac.plugins.dependency.FileManagerInitializationPlugin; +import com.google.devtools.build.buildjar.javac.plugins.errorprone.ErrorProneOptionsPlugin; +import com.google.devtools.build.buildjar.javac.plugins.filemanager.FileManagerInitializationPlugin; import java.io.IOException; import java.util.Arrays; @@ -36,7 +37,9 @@ public abstract class BazelJavaBuilder { public static void main(String[] args) { try { ImmutableList<BlazeJavaCompilerPlugin> plugins = - ImmutableList.<BlazeJavaCompilerPlugin>of(new FileManagerInitializationPlugin()); + ImmutableList.<BlazeJavaCompilerPlugin>of( + new FileManagerInitializationPlugin(), + new ErrorProneOptionsPlugin()); JavaLibraryBuildRequest build = new JavaLibraryBuildRequest( Arrays.asList(args), plugins, new DependencyModule.Builder()); diff --git a/src/java_tools/buildjar/java/com/google/devtools/build/buildjar/javac/plugins/errorprone/ErrorProneOptionsPlugin.java b/src/java_tools/buildjar/java/com/google/devtools/build/buildjar/javac/plugins/errorprone/ErrorProneOptionsPlugin.java new file mode 100644 index 0000000000..2172cd9f49 --- /dev/null +++ b/src/java_tools/buildjar/java/com/google/devtools/build/buildjar/javac/plugins/errorprone/ErrorProneOptionsPlugin.java @@ -0,0 +1,64 @@ +// Copyright 2014 Google Inc. All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package com.google.devtools.build.buildjar.javac.plugins.errorprone; + +import com.google.devtools.build.buildjar.InvalidCommandLineException; +import com.google.devtools.build.buildjar.javac.plugins.BlazeJavaCompilerPlugin; +import com.google.errorprone.ErrorProneOptions; +import com.google.errorprone.InvalidCommandLineOptionException; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +/** + * Process (and discard) Error Prone specific options. + * + * <p>This is a stop-gap until full Error Prone support is added to Bazel. + */ +public class ErrorProneOptionsPlugin extends BlazeJavaCompilerPlugin { + + @Override + public List<String> processArgs(List<String> args) throws InvalidCommandLineException { + // TODO(cushon): add -XepIgnoreUnknownCheckNames once Error Prone is supported + return processEpOptions(processExtraChecksOption(args)); + } + + private List<String> processEpOptions(List<String> args) throws InvalidCommandLineException { + ErrorProneOptions epOptions; + try { + epOptions = ErrorProneOptions.processArgs(args); + } catch (InvalidCommandLineOptionException e) { + throw new InvalidCommandLineException(e.getMessage()); + } + return Arrays.asList(epOptions.getRemainingArgs()); + } + + private List<String> processExtraChecksOption(List<String> args) { + List<String> arguments = new ArrayList<>(); + for (String arg : args) { + switch (arg) { + case "-extra_checks": + case "-extra_checks:on": + break; + case "-extra_checks:off": + break; + default: + arguments.add(arg); + } + } + return arguments; + } +} diff --git a/src/java_tools/buildjar/java/com/google/devtools/build/buildjar/javac/plugins/dependency/FileManagerInitializationPlugin.java b/src/java_tools/buildjar/java/com/google/devtools/build/buildjar/javac/plugins/filemanager/FileManagerInitializationPlugin.java index fe76c5d84a..532bada25e 100644 --- a/src/java_tools/buildjar/java/com/google/devtools/build/buildjar/javac/plugins/dependency/FileManagerInitializationPlugin.java +++ b/src/java_tools/buildjar/java/com/google/devtools/build/buildjar/javac/plugins/filemanager/FileManagerInitializationPlugin.java @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -package com.google.devtools.build.buildjar.javac.plugins.dependency; +package com.google.devtools.build.buildjar.javac.plugins.filemanager; import com.google.devtools.build.buildjar.javac.plugins.BlazeJavaCompilerPlugin; diff --git a/third_party/BUILD b/third_party/BUILD index b1589692a5..de753d31e5 100644 --- a/third_party/BUILD +++ b/third_party/BUILD @@ -151,6 +151,11 @@ java_import( ) java_import( + name = "error_prone", + jars = ["error_prone/error_prone_core-2.0.2.jar"], +) + +java_import( name = "guava", jars = ["guava/guava-18.0.jar"], ) diff --git a/third_party/README.md b/third_party/README.md index afd6ca5106..35c80a1ea9 100644 --- a/third_party/README.md +++ b/third_party/README.md @@ -60,6 +60,11 @@ a minimal set of extra dependencies. * [auto_value](https://github.com/google/auto/tree/master/value) (version 1.0) * License: Apache License 2.0 +[Error Prone](github.com/google/error-prone) +------------- + +* Version: 2.0.2 +* License: Apache License 2.0 [Buck (iOS support)](http://facebook.github.io/buck/) -------------------- diff --git a/third_party/error_prone/error_prone_core-2.0.2.jar b/third_party/error_prone/error_prone_core-2.0.2.jar Binary files differnew file mode 100644 index 0000000000..cf649d8f6d --- /dev/null +++ b/third_party/error_prone/error_prone_core-2.0.2.jar |