Class CheckstyleOperation


public class CheckstyleOperation extends AbstractProcessOperation<CheckstyleOperation>
Static code analysis using Checkstyle.
Since:
1.0
Author:
Erik C. Thauvin
  • Field Details

    • exclude

      protected final List<String> exclude
    • excludeRegex

      protected final List<String> excludeRegex
    • options

      protected final Map<String,String> options
      The command line options.
    • sourceDirs

      protected final Set<String> sourceDirs
      The source files(s) or folder(s).
  • Constructor Details

    • CheckstyleOperation

      public CheckstyleOperation()
  • Method Details

    • branchMatchingXpath

      public CheckstyleOperation branchMatchingXpath(String xPathQuery)
      Shows Abstract Syntax Tree(AST) branches that match given XPath query.
      Parameters:
      xPathQuery - the xPath query
      Returns:
      the checkstyle operation
    • configurationFile

      public CheckstyleOperation configurationFile(String file)
      Specifies the location of the file that defines the configuration modules. The location can either be a filesystem location, or a name passed to the ClassLoader.getResource() method. A configuration file is required.
      Parameters:
      file - the file
      Returns:
      the checkstyle operation
    • debug

      public CheckstyleOperation debug(boolean isDebug)
      Prints all debug logging of CheckStyle utility.
      Parameters:
      isDebug - true or false
      Returns:
      the checkstyle operation
    • exclude

      public CheckstyleOperation exclude(String... path)
      Directory/file to exclude from CheckStyle. The path can be the full, absolute path, or relative to the current path. Multiple excludes are allowed.
      Parameters:
      path - one or more paths
      Returns:
      the checkstyle operation
      See Also:
    • exclude

      public CheckstyleOperation exclude(Collection<String> paths)
      Directory/file to exclude from CheckStyle. The path can be the full, absolute path, or relative to the current path. Multiple excludes are allowed.
      Parameters:
      paths - the paths
      Returns:
      the checkstyle operation
      See Also:
    • excludeRegex

      public CheckstyleOperation excludeRegex(String... regex)
      Directory/file pattern to exclude from CheckStyle. Multiple exclude are allowed.
      Parameters:
      regex - the pattern to exclude
      Returns:
      the checkstyle operation
      See Also:
    • excludeRegex

      public CheckstyleOperation excludeRegex(Collection<String> regex)
      Directory/file pattern to exclude from CheckStyle. Multiple exclude are allowed.
      Parameters:
      regex - the patterns to exclude
      Returns:
      the checkstyle operation
      See Also:
    • 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>
    • fromProject

      public CheckstyleOperation fromProject(BaseProject project)
      Configures the BaseProject.
      Specified by:
      fromProject in class AbstractProcessOperation<CheckstyleOperation>
    • executeIgnoredModules

      public CheckstyleOperation executeIgnoredModules(boolean isAllowIgnoreModules)
      Allows ignored modules to be run.
      Parameters:
      isAllowIgnoreModules - true or false
      Returns:
      the checkstyle operation
    • format

      Specifies the output format. Valid values: CheckstyleFormatOption.XML, CheckstyleFormatOption.SARIF, CheckstyleFormatOption.PLAIN for the XML, sarif and default logger respectively.

      Defaults to CheckstyleFormatOption.PLAIN.

      Parameters:
      format - the output format
      Returns:
      the checkstyle operation
    • generateXpathSuppression

      public CheckstyleOperation generateXpathSuppression(boolean xPathSuppression)
      Generates to output a suppression xml to use to suppress all violations from user's config. Instead of printing every violation, all violations will be caught and single suppressions xml file will be printed out. Used only with the configurationFile option. Output location can be specified with the output option.
      Parameters:
      xPathSuppression - true or false
      Returns:
      the checkstyle operation
    • javadocTree

      public CheckstyleOperation javadocTree(boolean isTree)
      This option is used to print the Parse Tree of the Javadoc comment. The file has to contain only Javadoc comment content excluding '/**' and '*/' at the beginning and at the end respectively. It can only be used on a single file and cannot be combined with other options.
      Parameters:
      isTree - true or false
      Returns:
      the checkstyle operation
    • outputPath

      public CheckstyleOperation outputPath(String file)
      Sets the output file.

      Defaults to stdout.

      Parameters:
      file - the output file
      Returns:
      the checkstyle operation
    • propertiesFile

      public CheckstyleOperation propertiesFile(String file)
      Sets the property files to load.
      Parameters:
      file - the file
      Returns:
      the checkstyle operation
    • sourceDir

      public CheckstyleOperation sourceDir(String... dir)
      Specified the file(s) or folder(s) containing the source files to check.
      Parameters:
      dir - one or more directories
      Returns:
      the checkstyle operation
      See Also:
    • sourceDir

      public CheckstyleOperation sourceDir(Collection<String> dirs)
      Specified the file(s) or folder(s) containing the source files to check.
      Parameters:
      dirs - the directories
      Returns:
      the checkstyle operation
      See Also:
    • suppressionLineColumnNumber

      public CheckstyleOperation suppressionLineColumnNumber(String lineColumnNumber)
      Prints xpath suppressions at the file's line and column position. Argument is the line and column number (separated by a : ) in the file that the suppression should be generated for. The option cannot be used with other options and requires exactly one file to run on to be specified.

      Note that the generated result will have few queries, joined by pipe(|). Together they will match all AST nodes on specified line and column. You need to choose only one and recheck that it works. Usage of all of them is also ok, but might result in undesirable matching and suppress other issues.

      Parameters:
      lineColumnNumber - the line column number
      Returns:
      the checkstyle operation
    • tabWith

      public CheckstyleOperation tabWith(int length)
      Sets the length of the tab character. Used only with the suppressionLineColumnNumber option.

      Default value is 8.

      Parameters:
      length - the length
      Returns:
      the checkstyle operation
    • tree

      public CheckstyleOperation tree(boolean isTree)
      This option is used to display the Abstract Syntax Tree (AST) without any comments of the specified file. It can only be used on a single file and cannot be combined with other options.
      Parameters:
      isTree - true or false
      Returns:
      the checkstyle operation
    • treeWithComments

      public CheckstyleOperation treeWithComments(boolean isTree)
      This option is used to display the Abstract Syntax Tree (AST) with comment nodes excluding Javadoc of the specified file. It can only be used on a single file and cannot be combined with other options.
      Parameters:
      isTree - true or false
      Returns:
      the checkstyle operation
    • treeWithJavadoc

      public CheckstyleOperation treeWithJavadoc(boolean isTree)
      This option is used to display the Abstract Syntax Tree (AST) with Javadoc nodes of the specified file. It can only be used on a single file and cannot be combined with other options.
      Parameters:
      isTree - true or false
      Returns:
      the checkstyle operation