Package rife.bld.extension
Class CheckstyleOperation
java.lang.Object
rife.bld.operations.AbstractOperation<T>
rife.bld.operations.AbstractProcessOperation<CheckstyleOperation>
rife.bld.extension.CheckstyleOperation
Static code analysis operation using Checkstyle.
Provides a fluent API to configure and execute Checkstyle against Java source files.
Example usage:
new CheckstyleOperation()
.fromProject(project)
.configurationFile("config/checkstyle.xml")
.format(OutputFormat.XML)
.outputPath("build/checkstyle.xml")
.execute();
- Since:
- 1.0
- Author:
- Erik C. Thauvin
-
Field Summary
Fields inherited from class rife.bld.operations.AbstractProcessOperation
classpath_, DEFAULT_JAVA_TOOL, environment_, errorProcessor_, errorProcessorThread_, javaOptions_, javaTool_, mainClass_, module_, modulePath_, outputProcessor_, outputProcessorThread_, process_, successful_, workDirectory_ -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbranchMatchingXpath(String xPathQuery) Shows Abstract Syntax Tree (AST) branches that match the given XPath query.configurationFile(File file) Specifies the location of the Checkstyle configuration file.configurationFile(String file) Specifies the location of the Checkstyle configuration file.configurationFile(Path file) Specifies the location of the Checkstyle configuration file.debug(boolean isDebug) Enables or disables debug logging for the Checkstyle utility.exclude()Retrieves the list of files and directories excluded from analysis.Specifies directories or files to exclude from Checkstyle analysis.Specifies directories or files to exclude from Checkstyle analysis.Specifies directories or files to exclude from Checkstyle analysis.exclude(Collection<File> paths) Specifies directories or files to exclude from Checkstyle analysis.excludePaths(Collection<Path> paths) Specifies directories or files to exclude from Checkstyle analysis.Retrieves the list of regex patterns excluded from analysis.excludeRegex(String... patterns) Specifies directory or file patterns to exclude from Checkstyle analysis.excludeRegex(Collection<String> patterns) Specifies directory or file patterns to exclude from Checkstyle analysis.excludeStrings(Collection<String> paths) Specifies directories or files to exclude from Checkstyle analysis.Part of theAbstractProcessOperation.execute()operation, constructs the command list to use for building the process.executeIgnoredModules(boolean isAllowIgnoreModules) Allows ignored modules to be executed.format(OutputFormat format) Specifies the output format for Checkstyle results.fromProject(BaseProject project) Configures the operation from aBaseProject.generateChecksAndFileSuppression(boolean generateChecksAndFileSuppression) Generates suppression XML files for checks and files.generateXpathSuppression(boolean xPathSuppression) Generates XPath suppression XML.javadocTree(boolean isTree) Prints the Javadoc parse tree.options()Returns the mutable map of command line options.outputPath(File file) Sets the output file for Checkstyle results.outputPath(String file) Sets the output file for Checkstyle results.outputPath(Path file) Sets the output file for Checkstyle results.propertiesFile(File file) Sets the properties file for Checkstyle.propertiesFile(String file) Sets the properties file for Checkstyle.propertiesFile(Path file) Sets the properties file for Checkstyle.Returns the set of source directories to analyze.Specifies source directories to analyze.Specifies source directories to analyze.Specifies source directories to analyze.sourceDir(Collection<File> dirs) Specifies source directories to analyze.sourceDirPaths(Collection<Path> dirs) Specifies source directories to analyze.sourceDirStrings(Collection<String> dirs) Specifies source directories to analyze.suppressionLineColumnNumber(int line, int column) Prints XPath suppressions for a specific line and column.tabWidth(int length) Sets the tab width for column reporting.tree(boolean isTree) Prints the Abstract Syntax Tree without comments.treeWithComments(boolean isTree) Prints the Abstract Syntax Tree with comment nodes included.treeWithJavadoc(boolean isTree) Prints the Abstract Syntax Tree with Javadoc nodes included.Methods inherited from class rife.bld.operations.AbstractProcessOperation
classpath, classpath, classpath, classpath, classpath, environment, environment, environment, errorProcessor, errorProcessor, execute, executeStartProcess, javaOptions, javaOptions, javaTool, javaTool, mainClass, mainClass, module, module, modulePath, modulePath, modulePath, modulePath, modulePath, outputProcessor, outputProcessor, process, workDirectory, workDirectoryMethods inherited from class rife.bld.operations.AbstractOperation
executeOnce, executeOnce, silent, silent
-
Constructor Details
-
CheckstyleOperation
public CheckstyleOperation()
-
-
Method Details
-
executeConstructProcessCommandList
Part of theAbstractProcessOperation.execute()operation, constructs the command list to use for building the process.- Specified by:
executeConstructProcessCommandListin classAbstractProcessOperation<CheckstyleOperation>- Returns:
- the list of command arguments
- Throws:
NullPointerException- iffromProject(BaseProject)was not called
-
fromProject
Configures the operation from aBaseProject.Sets the
source directoriesto the project'smainandtestJava source directories, if not already set.- Specified by:
fromProjectin classAbstractProcessOperation<CheckstyleOperation>- Parameters:
project- the project to configure from, must not benull- Returns:
- this operation instance
- Throws:
NullPointerException- ifprojectisnull
-
branchMatchingXpath
Shows Abstract Syntax Tree (AST) branches that match the given XPath query. Corresponds to the-boption.- Parameters:
xPathQuery- the XPath query, must not benullor empty- Returns:
- this operation instance
- Throws:
IllegalArgumentException- ifxPathQueryisnullor empty
-
configurationFile
Specifies the location of the Checkstyle configuration file.The location can be a filesystem path or a name passed to
ClassLoader.getResource(). Corresponds to the-coption.- Parameters:
file- the configuration file path, must not benull- Returns:
- this operation instance
- Throws:
NullPointerException- iffileisnull
-
configurationFile
Specifies the location of the Checkstyle configuration file. Corresponds to the-coption.- Parameters:
file- the configuration file, must not benull- Returns:
- this operation instance
- Throws:
NullPointerException- iffileisnull
-
configurationFile
Specifies the location of the Checkstyle configuration file. Corresponds to the-coption.- Parameters:
file- the configuration file path, must not benull- Returns:
- this operation instance
- Throws:
NullPointerException- iffileisnull
-
debug
Enables or disables debug logging for the Checkstyle utility. Corresponds to the-doption.- Parameters:
isDebug-trueto enable debug logging,falseto disable- Returns:
- this operation instance
-
exclude
Retrieves the list of files and directories excluded from analysis.- Returns:
- a mutable list of excluded files
- Since:
- 1.1.0
-
exclude
Specifies directories or files to exclude from Checkstyle analysis. Corresponds to the-eoption. Replaces any previously set excludes.- Parameters:
paths- the paths to exclude, must not containnullor empty values- Returns:
- this operation instance
- Throws:
IllegalArgumentException- ifpathsisnullor containsnullor empty values
-
exclude
Specifies directories or files to exclude from Checkstyle analysis. Corresponds to the-eoption. Replaces any previously set excludes.- Parameters:
paths- the files to exclude, must not containnull- Returns:
- this operation instance
- Throws:
IllegalArgumentException- ifpathsisnullor containsnull
-
exclude
Specifies directories or files to exclude from Checkstyle analysis. Corresponds to the-eoption. Replaces any previously set excludes.- Parameters:
paths- the paths to exclude, must not containnull- Returns:
- this operation instance
- Throws:
IllegalArgumentException- ifpathsisnullor containsnull
-
exclude
Specifies directories or files to exclude from Checkstyle analysis. Corresponds to the-eoption. Replaces any previously set excludes.- Parameters:
paths- the collection of files to exclude, must not benullor containnull- Returns:
- this operation instance
- Throws:
IllegalArgumentException- ifpathsisnullor containsnull
-
excludePaths
Specifies directories or files to exclude from Checkstyle analysis. Corresponds to the-eoption. Replaces any previously set excludes.- Parameters:
paths- the collection of paths to exclude, must not benullor containnull- Returns:
- this operation instance
- Throws:
IllegalArgumentException- ifpathsisnullor containsnull
-
excludeRegex
Specifies directory or file patterns to exclude from Checkstyle analysis. Corresponds to the-xoption. Replaces any previously set exclude patterns.- Parameters:
patterns- the regex patterns to exclude, must not containnullor empty values- Returns:
- this operation instance
- Throws:
IllegalArgumentException- ifpatternsisnullor containsnullor empty values
-
excludeRegex
Specifies directory or file patterns to exclude from Checkstyle analysis. Corresponds to the-xoption. Replaces any previously set exclude patterns.- Parameters:
patterns- the collection of regex patterns to exclude, must not benullor containnullor empty values- Returns:
- this operation instance
- Throws:
IllegalArgumentException- ifpatternsisnullor containsnullor empty values
-
excludeRegex
Retrieves the list of regex patterns excluded from analysis.- Returns:
- a mutable list of exclude regex patterns
-
excludeStrings
Specifies directories or files to exclude from Checkstyle analysis. Corresponds to the-eoption. Replaces any previously set excludes.- Parameters:
paths- the collection of path strings to exclude, must not benullor containnullor empty values- Returns:
- this operation instance
- Throws:
IllegalArgumentException- ifpathsisnullor containsnullor empty values
-
executeIgnoredModules
Allows ignored modules to be executed. Corresponds to the-Eoption.- Parameters:
isAllowIgnoreModules-trueto execute ignored modules,falseto skip them- Returns:
- this operation instance
-
format
Specifies the output format for Checkstyle results. Corresponds to the-foption.- Parameters:
format- the output format, must not benull- Returns:
- this operation instance
- Throws:
NullPointerException- ifformatisnull
-
generateChecksAndFileSuppression
@NonNull public CheckstyleOperation generateChecksAndFileSuppression(boolean generateChecksAndFileSuppression) Generates suppression XML files for checks and files. Corresponds to the-Goption.- Parameters:
generateChecksAndFileSuppression-trueto generate suppression XML,falseotherwise- Returns:
- this operation instance
-
generateXpathSuppression
Generates XPath suppression XML. Corresponds to the-goption.- Parameters:
xPathSuppression-trueto generate XPath suppression XML,falseotherwise- Returns:
- this operation instance
-
javadocTree
Prints the Javadoc parse tree. Corresponds to the-joption.- Parameters:
isTree-trueto print the Javadoc tree,falseotherwise- Returns:
- this operation instance
-
options
Returns the mutable map of command line options.Modifying this map bypasses validation. Use with care. Intended for advanced configuration and passing options not exposed by the fluent API.
- Returns:
- the mutable options map
-
outputPath
Sets the output file for Checkstyle results. Corresponds to the-ooption.- Parameters:
file- the output file path, must not benull- Returns:
- this operation instance
- Throws:
NullPointerException- iffileisnull
-
outputPath
Sets the output file for Checkstyle results. Corresponds to the-ooption.- Parameters:
file- the output file, must not benull- Returns:
- this operation instance
- Throws:
NullPointerException- iffileisnull
-
outputPath
Sets the output file for Checkstyle results. Corresponds to the-ooption.- Parameters:
file- the output file path, must not benull- Returns:
- this operation instance
- Throws:
NullPointerException- iffileisnull
-
propertiesFile
Sets the properties file for Checkstyle. Corresponds to the-poption.- Parameters:
file- the properties file path, must not benull- Returns:
- this operation instance
- Throws:
NullPointerException- iffileisnull
-
propertiesFile
Sets the properties file for Checkstyle. Corresponds to the-poption.- Parameters:
file- the properties file, must not benull- Returns:
- this operation instance
- Throws:
NullPointerException- iffileisnull
-
propertiesFile
Sets the properties file for Checkstyle. Corresponds to the-poption.- Parameters:
file- the properties file path, must not benull- Returns:
- this operation instance
- Throws:
NullPointerException- iffileisnull
-
sourceDir
Specifies source directories to analyze. Replaces any previously set source directories.- Parameters:
dirs- the directory paths, must not containnullor empty values- Returns:
- this operation instance
- Throws:
IllegalArgumentException- ifdirsisnullor containsnullor empty values
-
sourceDir
Specifies source directories to analyze. Replaces any previously set source directories.- Parameters:
dirs- the directories, must not containnull- Returns:
- this operation instance
- Throws:
IllegalArgumentException- ifdirsisnullor containsnull
-
sourceDir
Specifies source directories to analyze. Replaces any previously set source directories.- Parameters:
dirs- the directory paths, must not containnull- Returns:
- this operation instance
- Throws:
IllegalArgumentException- ifdirsisnullor containsnull
-
sourceDir
Specifies source directories to analyze. Replaces any previously set source directories.- Parameters:
dirs- the collection of directories, must not benullor containnull- Returns:
- this operation instance
- Throws:
IllegalArgumentException- ifdirsisnullor containsnull
-
sourceDir
Returns the set of source directories to analyze.- Returns:
- a mutable set of source directories
-
sourceDirPaths
Specifies source directories to analyze. Replaces any previously set source directories.- Parameters:
dirs- the collection of directory paths, must not benullor containnull- Returns:
- this operation instance
- Throws:
IllegalArgumentException- ifdirsisnullor containsnull
-
sourceDirStrings
Specifies source directories to analyze. Replaces any previously set source directories.- Parameters:
dirs- the collection of directory path strings, must not benullor containnullor empty values- Returns:
- this operation instance
- Throws:
IllegalArgumentException- ifdirsisnullor containsnullor empty values
-
suppressionLineColumnNumber
Prints XPath suppressions for a specific line and column. Corresponds to the-soption.- Parameters:
line- the line number, must not be negativecolumn- the column number, must not be negative- Returns:
- this operation instance
- Throws:
IllegalArgumentException- iflineorcolumnis negative
-
tabWidth
Sets the tab width for column reporting.A value of
0disables tab expansion, causing tabs to be counted as a single character. Corresponds to the-woption. Default is 8 if not set.- Parameters:
length- the tab width, must not be negative- Returns:
- this operation instance
- Throws:
IllegalArgumentException- iflengthis negative
-
tree
Prints the Abstract Syntax Tree without comments. Corresponds to the-toption.- Parameters:
isTree-trueto print the AST,falseotherwise- Returns:
- this operation instance
-
treeWithComments
Prints the Abstract Syntax Tree with comment nodes included. Corresponds to the-Toption.- Parameters:
isTree-trueto print the AST with comments,falseotherwise- Returns:
- this operation instance
-
treeWithJavadoc
Prints the Abstract Syntax Tree with Javadoc nodes included. Corresponds to the-Joption.- Parameters:
isTree-trueto print the AST with Javadoc,falseotherwise- Returns:
- this operation instance
-