Skip to content

Commit

Permalink
Run error-prone as javac plugin on Java 9 or newer
Browse files Browse the repository at this point in the history
This is the recommended way in the future, but not supported on Java 8,
cf. google/error-prone#860

Also move all the special error-prone options for this project
to build.xml to allow reuse of build-compile.xml across projects.
  • Loading branch information
PhilippWendler committed Jun 12, 2018
1 parent 1bbca6f commit 5ab2b1a
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 15 deletions.
26 changes: 26 additions & 0 deletions build.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,32 @@
<property name="ivy.pom.groupId" value="org.sosy-lab"/>
<property name="ivy.pom.artifactId" value="common"/>

<!-- We activate even the experimental error-prone checks, with a few exceptions:
- StaticOrDefaultInterfaceMethod: only relevant for Android
- FieldCanBeFinal: not possible for our @Option fields
- TestExceptionChecker: TODO
- ParameterPackage: buggy
- ConstructorInvokesOverridable: buggy
- ConstructorLeaksThis: buggy
- FieldMissingNullable: buggy
- ReturnMissingNullable: buggy
-->
<property name="errorprone.options" value="
-XepPatchLocation:${basedir}
-XepPatchChecks:
-XepAllDisabledChecksAsWarnings
-Xep:StaticOrDefaultInterfaceMethod:OFF
-Xep:FieldCanBeFinal:OFF
-Xep:TestExceptionChecker:OFF
-Xep:ParameterPackage:OFF
-Xep:ConstructorInvokesOverridable:OFF
-Xep:ConstructorLeaksThis:OFF
-Xep:FieldMissingNullable:OFF
-Xep:ReturnMissingNullable:OFF
-Xep:InconsistentOverloads:OFF
-Xep:UngroupedOverloads:OFF
"/>

<import file="build/build-version.xml"/>
<import file="build/build-ivy.xml"/>
<import file="build/build-compile.xml"/>
Expand Down
31 changes: 16 additions & 15 deletions build/build-compile.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,25 @@
<property name="source.generated.dir" value=".apt-generated"/>
<property name="class.format" value="1.8"/>
<property name="class.dir" value="bin"/>
<property name="errorprone.options" value=""/>

<path id="errorprone">
<pathelement location="${ivy.lib.dir}/build/error_prone_ant.jar"/>
</path>

<!-- Needs to include all annotation processors and error-prone -->
<path id="processorpath">
<fileset dir="${ivy.lib.dir}" includes="build/*.jar"/>
</path>

<property name="errorprone" value="com.google.errorprone.ErrorProneAntCompilerAdapter"/>
<condition property="java8">
<matches string="${ant.java.version}" pattern="8"/>
</condition>
<condition property="java.compiler" value="${errorprone}" else="modern">
<isset property="java8"/>
</condition>

<!-- We use error-prone as the compiler, cf. http://errorprone.info/ -->
<target name="build-project" unless="skipBuild" depends="build-dependencies">
<depend srcdir="${source.dir}" destdir="${class.dir}"/>
Expand All @@ -30,27 +41,17 @@
source="${source.format}"
target="${class.format}"
includeAntRuntime="false"
compiler="com.google.errorprone.ErrorProneAntCompilerAdapter"
compiler="${java.compiler}"
encoding="UTF-8">
<src path="${source.dir}"/>
<classpath refid="classpath"/>
<compilerarg value="-Xlint"/>
<compilerarg value="-Xlint:-processing"/>
<compilerarg value="-Xlint:-options"/> <!-- suppress warning about bootclasspath on newer JDK -->
<compilerarg value="-Werror"/>
<compilerarg value="-XepAllDisabledChecksAsWarnings"/>
<compilerarg value="-Xep:InconsistentOverloads:OFF"/>
<compilerarg value="-Xep:UngroupedOverloads:OFF"/>
<compilerarg value="-Xep:StaticOrDefaultInterfaceMethod:OFF"/> <!-- only relevant for Android -->
<compilerarg value="-Xep:TestExceptionChecker:OFF"/> <!-- TODO -->
<compilerarg value="-Xep:ParameterPackage:OFF"/> <!-- buggy -->
<compilerarg value="-Xep:ConstructorInvokesOverridable:OFF"/> <!-- buggy -->
<compilerarg value="-Xep:ConstructorLeaksThis:OFF"/> <!-- buggy -->
<compilerarg value="-Xep:FieldMissingNullable:OFF"/> <!-- buggy -->
<compilerarg value="-Xep:ReturnMissingNullable:OFF"/> <!-- buggy -->
<compilerarg value="-Xep:FieldCanBeFinal:OFF"/> <!-- not possible for our @Option fields -->
<compilerarg value="-XepPatchLocation:${basedir}"/>
<compilerarg value="-XepPatchChecks:"/>
<compilerarg value="-XepDisableWarningsInGeneratedCode"/>
<compilerarg compiler="${errorprone}" line="-XepDisableWarningsInGeneratedCode ${errorprone.options}"/>
<compilerarg compiler="modern" value="-XDcompilePolicy=simple"/> <!-- necessary for error-prone -->
<compilerarg compiler="modern" value="-Xplugin:ErrorProne -XepDisableWarningsInGeneratedCode ${errorprone.options}"/>
<compilerarg value="-s"/><compilerarg value="${source.generated.dir}"/>
<compilerarg value="-processorpath"/><compilerarg pathref="processorpath"/>
<compilerclasspath refid="errorprone"/>
Expand Down

0 comments on commit 5ab2b1a

Please sign in to comment.