Class CpdExtension

java.lang.Object
org.gradle.api.plugins.quality.CodeQualityExtension
de.aaschmid.gradle.plugins.cpd.CpdExtension

public class CpdExtension extends org.gradle.api.plugins.quality.CodeQualityExtension
Configuration options for the CPD plugin.

The sample below shows various configuration options:

 apply plugin: 'cpd'

 cpd {
     encoding = 'UTF-8'
     ignoreAnnotations = true
     language = 'java'
     minimumTokenCount = 20
 }
 
See Also:
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    The character set encoding (e.g., UTF-8) to use when reading the source code files but also when producing the report; defaults to System.getProperty("file.encoding").
    Flag to select the appropriate language; defaults to 'java'.
    int
    A positive integer indicating the minimum token count to trigger a CPD match; defaults to 50.
    CConfigures the pattern, to find the blocks to skip if enabled using skipBlocks.
    boolean
    Whether CPD should exit with status 4 (the default behavior, true) if violations are found or just with 0 (to not break the build, e.g.).
    boolean
    Whether PMD should exit with status 5 (the default behavior, true) if recoverable errors occurred or just with 0 (to not break the build, e.g.
    boolean
    Ignore annotations because more and more modern frameworks use annotations on classes and methods which can be very redundant and causes false positives; defaults to false.
    boolean
    Option if CPD should ignore identifiers differences, i.e.
    boolean
    Option if CPD should ignore literal value differences when evaluating a duplicate block; defaults to false.
    boolean
    Enables or disables skipping of blocks configured by skipBlocksPattern like a pre-processor; defaults to true.
    boolean
    Ignore multiple copies of files of the same name and length in comparison; defaults to false.
    void
    setEncoding(String encoding)
     
    void
    setFailOnError(boolean failOnError)
     
    void
    setFailOnViolation(boolean failOnViolation)
     
    void
    setIgnoreAnnotations(boolean ignoreAnnotations)
     
    void
    setIgnoreIdentifiers(boolean ignoreIdentifiers)
     
    void
    setIgnoreLiterals(boolean ignoreLiterals)
     
    void
    setLanguage(String language)
     
    void
    setMinimumTokenCount(int minimumTokenCount)
     
    void
    setSkipBlocks(boolean skipBlocks)
     
    void
    setSkipBlocksPattern(String skipBlocksPattern)
     
    void
    setSkipDuplicateFiles(boolean skipDuplicateFiles)
     

    Methods inherited from class org.gradle.api.plugins.quality.CodeQualityExtension

    getReportsDir, getSourceSets, getToolVersion, isIgnoreFailures, setIgnoreFailures, setReportsDir, setSourceSets, setToolVersion

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • CpdExtension

      public CpdExtension()
  • Method Details

    • getEncoding

      public String getEncoding()
      The character set encoding (e.g., UTF-8) to use when reading the source code files but also when producing the report; defaults to System.getProperty("file.encoding").

      Example: encoding = UTF-8

      Returns:
      the charset encoding
    • setEncoding

      public void setEncoding(String encoding)
    • isIgnoreAnnotations

      public boolean isIgnoreAnnotations()
      Ignore annotations because more and more modern frameworks use annotations on classes and methods which can be very redundant and causes false positives; defaults to false.

      Note: if this option is recognized depends on the used language and its tokenizer.

      Example: ignoreAnnotations = true

      Returns:
      whether annotation should be ignored
    • setIgnoreAnnotations

      public void setIgnoreAnnotations(boolean ignoreAnnotations)
    • isIgnoreIdentifiers

      public boolean isIgnoreIdentifiers()
      Option if CPD should ignore identifiers differences, i.e. variable names, methods names, and so forth, when evaluating a duplicate block; defaults to false.

      Note: if this option is recognized depends on the used language and its tokenizer.

      Example: ignoreIdentifiers = true

      Returns:
      whether identifiers should be ignored
    • setIgnoreIdentifiers

      public void setIgnoreIdentifiers(boolean ignoreIdentifiers)
    • isIgnoreLiterals

      public boolean isIgnoreLiterals()
      Option if CPD should ignore literal value differences when evaluating a duplicate block; defaults to false. This means e.g. that foo=42; and foo=43; will be seen as equivalent.

      Note: if this option is recognized depends on the used language and its tokenizer.

      Example: ignoreLiterals = true

      Returns:
      whether literals should be ignored
    • setIgnoreLiterals

      public void setIgnoreLiterals(boolean ignoreLiterals)
    • getLanguage

      public String getLanguage()
      Flag to select the appropriate language; defaults to 'java'.

      Example: language = 'java'

      Returns:
      the used language
    • setLanguage

      public void setLanguage(String language)
    • getMinimumTokenCount

      public int getMinimumTokenCount()
      A positive integer indicating the minimum token count to trigger a CPD match; defaults to 50.

      Example: minimumTokenCount = 25

      Returns:
      the minimum token count
    • setMinimumTokenCount

      public void setMinimumTokenCount(int minimumTokenCount)
    • isSkipDuplicateFiles

      public boolean isSkipDuplicateFiles()
      Ignore multiple copies of files of the same name and length in comparison; defaults to false.

      Example: skipDuplicateFiles = true

      Returns:
      whether duplicate files should be skipped
    • setSkipDuplicateFiles

      public void setSkipDuplicateFiles(boolean skipDuplicateFiles)
    • isFailOnError

      public boolean isFailOnError()
      Whether CPD should exit with status 4 (the default behavior, true) if violations are found or just with 0 (to not break the build, e.g.).

      Example: failOnError = false

      Returns:
      whether CPD should fail on error
    • setFailOnError

      public void setFailOnError(boolean failOnError)
    • isFailOnViolation

      public boolean isFailOnViolation()
      Whether PMD should exit with status 5 (the default behavior, true) if recoverable errors occurred or just with 0 (to not break the build, e.g. if the validation check fails).

      Example: failOnViolation = false

      Returns:
      whether CPD should fail on violation
    • setFailOnViolation

      public void setFailOnViolation(boolean failOnViolation)
    • isSkipBlocks

      public boolean isSkipBlocks()
      Enables or disables skipping of blocks configured by skipBlocksPattern like a pre-processor; defaults to true.

      Example: skipBlocks = false

      Returns:
      whether blocks should be skipped by a given pattern
      See Also:
      • skipBlocksPattern
    • setSkipBlocks

      public void setSkipBlocks(boolean skipBlocks)
    • getSkipBlocksPattern

      public String getSkipBlocksPattern()
      CConfigures the pattern, to find the blocks to skip if enabled using skipBlocks. It is a String property and contains of two parts, separated by '|'. The first part is the start pattern, the second part is the ending pattern. defaults to '#if 0|#endif' (which should be the same as CpdLanguagePropertiesDefaults.DEFAULT_SKIP_BLOCKS_PATTERN).

      Example: skipBlocksPattern = '#include <|>'

      Returns:
      the pattern used to skip blocks
      See Also:
      • skipBlocks
    • setSkipBlocksPattern

      public void setSkipBlocksPattern(String skipBlocksPattern)