Class CheckstyleOperation


@NullMarked public class CheckstyleOperation extends AbstractProcessOperation<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
  • Constructor Details

    • CheckstyleOperation

      public CheckstyleOperation()
  • Method Details

    • executeConstructProcessCommandList

      protected List<String> executeConstructProcessCommandList()
      Part of the AbstractProcessOperation.execute() operation, constructs the command list to use for building the process.
      Specified by:
      executeConstructProcessCommandList in class AbstractProcessOperation<CheckstyleOperation>
      Returns:
      the list of command arguments
      Throws:
      NullPointerException - if project_ is null
    • fromProject

      public CheckstyleOperation fromProject(BaseProject project)
      Configures the operation from a BaseProject.

      Sets the source directories to the project's main and test Java source directories, if not already set.

      Specified by:
      fromProject in class AbstractProcessOperation<CheckstyleOperation>
      Parameters:
      project - the project to configure from
      Returns:
      this operation instance
      Throws:
      NullPointerException - if project is null
    • branchMatchingXpath

      public CheckstyleOperation branchMatchingXpath(String xPathQuery)
      Shows Abstract Syntax Tree (AST) branches that match the given XPath query. Corresponds to the -b option.
      Parameters:
      xPathQuery - the XPath query or empty
      Returns:
      this operation instance
      Throws:
      NullPointerException - if xPathQuery is null
      IllegalArgumentException - if xPathQuery is blank
    • configurationFile

      public CheckstyleOperation configurationFile(String file)
      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 -c option.

      Parameters:
      file - the configuration file path
      Returns:
      this operation instance
      Throws:
      NullPointerException - if file is null
      IllegalArgumentException - if file is blank
    • configurationFile

      public CheckstyleOperation configurationFile(File file)
      Specifies the location of the Checkstyle configuration file. Corresponds to the -c option.
      Parameters:
      file - the configuration file
      Returns:
      this operation instance
      Throws:
      NullPointerException - if file is null
    • configurationFile

      public CheckstyleOperation configurationFile(Path file)
      Specifies the location of the Checkstyle configuration file. Corresponds to the -c option.
      Parameters:
      file - the configuration file path
      Returns:
      this operation instance
      Throws:
      NullPointerException - if file is null
    • debug

      public CheckstyleOperation debug(boolean isDebug)
      Enables or disables debug logging for the Checkstyle utility. Corresponds to the -d option.
      Parameters:
      isDebug - true to enable debug logging, false to disable
      Returns:
      this operation instance
    • exclude

      public List<File> exclude()
      Retrieves the list of files and directories excluded from analysis.
      Returns:
      a mutable list of excluded files
      Since:
      1.1.0
    • exclude

      public CheckstyleOperation exclude(String... paths)
      Specifies directories or files to exclude from Checkstyle analysis.
      Parameters:
      paths - the paths to exclude
      Returns:
      this operation instance
      Throws:
      NullPointerException - if paths is null or contains null elements
      IllegalArgumentException - if paths is blank, or contains blank elements
    • exclude

      public CheckstyleOperation exclude(File... paths)
      Specifies directories or files to exclude from Checkstyle analysis.
      Parameters:
      paths - the files to exclude
      Returns:
      this operation instance
      Throws:
      NullPointerException - if paths is null or contains null elements
      IllegalArgumentException - if paths is empty
    • exclude

      public CheckstyleOperation exclude(Path... paths)
      Specifies directories or files to exclude from Checkstyle analysis.
      Parameters:
      paths - the paths to exclude
      Returns:
      this operation instance
      Throws:
      NullPointerException - if paths is null or contains null elements
      IllegalArgumentException - if paths is empty
    • exclude

      public CheckstyleOperation exclude(Collection<File> paths)
      Specifies directories or files to exclude from Checkstyle analysis.
      Parameters:
      paths - the collection of files to exclude
      Returns:
      this operation instance
      Throws:
      NullPointerException - if paths is null or contains null elements
      IllegalArgumentException - if paths is empty
    • excludePaths

      public CheckstyleOperation excludePaths(Collection<Path> paths)
      Specifies directories or files to exclude from Checkstyle analysis.
      Parameters:
      paths - the collection of paths to exclude
      Returns:
      this operation instance
      Throws:
      NullPointerException - if paths is null or contains null elements
      IllegalArgumentException - if paths is empty
    • excludeRegex

      public CheckstyleOperation excludeRegex(String... patterns)
      Specifies directory or file patterns to exclude from Checkstyle analysis.
      Parameters:
      patterns - the regex patterns to exclude
      Returns:
      this operation instance
      Throws:
      NullPointerException - if patterns is null or contains null elements
      IllegalArgumentException - if patterns is empty, or contains empty elements
    • excludeRegex

      public CheckstyleOperation excludeRegex(Collection<String> patterns)
      Specifies directory or file patterns to exclude from Checkstyle analysis.
      Parameters:
      patterns - the collection of regex patterns to exclude
      Returns:
      this operation instance
      Throws:
      NullPointerException - if patterns is null or contains null elements
      IllegalArgumentException - if patterns is empty, or contains empty elements
    • excludeRegex

      public List<String> excludeRegex()
      Retrieves the list of regex patterns excluded from analysis.
      Returns:
      a mutable list of exclude regex patterns
    • excludeStrings

      public CheckstyleOperation excludeStrings(Collection<String> paths)
      Specifies directories or files to exclude from Checkstyle analysis.
      Parameters:
      paths - the collection of path strings to exclude
      Returns:
      this operation instance
      Throws:
      NullPointerException - if paths is null or contains null elements
      IllegalArgumentException - if paths is empty, or contains empty elements
    • executeIgnoredModules

      public CheckstyleOperation executeIgnoredModules(boolean isAllowIgnoreModules)
      Allows ignored modules to be executed. Corresponds to the -E option.
      Parameters:
      isAllowIgnoreModules - true to execute ignored modules, false to skip them
      Returns:
      this operation instance
    • format

      public CheckstyleOperation format(OutputFormat format)
      Specifies the output format for Checkstyle results. Corresponds to the -f option.
      Parameters:
      format - the output format
      Returns:
      this operation instance
      Throws:
      NullPointerException - if format is null
    • generateChecksAndFileSuppression

      public CheckstyleOperation generateChecksAndFileSuppression(boolean generateChecksAndFileSuppression)
      Generates suppression XML files for checks and files. Corresponds to the -G option.
      Parameters:
      generateChecksAndFileSuppression - true to generate suppression XML, false otherwise
      Returns:
      this operation instance
    • generateXpathSuppression

      public CheckstyleOperation generateXpathSuppression(boolean xPathSuppression)
      Generates XPath suppression XML. Corresponds to the -g option.
      Parameters:
      xPathSuppression - true to generate XPath suppression XML, false otherwise
      Returns:
      this operation instance
    • javadocTree

      public CheckstyleOperation javadocTree(boolean isTree)
      Prints the Javadoc parse tree. Corresponds to the -j option.
      Parameters:
      isTree - true to print the Javadoc tree, false otherwise
      Returns:
      this operation instance
    • options

      public Map<String,String> 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

      public CheckstyleOperation outputPath(String file)
      Sets the output file for Checkstyle results. Corresponds to the -o option.
      Parameters:
      file - the output file path
      Returns:
      this operation instance
      Throws:
      NullPointerException - if file is null
      IllegalArgumentException - if file is blank
    • outputPath

      public CheckstyleOperation outputPath(File file)
      Sets the output file for Checkstyle results. Corresponds to the -o option.
      Parameters:
      file - the output file
      Returns:
      this operation instance
      Throws:
      NullPointerException - if file is null
    • outputPath

      public CheckstyleOperation outputPath(Path file)
      Sets the output file for Checkstyle results. Corresponds to the -o option.
      Parameters:
      file - the output file path
      Returns:
      this operation instance
      Throws:
      NullPointerException - if file is null
    • propertiesFile

      public CheckstyleOperation propertiesFile(String file)
      Sets the properties file for Checkstyle. Corresponds to the -p option.
      Parameters:
      file - the properties file path
      Returns:
      this operation instance
      Throws:
      NullPointerException - if file is null
      IllegalArgumentException - if file is blank
    • propertiesFile

      public CheckstyleOperation propertiesFile(File file)
      Sets the properties file for Checkstyle. Corresponds to the -p option.
      Parameters:
      file - the properties file
      Returns:
      this operation instance
      Throws:
      NullPointerException - if file is null
    • propertiesFile

      public CheckstyleOperation propertiesFile(Path file)
      Sets the properties file for Checkstyle. Corresponds to the -p option.
      Parameters:
      file - the properties file path
      Returns:
      this operation instance
      Throws:
      NullPointerException - if file is null
    • sourceDir

      public CheckstyleOperation sourceDir(String... dirs)
      Specifies source directories to analyze.
      Parameters:
      dirs - the directory paths
      Returns:
      this operation instance
      Throws:
      NullPointerException - if dirs is null or contains null elements
      IllegalArgumentException - if dirs is blank, or contains blank elements
    • sourceDir

      public CheckstyleOperation sourceDir(File... dirs)
      Specifies source directories to analyze.
      Parameters:
      dirs - the directories
      Returns:
      this operation instance
      Throws:
      NullPointerException - if dirs is null or contains null elements
      IllegalArgumentException - if dirs is empty
    • sourceDir

      public CheckstyleOperation sourceDir(Path... dirs)
      Specifies source directories to analyze.
      Parameters:
      dirs - the directory paths
      Returns:
      this operation instance
      Throws:
      NullPointerException - if dirs is null or contains null elements
      IllegalArgumentException - if dirs is empty
    • sourceDir

      public CheckstyleOperation sourceDir(Collection<File> dirs)
      Specifies source directories to analyze.
      Parameters:
      dirs - the collection of directories
      Returns:
      this operation instance
      Throws:
      NullPointerException - if dirs is null or contains null elements
      IllegalArgumentException - if dirs is empty
    • sourceDir

      public Set<File> sourceDir()
      Returns the set of source directories to analyze.
      Returns:
      a mutable set of source directories
    • sourceDirPaths

      public CheckstyleOperation sourceDirPaths(Collection<Path> dirs)
      Specifies source directories to analyze.
      Parameters:
      dirs - the collection of directory paths
      Returns:
      this operation instance
      Throws:
      NullPointerException - if dirs is null or contains null elements
      IllegalArgumentException - if dirs is empty
    • sourceDirStrings

      public CheckstyleOperation sourceDirStrings(Collection<String> dirs)
      Specifies source directories to analyze.
      Parameters:
      dirs - the collection of directory path strings
      Returns:
      this operation instance
      Throws:
      NullPointerException - if dirs is null or contains null elements
      IllegalArgumentException - if dirs is empty, or contains empty elements
    • suppressionLineColumnNumber

      public CheckstyleOperation suppressionLineColumnNumber(int line, int column)
      Prints XPath suppressions for a specific line and column.
      Parameters:
      line - the line number
      column - the column number
      Returns:
      this operation instance
      Throws:
      IllegalArgumentException - if line or column is negative
    • tabWidth

      public CheckstyleOperation tabWidth(int length)
      Sets the tab width for column reporting.

      A value of 0 disables tab expansion, causing tabs to be counted as a single character. Corresponds to the -w option. Default is 8 if not set.

      Parameters:
      length - the tab width, must not be negative
      Returns:
      this operation instance
      Throws:
      IllegalArgumentException - if length is negative
    • tree

      public CheckstyleOperation tree(boolean isTree)
      Prints the Abstract Syntax Tree without comments. Corresponds to the -t option.
      Parameters:
      isTree - true to print the AST, false otherwise
      Returns:
      this operation instance
    • treeWithComments

      public CheckstyleOperation treeWithComments(boolean isTree)
      Prints the Abstract Syntax Tree with comment nodes included. Corresponds to the -T option.
      Parameters:
      isTree - true to print the AST with comments, false otherwise
      Returns:
      this operation instance
    • treeWithJavadoc

      public CheckstyleOperation treeWithJavadoc(boolean isTree)
      Prints the Abstract Syntax Tree with Javadoc nodes included. Corresponds to the -J option.
      Parameters:
      isTree - true to print the AST with Javadoc, false otherwise
      Returns:
      this operation instance