Package de.aaschmid.gradle.plugins.cpd
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 -
Method Summary
Modifier and TypeMethodDescriptionThe character set encoding (e.g., UTF-8) to use when reading the source code files but also when producing the report; defaults toSystem.getProperty("file.encoding").Flag to select the appropriate language; defaults to'java'.intA positive integer indicating the minimum token count to trigger a CPD match; defaults to50.CConfigures the pattern, to find the blocks to skip if enabled usingskipBlocks.booleanWhether 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.).booleanWhether 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.booleanIgnore annotations because more and more modern frameworks use annotations on classes and methods which can be very redundant and causes false positives; defaults tofalse.booleanOption if CPD should ignore identifiers differences, i.e.booleanOption if CPD should ignore literal value differences when evaluating a duplicate block; defaults tofalse.booleanEnables or disables skipping of blocks configured byskipBlocksPatternlike a pre-processor; defaults totrue.booleanIgnore multiple copies of files of the same name and length in comparison; defaults tofalse.voidsetEncoding(String encoding) voidsetFailOnError(boolean failOnError) voidsetFailOnViolation(boolean failOnViolation) voidsetIgnoreAnnotations(boolean ignoreAnnotations) voidsetIgnoreIdentifiers(boolean ignoreIdentifiers) voidsetIgnoreLiterals(boolean ignoreLiterals) voidsetLanguage(String language) voidsetMinimumTokenCount(int minimumTokenCount) voidsetSkipBlocks(boolean skipBlocks) voidsetSkipBlocksPattern(String skipBlocksPattern) voidsetSkipDuplicateFiles(boolean skipDuplicateFiles) Methods inherited from class org.gradle.api.plugins.quality.CodeQualityExtension
getReportsDir, getSourceSets, getToolVersion, isIgnoreFailures, setIgnoreFailures, setReportsDir, setSourceSets, setToolVersion
-
Constructor Details
-
CpdExtension
public CpdExtension()
-
-
Method Details
-
getEncoding
The character set encoding (e.g., UTF-8) to use when reading the source code files but also when producing the report; defaults toSystem.getProperty("file.encoding").Example:
encoding = UTF-8- Returns:
- the charset encoding
-
setEncoding
-
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 tofalse.Note: if this option is recognized depends on the used
languageand 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 tofalse.Note: if this option is recognized depends on the used
languageand 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 tofalse. This means e.g. thatfoo=42;andfoo=43;will be seen as equivalent.Note: if this option is recognized depends on the used
languageand its tokenizer.Example:
ignoreLiterals = true- Returns:
- whether literals should be ignored
-
setIgnoreLiterals
public void setIgnoreLiterals(boolean ignoreLiterals) -
getLanguage
Flag to select the appropriate language; defaults to'java'.Example:
language = 'java'- Returns:
- the used language
-
setLanguage
-
getMinimumTokenCount
public int getMinimumTokenCount()A positive integer indicating the minimum token count to trigger a CPD match; defaults to50.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 tofalse.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 byskipBlocksPatternlike a pre-processor; defaults totrue.Example:
skipBlocks = false- Returns:
- whether blocks should be skipped by a given pattern
- See Also:
-
skipBlocksPattern
-
setSkipBlocks
public void setSkipBlocks(boolean skipBlocks) -
getSkipBlocksPattern
CConfigures the pattern, to find the blocks to skip if enabled usingskipBlocks. It is aStringproperty 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 asCpdLanguagePropertiesDefaults.DEFAULT_SKIP_BLOCKS_PATTERN).Example:
skipBlocksPattern = '#include <|>'- Returns:
- the pattern used to skip blocks
- See Also:
-
skipBlocks
-
setSkipBlocksPattern
-