Class CheckstyleOperation


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

      @NonNull 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 fromProject(BaseProject) was not called
    • fromProject

      @NonNull public CheckstyleOperation fromProject(@NonNull 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, must not be null
      Returns:
      this operation instance
      Throws:
      NullPointerException - if project is null
    • branchMatchingXpath

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

      @NonNull public CheckstyleOperation configurationFile(@NonNull 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, must not be null
      Returns:
      this operation instance
      Throws:
      NullPointerException - if file is null
    • configurationFile

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

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

      @NonNull 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

      @NonNull 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

      @NonNull public CheckstyleOperation exclude(@NonNull String... paths)
      Specifies directories or files to exclude from Checkstyle analysis. Corresponds to the -e option. Replaces any previously set excludes.
      Parameters:
      paths - the paths to exclude, must not contain null or empty values
      Returns:
      this operation instance
      Throws:
      IllegalArgumentException - if paths is null or contains null or empty values
    • exclude

      @NonNull public CheckstyleOperation exclude(@NonNull File... paths)
      Specifies directories or files to exclude from Checkstyle analysis. Corresponds to the -e option. Replaces any previously set excludes.
      Parameters:
      paths - the files to exclude, must not contain null
      Returns:
      this operation instance
      Throws:
      IllegalArgumentException - if paths is null or contains null
    • exclude

      @NonNull public CheckstyleOperation exclude(@NonNull Path... paths)
      Specifies directories or files to exclude from Checkstyle analysis. Corresponds to the -e option. Replaces any previously set excludes.
      Parameters:
      paths - the paths to exclude, must not contain null
      Returns:
      this operation instance
      Throws:
      IllegalArgumentException - if paths is null or contains null
    • exclude

      Specifies directories or files to exclude from Checkstyle analysis. Corresponds to the -e option. Replaces any previously set excludes.
      Parameters:
      paths - the collection of files to exclude, must not be null or contain null
      Returns:
      this operation instance
      Throws:
      IllegalArgumentException - if paths is null or contains null
    • excludePaths

      @NonNull public CheckstyleOperation excludePaths(@NonNull Collection<Path> paths)
      Specifies directories or files to exclude from Checkstyle analysis. Corresponds to the -e option. Replaces any previously set excludes.
      Parameters:
      paths - the collection of paths to exclude, must not be null or contain null
      Returns:
      this operation instance
      Throws:
      IllegalArgumentException - if paths is null or contains null
    • excludeRegex

      @NonNull public CheckstyleOperation excludeRegex(@NonNull String... patterns)
      Specifies directory or file patterns to exclude from Checkstyle analysis. Corresponds to the -x option. Replaces any previously set exclude patterns.
      Parameters:
      patterns - the regex patterns to exclude, must not contain null or empty values
      Returns:
      this operation instance
      Throws:
      IllegalArgumentException - if patterns is null or contains null or empty values
    • excludeRegex

      @NonNull public CheckstyleOperation excludeRegex(@NonNull Collection<String> patterns)
      Specifies directory or file patterns to exclude from Checkstyle analysis. Corresponds to the -x option. Replaces any previously set exclude patterns.
      Parameters:
      patterns - the collection of regex patterns to exclude, must not be null or contain null or empty values
      Returns:
      this operation instance
      Throws:
      IllegalArgumentException - if patterns is null or contains null or empty values
    • excludeRegex

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

      @NonNull public CheckstyleOperation excludeStrings(@NonNull Collection<String> paths)
      Specifies directories or files to exclude from Checkstyle analysis. Corresponds to the -e option. Replaces any previously set excludes.
      Parameters:
      paths - the collection of path strings to exclude, must not be null or contain null or empty values
      Returns:
      this operation instance
      Throws:
      IllegalArgumentException - if paths is null or contains null or empty values
    • executeIgnoredModules

      @NonNull 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

      Specifies the output format for Checkstyle results. Corresponds to the -f option.
      Parameters:
      format - the output format, must not be null
      Returns:
      this operation instance
      Throws:
      NullPointerException - if format is null
    • generateChecksAndFileSuppression

      @NonNull 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

      @NonNull 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

      @NonNull 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

      @NonNull 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

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

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

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

      @NonNull public CheckstyleOperation propertiesFile(@NonNull String file)
      Sets the properties file for Checkstyle. Corresponds to the -p option.
      Parameters:
      file - the properties file path, must not be null
      Returns:
      this operation instance
      Throws:
      NullPointerException - if file is null
    • propertiesFile

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

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

      @NonNull public CheckstyleOperation sourceDir(@NonNull String... dirs)
      Specifies source directories to analyze. Replaces any previously set source directories.
      Parameters:
      dirs - the directory paths, must not contain null or empty values
      Returns:
      this operation instance
      Throws:
      IllegalArgumentException - if dirs is null or contains null or empty values
    • sourceDir

      @NonNull public CheckstyleOperation sourceDir(@NonNull File... dirs)
      Specifies source directories to analyze. Replaces any previously set source directories.
      Parameters:
      dirs - the directories, must not contain null
      Returns:
      this operation instance
      Throws:
      IllegalArgumentException - if dirs is null or contains null
    • sourceDir

      @NonNull public CheckstyleOperation sourceDir(@NonNull Path... dirs)
      Specifies source directories to analyze. Replaces any previously set source directories.
      Parameters:
      dirs - the directory paths, must not contain null
      Returns:
      this operation instance
      Throws:
      IllegalArgumentException - if dirs is null or contains null
    • sourceDir

      Specifies source directories to analyze. Replaces any previously set source directories.
      Parameters:
      dirs - the collection of directories, must not be null or contain null
      Returns:
      this operation instance
      Throws:
      IllegalArgumentException - if dirs is null or contains null
    • sourceDir

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

      @NonNull public CheckstyleOperation sourceDirPaths(@NonNull Collection<Path> dirs)
      Specifies source directories to analyze. Replaces any previously set source directories.
      Parameters:
      dirs - the collection of directory paths, must not be null or contain null
      Returns:
      this operation instance
      Throws:
      IllegalArgumentException - if dirs is null or contains null
    • sourceDirStrings

      @NonNull public CheckstyleOperation sourceDirStrings(@NonNull Collection<String> dirs)
      Specifies source directories to analyze. Replaces any previously set source directories.
      Parameters:
      dirs - the collection of directory path strings, must not be null or contain null or empty values
      Returns:
      this operation instance
      Throws:
      IllegalArgumentException - if dirs is null or contains null or empty values
    • suppressionLineColumnNumber

      @NonNull public CheckstyleOperation suppressionLineColumnNumber(int line, int column)
      Prints XPath suppressions for a specific line and column. Corresponds to the -s option.
      Parameters:
      line - the line number, must not be negative
      column - the column number, must not be negative
      Returns:
      this operation instance
      Throws:
      IllegalArgumentException - if line or column is negative
    • tabWidth

      @NonNull 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

      @NonNull 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

      @NonNull 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

      @NonNull 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