Class CheckstyleOperation


public class CheckstyleOperation extends AbstractProcessOperation<CheckstyleOperation>
Static code analysis using Checkstyle.
Since:
1.0
Author:
Erik C. Thauvin
  • 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
    • configurationFile

      public CheckstyleOperation configurationFile(File 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
    • configurationFile

      public CheckstyleOperation configurationFile(Path 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(File... 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(Path... 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<File> 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:
    • excludePaths

      public CheckstyleOperation excludePaths(Collection<Path> 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:
    • excludeStrings

      public CheckstyleOperation excludeStrings(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:
    • execute

      public void execute() throws IOException, InterruptedException, ExitStatusException
      Overrides:
      execute in class AbstractProcessOperation<CheckstyleOperation>
      Throws:
      IOException
      InterruptedException
      ExitStatusException
    • executeConstructProcessCommandList

      protected List<String> executeConstructProcessCommandList()
      Part of the 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

      public CheckstyleOperation format(OutputFormat format)
      Specifies the output format. Valid values: OutputFormat.XML, OutputFormat.SARIF, OutputFormat.PLAIN for the XML, sarif and default logger respectively.

      Defaults to OutputFormat.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
    • options

      public Map<String,String> options()
      Returns the command line options.
      Returns:
      the command line options
    • outputPath

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

      Defaults to stdout.

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

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

      Defaults to stdout.

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

      public CheckstyleOperation outputPath(Path 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
    • propertiesFile

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

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

      public CheckstyleOperation sourceDir(String... dir)
      Specifies 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(File... dir)
      Specifies 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(Path... dir)
      Specifies 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<File> dirs)
      Specifies the file(s) or folder(s) containing the source files to check.
      Parameters:
      dirs - the directories
      Returns:
      the checkstyle operation
      See Also:
    • sourceDir

      public Set<File> sourceDir()
      Returns the file(s) or folders(s) containing the sources files to check
      Returns:
      the files or directories
    • sourceDirPaths

      public CheckstyleOperation sourceDirPaths(Collection<Path> dirs)
      Specifies the file(s) or folder(s) containing the source files to check.
      Parameters:
      dirs - the directories
      Returns:
      the checkstyle operation
      See Also:
    • sourceDirStrings

      public CheckstyleOperation sourceDirStrings(Collection<String> dirs)
      Specifies 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