From 7d89f0a053f32e0ba6d0384cf73a70ce99190821 Mon Sep 17 00:00:00 2001 From: David Ostrovsky Date: Sun, 26 Aug 2018 16:14:32 +0200 Subject: [PATCH] Bazel: Provide toolchain with activated error prone warnings On recent bazel versions it's trivial to apply package specific checks. Provide custom java toolchain with all error prone warnings activated. The list of all error prone warnings was borrowed from here: [1]. Test Plan: $ bazel build --java_toolchain //tools:error_prone_warnings_toolchain \ //... [1] https://github.com/bazelbuild/BUILD_file_generator/blob/master/tools/bazel_defs/java.bzl Change-Id: I207a368555bfb7ddab8d782d46d563ce779a6211 Signed-off-by: David Ostrovsky Signed-off-by: David Pursehouse --- tools/BUILD | 107 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 107 insertions(+) diff --git a/tools/BUILD b/tools/BUILD index e69de29bb..84da3a8df 100644 --- a/tools/BUILD +++ b/tools/BUILD @@ -0,0 +1,107 @@ +load( + "@bazel_tools//tools/jdk:default_java_toolchain.bzl", + "JDK9_JVM_OPTS", + "default_java_toolchain", +) + +default_java_toolchain( + name = "error_prone_warnings_toolchain", + bootclasspath = ["@bazel_tools//tools/jdk:platformclasspath9.jar"], + jvm_opts = JDK9_JVM_OPTS, + package_configuration = [ + ":error_prone", + ], + visibility = ["//visibility:public"], +) + +# This EP warnings list borrowed from here: +# https://github.com/bazelbuild/BUILD_file_generator/blob/master/tools/bazel_defs/java.bzl +java_package_configuration( + name = "error_prone", + javacopts = [ + "-XepDisableWarningsInGeneratedCode", + "-Xep:MissingCasesInEnumSwitch:ERROR", + "-Xep:ReferenceEquality:WARN", + "-Xep:StringEquality:WARN", + "-Xep:WildcardImport:WARN", + "-Xep:AmbiguousMethodReference:WARN", + "-Xep:BadAnnotationImplementation:WARN", + "-Xep:BadComparable:WARN", + "-Xep:BoxedPrimitiveConstructor:ERROR", + "-Xep:CannotMockFinalClass:WARN", + "-Xep:ClassCanBeStatic:WARN", + "-Xep:ClassNewInstance:WARN", + "-Xep:DefaultCharset:WARN", + "-Xep:DoubleCheckedLocking:WARN", + "-Xep:ElementsCountedInLoop:WARN", + "-Xep:EqualsHashCode:WARN", + "-Xep:EqualsIncompatibleType:WARN", + "-Xep:ExpectedExceptionChecker:WARN", + "-Xep:Finally:WARN", + "-Xep:FloatingPointLiteralPrecision:WARN", + "-Xep:FragmentInjection:WARN", + "-Xep:FragmentNotInstantiable:WARN", + "-Xep:FunctionalInterfaceClash:WARN", + "-Xep:FutureReturnValueIgnored:WARN", + "-Xep:GetClassOnEnum:WARN", + "-Xep:ImmutableAnnotationChecker:WARN", + "-Xep:ImmutableEnumChecker:WARN", + "-Xep:IncompatibleModifiers:WARN", + "-Xep:InjectOnConstructorOfAbstractClass:WARN", + "-Xep:InputStreamSlowMultibyteRead:WARN", + "-Xep:IterableAndIterator:WARN", + "-Xep:JUnit3FloatingPointComparisonWithoutDelta:WARN", + "-Xep:JUnitAmbiguousTestClass:WARN", + "-Xep:LiteralClassName:WARN", + "-Xep:MissingFail:WARN", + "-Xep:MissingOverride:WARN", + "-Xep:MutableConstantField:WARN", + "-Xep:NarrowingCompoundAssignment:WARN", + "-Xep:NonAtomicVolatileUpdate:WARN", + "-Xep:NonOverridingEquals:WARN", + "-Xep:NullableConstructor:WARN", + "-Xep:NullablePrimitive:WARN", + "-Xep:NullableVoid:WARN", + "-Xep:OperatorPrecedence:WARN", + "-Xep:OverridesGuiceInjectableMethod:WARN", + "-Xep:PreconditionsInvalidPlaceholder:WARN", + "-Xep:ProtoFieldPreconditionsCheckNotNull:WARN", + "-Xep:ProtocolBufferOrdinal:WARN", + "-Xep:RequiredModifiers:WARN", + "-Xep:ShortCircuitBoolean:WARN", + "-Xep:SimpleDateFormatConstant:WARN", + "-Xep:StaticGuardedByInstance:WARN", + "-Xep:SynchronizeOnNonFinalField:WARN", + "-Xep:TruthConstantAsserts:WARN", + "-Xep:TypeParameterShadowing:WARN", + "-Xep:TypeParameterUnusedInFormals:WARN", + "-Xep:URLEqualsHashCode:WARN", + "-Xep:UnsynchronizedOverridesSynchronized:WARN", + "-Xep:WaitNotInLoop:WARN", + ], + packages = ["error_prone_packages"], +) + +package_group( + name = "error_prone_packages", + packages = [ + "//org.eclipse.jgit/...", + "//org.eclipse.jgit.ant/...", + "//org.eclipse.jgit.ant.test/...", + "//org.eclipse.jgit.archive/...", + "//org.eclipse.jgit.http.apache/...", + "//org.eclipse.jgit.http.server/...", + "//org.eclipse.jgit.http.test/...", + "//org.eclipse.jgit.junit/...", + "//org.eclipse.jgit.junit.http/...", + "//org.eclipse.jgit.lfs/...", + "//org.eclipse.jgit.lfs.server/...", + "//org.eclipse.jgit.lfs.server.test/...", + "//org.eclipse.jgit.lfs.test/...", + "//org.eclipse.jgit.packaging/...", + "//org.eclipse.jgit.pgm/...", + "//org.eclipse.jgit.pgm.test/...", + "//org.eclipse.jgit.test/...", + "//org.eclipse.jgit.ui/...", + ], +)