Class ErrorProneOperation
All javac diagnostics are reported, not just those of a failed compilation.
The Error Prone version defaults to ERROR_PRONE_VERSION on JDK 21+ and 2.42.0 on JDK 17-20.
Required JVM options in lib/bld/bld-wrapper.properties:
bld.javaOptions=--add-exports=jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED\ \ --add-exports=jdk.compiler/com.sun.tools.javac.file=ALL-UNNAMED\ \ --add-exports=jdk.compiler/com.sun.tools.javac.main=ALL-UNNAMED\ \ --add-exports=jdk.compiler/com.sun.tools.javac.model=ALL-UNNAMED\ \ --add-exports=jdk.compiler/com.sun.tools.javac.parser=ALL-UNNAMED\ \ --add-exports=jdk.compiler/com.sun.tools.javac.processing=ALL-UNNAMED\ \ --add-exports=jdk.compiler/com.sun.tools.javac.tree=ALL-UNNAMED\ \ --add-exports=jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED\ \ --add-opens=jdk.compiler/com.sun.tools.javac.code=ALL-UNNAMED\ \ --add-opens=jdk.compiler/com.sun.tools.javac.comp=ALL-UNNAMED
- Since:
- 1.0
- Author:
- Erik C. Thauvin
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionallDisabledChecksAsWarnings(boolean allDisabledChecksAsWarnings) Reports all disabled-by-default checks as warnings (-XepAllDisabledChecksAsWarnings).allErrorsAsWarnings(boolean allErrorsAsWarnings) Reports all Error Prone errors as warnings (-XepAllErrorsAsWarnings).allSuggestionsAsWarnings(boolean allSuggestionsAsWarnings) Reports all suggestion-level findings as warnings (-XepAllSuggestionsAsWarnings).compileOptions(Consumer<JavacOptions> customizer) Configures theJavacOptionsused for the compilation.disableAllChecks(boolean disableAllChecks) Disables all checks (-XepDisableAllChecks).disableAllWarnings(boolean disableAllWarnings) Disables all warning-level checks (-XepDisableAllWarnings).disableCheck(String... names) Disables Error Prone checks (-Xep:Check:OFF).disableCheck(Collection<String> names) Disables Error Prone checks (-Xep:Check:OFF).disableWarningsInGeneratedCode(boolean disableWarningsInGeneratedCode) Disables warnings in classes annotated with@Generated(-XepDisableWarningsInGeneratedCode).enableCheck(String... names) Enables Error Prone checks at the severity from their own definition (-Xep:Check).enableCheck(Collection<String> names) Enables Error Prone checks at the severity from their own definition (-Xep:Check).errorCheck(String... names) Sets Error Prone checks to report at error severity (-Xep:Check:ERROR).errorCheck(Collection<String> names) Sets Error Prone checks to report at error severity (-Xep:Check:ERROR).excludedPath(String... regexes) Excludes source paths from analysis (-XepExcludedPaths:regex).excludedPath(Collection<String> regexes) Excludes source paths from analysis (-XepExcludedPaths:regex).excludedPath(Pattern... patterns) Excludes source paths from analysis (-XepExcludedPaths:regex).voidexecute()Compiles the project's main and test sources.Adds raw Error Prone flags.fromProject(BaseProject project) Configures the operation from a project.ignoreUnknownCheckNames(boolean ignoreUnknownCheckNames) Allows unknown check names instead of failing (-XepIgnoreUnknownCheckNames).Sets a check option (-XepOpt:name).Sets a check option (-XepOpt:name=value).patchChecks(String... checks) Sets the checks whose suggested fixes are written as a patch (-XepPatchChecks:).patchChecks(Collection<String> checks) Sets the checks whose suggested fixes are written as a patch (-XepPatchChecks:).patchLocation(String location) Sets where patches are written (-XepPatchLocation:).repositories(Collection<Repository> repositories) Sets the repositories to download Error Prone from, replacing the current list.repositories(Repository... repositories) Sets the repositories to download Error Prone from, replacing the current list.version()Returns the Error Prone version.Sets the Error Prone version.Sets the Error Prone version.Sets Error Prone checks to report at warning severity (-Xep:Check:WARN).warnCheck(Collection<String> names) Sets Error Prone checks to report at warning severity (-Xep:Check:WARN).Methods inherited from class rife.bld.operations.AbstractOperation
executeOnce, executeOnce, silent, silent, verbose, verbose
-
Field Details
-
ERROR_PRONE_VERSION
The Error Prone version used on JDK 21 and newer.Currently:
2.52.0 -
LAST_JDK17_VERSION
The Error Prone version used for JDK 17-20.Last:
2.42.0
-
-
Constructor Details
-
ErrorProneOperation
public ErrorProneOperation()
-
-
Method Details
-
execute
Compiles the project's main and test sources.- Specified by:
executein classAbstractOperation<ErrorProneOperation>- Throws:
NullPointerException- if no project was setIllegalStateException- if the JDK is unsupported, the JVM lacks required--add-exports/--add-opens, or the Error Prone jars can't be downloadedException- if compilation fails
-
allDisabledChecksAsWarnings
Reports all disabled-by-default checks as warnings (-XepAllDisabledChecksAsWarnings).- Parameters:
allDisabledChecksAsWarnings-trueto enable- Returns:
- this operation
-
allErrorsAsWarnings
Reports all Error Prone errors as warnings (-XepAllErrorsAsWarnings).- Parameters:
allErrorsAsWarnings-trueto downgrade- Returns:
- this operation
-
allSuggestionsAsWarnings
Reports all suggestion-level findings as warnings (-XepAllSuggestionsAsWarnings).- Parameters:
allSuggestionsAsWarnings-trueto report- Returns:
- this operation
-
compileOptions
Configures theJavacOptionsused for the compilation.Customizers run before the Error Prone options, so the operation's own options win.
A customizer-supplied
--processor-pathis merged with the Error Prone processor path.Annotation processors that javac would otherwise discover on the classpath are no longer found because the operation always sets a processor path; add them with
o.processorPath(...)if needed.- Parameters:
customizer- the customizer- Returns:
- this operation
- Throws:
NullPointerException- ifcustomizerisnull
-
disableAllChecks
Disables all checks (-XepDisableAllChecks).Enable individual checks afterward with
errorCheck(String...).- Parameters:
disableAllChecks-trueto disable- Returns:
- this operation
-
disableAllWarnings
Disables all warning-level checks (-XepDisableAllWarnings).- Parameters:
disableAllWarnings-trueto disable- Returns:
- this operation
-
disableCheck
Disables Error Prone checks (-Xep:Check:OFF).Later calls for the same name win.
- Parameters:
names- the check names- Returns:
- this operation
- Throws:
NullPointerException- ifnamesisnullor containsnullIllegalArgumentException- ifnamesis empty, or any name is blank or contains whitespace or control characters- See Also:
-
disableCheck
Disables Error Prone checks (-Xep:Check:OFF).Later calls for the same name win.
- Parameters:
names- the check names- Returns:
- this operation
- Throws:
NullPointerException- ifnamesisnullor containsnullIllegalArgumentException- ifnamesis empty, or any name is blank or contains whitespace or control characters- See Also:
-
disableWarningsInGeneratedCode
Disables warnings in classes annotated with@Generated(-XepDisableWarningsInGeneratedCode).- Parameters:
disableWarningsInGeneratedCode-trueto disable- Returns:
- this operation
-
enableCheck
Enables Error Prone checks at the severity from their own definition (-Xep:Check).Later calls for the same name win.
- Parameters:
names- the check names- Returns:
- this operation
- Throws:
NullPointerException- ifnamesisnullor containsnullIllegalArgumentException- ifnamesis empty, or any name is blank or contains whitespace or control characters- See Also:
-
enableCheck
Enables Error Prone checks at the severity from their own definition (-Xep:Check).Later calls for the same name win.
- Parameters:
names- the check names- Returns:
- this operation
- Throws:
NullPointerException- ifnamesisnullor containsnullIllegalArgumentException- ifnamesis empty, or any name is blank or contains whitespace or control characters- See Also:
-
errorCheck
Sets Error Prone checks to report at error severity (-Xep:Check:ERROR).Later calls for the same name win.
- Parameters:
names- the check names- Returns:
- this operation
- Throws:
NullPointerException- ifnamesisnullor containsnullIllegalArgumentException- ifnamesis empty, or any name is blank or contains whitespace or control characters- See Also:
-
errorCheck
Sets Error Prone checks to report at error severity (-Xep:Check:ERROR).Later calls for the same name win.
- Parameters:
names- the check names- Returns:
- this operation
- Throws:
NullPointerException- ifnamesisnullor containsnullIllegalArgumentException- ifnamesis empty, or any name is blank or contains whitespace or control characters- See Also:
-
excludedPath
Excludes source paths from analysis (-XepExcludedPaths:regex).Values are joined with
|.The regex must not contain whitespace.
- Parameters:
regexes- the regexes- Returns:
- this operation
- Throws:
NullPointerException- ifregexesisnullor containsnullIllegalArgumentException- ifregexesis empty, or any regex is blank or contains whitespace or control characters- See Also:
-
excludedPath
Excludes source paths from analysis (-XepExcludedPaths:regex).Values are joined with
|.The regex must not contain whitespace.
- Parameters:
regexes- the regexes- Returns:
- this operation
- Throws:
NullPointerException- ifregexesisnullor containsnullIllegalArgumentException- ifregexesis empty, or any regex is blank or contains whitespace or control characters- See Also:
-
excludedPath
Excludes source paths from analysis (-XepExcludedPaths:regex).Values are joined with
|.Any pattern with non-zero
flagsis rejected. Note thatPattern.flags()only reports flags passed toPattern.compile(String, int); inline flags such as(?i)are not included and therefore pass through unrejected. Use aStringoverload for inline-flag semantics.- Parameters:
patterns- the patterns- Returns:
- this operation
- Throws:
NullPointerException- ifpatternsisnullor containsnullIllegalArgumentException- ifpatternsis empty, any element was compiled with explicit flags (non-zeroflags()), or any pattern string is blank or contains whitespace or control characters- See Also:
-
flag
Adds raw Error Prone flags.Emitted in call order with the per-check methods.
- Parameters:
flags- the flags- Returns:
- this operation
- Throws:
NullPointerException- ifflagsisnullor containsnullIllegalArgumentException- ifflagsis empty, or any flag is blank or contains whitespace or control characters
-
fromProject
Configures the operation from a project.Copies the project's
verbosesetting; a laterverbose(...)call overrides it.- Parameters:
project- the project- Returns:
- this operation
- Throws:
NullPointerException- ifprojectisnull
-
ignoreUnknownCheckNames
Allows unknown check names instead of failing (-XepIgnoreUnknownCheckNames).- Parameters:
ignoreUnknownCheckNames-trueto ignore- Returns:
- this operation
-
option
Sets a check option (-XepOpt:name).A bare name is equivalent to
=true.- Parameters:
name- the option name, optionally namespaced- Returns:
- this operation
- Throws:
NullPointerException- ifnameisnullIllegalArgumentException- ifnameis blank or contains whitespace or control characters
-
option
Sets a check option (-XepOpt:name=value).- Parameters:
name- the option name, optionally namespacedvalue- the option value- Returns:
- this operation
- Throws:
NullPointerException- ifnameorvalueisnullIllegalArgumentException- ifnameorvalueis blank or contains whitespace or control characters
-
patchChecks
Sets the checks whose suggested fixes are written as a patch (-XepPatchChecks:).Requires
patchLocation(String).- Parameters:
checks- the check names- Returns:
- this operation
- Throws:
NullPointerException- ifchecksisnullor containsnullIllegalArgumentException- ifchecksis empty, or any name is blank or contains whitespace or control characters- See Also:
-
patchChecks
Sets the checks whose suggested fixes are written as a patch (-XepPatchChecks:).Requires
patchLocation(String).- Parameters:
checks- the check names- Returns:
- this operation
- Throws:
NullPointerException- ifchecksisnullor containsnullIllegalArgumentException- ifchecksis empty, or any name is blank or contains whitespace or control characters- See Also:
-
patchLocation
Sets where patches are written (-XepPatchLocation:).- Parameters:
location-IN_PLACEor a directory- Returns:
- this operation
- Throws:
NullPointerException- iflocationisnullIllegalArgumentException- iflocationis blank or contains whitespace or control characters- See Also:
-
repositories
Sets the repositories to download Error Prone from, replacing the current list.Default is
Repository.MAVEN_CENTRAL.- Parameters:
repositories- the repositories- Returns:
- this operation
- Throws:
NullPointerException- ifrepositoriesisnullor containsnullIllegalArgumentException- ifrepositoriesis empty- See Also:
-
repositories
Sets the repositories to download Error Prone from, replacing the current list.Default is
Repository.MAVEN_CENTRAL.- Parameters:
repositories- the repositories- Returns:
- this operation
- Throws:
NullPointerException- ifrepositoriesisnullor containsnullIllegalArgumentException- ifrepositoriesis empty- See Also:
-
version
Sets the Error Prone version.Default is
ERROR_PRONE_VERSIONon JDK 21+ and2.42.0on JDK 17-20.- Parameters:
version- the version- Returns:
- this operation
- Throws:
NullPointerException- ifversionisnull- See Also:
-
version
Sets the Error Prone version.Default is
ERROR_PRONE_VERSIONon JDK 21+ and2.42.0on JDK 17-20.- Parameters:
version- the version string- Returns:
- this operation
- Throws:
NullPointerException- ifversionisnullIllegalArgumentException- ifversionis blank or not a valid version- See Also:
-
version
Returns the Error Prone version.- Returns:
- the version
- See Also:
-
warnCheck
Sets Error Prone checks to report at warning severity (-Xep:Check:WARN).Later calls for the same name win.
- Parameters:
names- the check names- Returns:
- this operation
- Throws:
NullPointerException- ifnamesisnullor containsnullIllegalArgumentException- ifnamesis empty, or any name is blank or contains whitespace or control characters- See Also:
-
warnCheck
Sets Error Prone checks to report at warning severity (-Xep:Check:WARN).Later calls for the same name win.
- Parameters:
names- the check names- Returns:
- this operation
- Throws:
NullPointerException- ifnamesisnullor containsnullIllegalArgumentException- ifnamesis empty, or any name is blank or contains whitespace or control characters- See Also:
-