Class DetektOperation


public class DetektOperation extends AbstractProcessOperation<DetektOperation>
Performs static code analysis with Detekt.
Since:
1.0
Author:
Erik C. Thauvin
  • Constructor Details

    • DetektOperation

      public DetektOperation()
  • Method Details

    • allRules

      public DetektOperation allRules(boolean allRules)
      Activates all available (even unstable) rules.
      Parameters:
      allRules - true or false
      Returns:
      this operation instance
    • autoCorrect

      public DetektOperation autoCorrect(boolean autoCorrect)
      Allow rules to autocorrect code if they support it. The default rule sets do NOT support autocorrecting and won't change any line in the users code base. However, custom rules can be written to support autocorrecting. The additional 'formatting' rule set, added with Plugins, does support it and needs this flag.
      Parameters:
      autoCorrect - true or false
      Returns:
      this operation instance
    • basePath

      public DetektOperation basePath(String path)
      Specifies a directory as the base path. Currently, it impacts all file paths in the formatted reports. File paths in console output and txt report are not affected and remain as absolute paths.
      Parameters:
      path - the directory path
      Returns:
      this operation instance
    • baseline

      public DetektOperation baseline(String baseline)
      If a baseline xml file is passed in, only new code smells not in the baseline are printed in the console.
      Parameters:
      baseline - the baseline xml file
      Returns:
      this operation instance
    • buildUponDefaultConfig

      public DetektOperation buildUponDefaultConfig(boolean buildUponDefaultConfig)
      Preconfigures detekt with a bunch of rules and some opinionated defaults for you. Allows additional provided configurations to override the defaults.
      Parameters:
      buildUponDefaultConfig - true or false
      Returns:
      this operation instance
    • classPath

      public DetektOperation classPath(String... paths)
      EXPERIMENTAL: Paths where to find user class files and depending jar files. Used for type resolution.
      Parameters:
      paths - one or more files
      Returns:
      this operation instance
    • classPath

      public DetektOperation classPath(Collection<String> paths)
      EXPERIMENTAL: Paths where to find user class files and depending jar files. Used for type resolution.
      Parameters:
      paths - the list of files
      Returns:
      this operation instance
    • config

      public DetektOperation config(String... configs)
      Path to the config file (path/to/config.yml).
      Parameters:
      configs - one or more config files
      Returns:
      this operation instance
    • config

      public DetektOperation config(Collection<String> configs)
      Path to the config file (path/to/config.yml).
      Parameters:
      configs - the list pf config files
      Returns:
      this operation instance
    • configResource

      public DetektOperation configResource(String resource)
      Path to the config resource on detekt's classpath (path/to/config.yml).
      Parameters:
      resource - the config resource path
      Returns:
      this operation instance
    • createBaseline

      public DetektOperation createBaseline(boolean createBaseline)
      Treats current analysis findings as a smell baseline for future detekt runs.
      Parameters:
      createBaseline - true or false
      Returns:
      this operation instance
    • debug

      public DetektOperation debug(boolean debug)
      Prints extra information about configurations and extensions.
      Parameters:
      debug - true or false
      Returns:
      this operation instance
    • disableDefaultRuleSets

      public DetektOperation disableDefaultRuleSets(boolean disable)
      Disables default rule sets.
      Parameters:
      disable - true or false
      Returns:
      this operation instance
    • excludes

      public DetektOperation excludes(String patterns)
      Globbing patterns describing paths to exclude from the analysis.
      Parameters:
      patterns - the patterns
      Returns:
      this operation instance
    • execute

      Performs the operation.
      Overrides:
      execute in class AbstractProcessOperation<DetektOperation>
      Throws:
      InterruptedException - when the operation was interrupted
      IOException - when an exception occurred during the execution of the process
      FileUtilsErrorException - when an exception occurred during the retrieval of the operation output
      ExitStatusException - when the exit status was changed during the operation
    • 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<DetektOperation>
    • fromProject

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

      Sets the following:

      • baseline to detekt-baseline.xml, if it exists
      • excludes to exclude build and resources directories
      Specified by:
      fromProject in class AbstractProcessOperation<DetektOperation>
      Parameters:
      project - the project to configure the operation from
      Returns:
      this operation instance
    • generateConfig

      public DetektOperation generateConfig(boolean generate)
      Export default config. Path can be specified with config option.

      Default path: default-detekt-config.yml

      Parameters:
      generate - true or false
      Returns:
      this operation instance
    • includes

      public DetektOperation includes(String patterns)
      Globbing patterns describing paths to include in the analysis. Useful in combination with excludes patterns.
      Parameters:
      patterns - the patterns
      Returns:
      this operation instance
    • input

      public DetektOperation input(Collection<String> paths)
      Input paths to analyze. If not specified the current working directory is used.
      Parameters:
      paths - the list of paths
      Returns:
      this operation instance
    • input

      public DetektOperation input(String... paths)
      Input paths to analyze. If not specified the current working directory is used.
      Parameters:
      paths - one or more paths
      Returns:
      this operation instance
    • input

      public Collection<String> input()
      Returns the input paths to analyze.
      Returns:
      the input paths
    • jdkHome

      public DetektOperation jdkHome(String path)
      EXPERIMENTAL: Use a custom JDK home directory to include into the classpath.
      Parameters:
      path - the JDK home directory path
      Returns:
      this operation instance
    • jvmTarget

      public DetektOperation jvmTarget(String target)
      EXPERIMENTAL: Target version of the generated JVM bytecode that was generated during compilation and is now being used for type resolution

      Default: 1.8

      Parameters:
      target - the target version
      Returns:
      this operation instance
    • languageVersion

      public DetektOperation languageVersion(String version)
      EXPERIMENTAL: Compatibility mode for Kotlin language version X.Y, reports errors for all language features that came out later.

      Possible Values: [1.0, 1.1, 1.2, 1.3, 1.4, 1.5, 1.6, 1.7, 1.8, 1.9, 2.0, 2.1]

      Parameters:
      version - the version
      Returns:
      this operation instance
    • maxIssues

      public DetektOperation maxIssues(int max)
      Return exit code 0 only when found issues count does not exceed specified issues count.
      Parameters:
      max - the issues code
      Returns:
      this operation instance
    • parallel

      public DetektOperation parallel(boolean parallel)
      Enables parallel compilation and analysis of source files. Do some benchmarks first before enabling this flag. Heuristics show performance benefits starting from 2000 lines of Kotlin code.
      Parameters:
      parallel - true or false
      Returns:
      this operation instance
    • plugins

      public DetektOperation plugins(String... jars)
      Extra paths to plugin jars.
      Parameters:
      jars - one or more jars
      Returns:
      this operation instance
    • plugins

      public DetektOperation plugins(Collection<String> jars)
      Extra paths to plugin jars.
      Parameters:
      jars - the list of jars
      Returns:
      this operation instance
    • report

      public DetektOperation report(DetektReport... reports)
      Generates a report for given report-id and stores it on given 'path'.
      Parameters:
      reports - one or more reports
      Returns:
      this operation instance