@CacheableTask public class Cpd extends org.gradle.api.tasks.SourceTask implements org.gradle.api.tasks.VerificationTask, org.gradle.api.reporting.Reporting<CpdReports>
Sample:
apply plugin: 'cpd'
task cpd(type: Cpd, description: 'Copy/Paste detection for all Ruby scripts') {
// change language of cpd to Ruby
language = 'ruby'
// set minimum token count causing a duplication warning
minimumTokenCount = 10
// enable CSV reports and customize outputLocation, disable xml report
reports {
csv {
required = true
outputLocation = file("${buildDir}/cpd.csv")
}
xml.required = false
}
// explicitly include all Ruby files and exclude tests
include '**.rb'
exclude '**Test*'
// set source for running duplication check on
source = files('src/ruby')
}
CpdPlugin| Constructor and Description |
|---|
Cpd(org.gradle.api.model.ObjectFactory objectFactory,
org.gradle.api.provider.ProviderFactory providerFactory,
org.gradle.workers.WorkerExecutor workerExecutor) |
| Modifier and Type | Method and Description |
|---|---|
java.lang.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
CpdExtension.getEncoding(). |
boolean |
getIgnoreAnnotations()
Ignore annotations because more and more modern frameworks use annotations on classes and methods which can be very redundant and
causes false positives.
|
boolean |
getIgnoreFailures()
Whether or not to allow the build to continue if there are warnings.
|
boolean |
getIgnoreIdentifiers()
Option if CPD should ignore identifiers differences, i.e. variable names, methods names, and so forth, when evaluating a duplicate
block.
|
boolean |
getIgnoreLiterals()
Option if CPD should ignore literal value differences when evaluating a duplicate block.
|
java.lang.String |
getLanguage()
Flag to select the appropriate language.
|
java.lang.Integer |
getMinimumTokenCount()
A positive integer indicating the minimum token count to trigger a CPD match; defaults to
CpdExtension.getMinimumTokenCount(). |
org.gradle.api.file.FileCollection |
getPmdClasspath()
The classpath containing the PMD library which contains the CPD library to be used.
|
CpdReports |
getReports() |
boolean |
getSkipBlocks()
Enables or disables skipping of blocks configured by
skipBlocksPattern. |
java.lang.String |
getSkipBlocksPattern()
Configures the pattern, to find the blocks to skip if enabled using
skipBlocks. |
boolean |
getSkipDuplicateFiles()
Ignore multiple copies of files of the same name and length in comparison.
|
boolean |
getSkipLexicalErrors()
Skip files which cannot be tokenized due to invalid characters instead of aborting CPD.
|
org.gradle.api.file.FileTree |
getSource() |
CpdReports |
reports(org.gradle.api.Action<? super CpdReports> action) |
CpdReports |
reports(groovy.lang.Closure closure) |
void |
run() |
void |
setEncoding(java.lang.String encoding) |
void |
setIgnoreAnnotations(boolean ignoreAnnotations) |
void |
setIgnoreFailures(boolean ignoreFailures) |
void |
setIgnoreIdentifiers(boolean ignoreIdentifiers) |
void |
setIgnoreLiterals(boolean ignoreLiterals) |
void |
setLanguage(java.lang.String language) |
void |
setMinimumTokenCount(java.lang.Integer minimumTokenCount) |
void |
setPmdClasspath(org.gradle.api.file.FileCollection pmdClasspath) |
void |
setSkipBlocks(boolean skipBlocks) |
void |
setSkipBlocksPattern(java.lang.String skipBlocksPattern) |
void |
setSkipDuplicateFiles(boolean skipDuplicateFiles) |
void |
setSkipLexicalErrors(boolean skipLexicalErrors) |
exclude, exclude, exclude, exclude, getExcludes, getIncludes, getPatternSetFactory, include, include, include, include, setExcludes, setIncludes, setSource, setSource, sourceconventionMapping, conventionMapping, getConventionMappingcompareTo, configure, dependsOn, doFirst, doFirst, doFirst, doLast, doLast, doLast, finalizedBy, getActions, getAnt, getDependsOn, getDescription, getDestroyables, getDidWork, getEnabled, getExtensions, getFinalizedBy, getGroup, getInputs, getLocalState, getLogger, getLogging, getMustRunAfter, getName, getOutputs, getPath, getProject, getShouldRunAfter, getState, getTaskDependencies, getTemporaryDir, getTimeout, hasProperty, mustRunAfter, onlyIf, onlyIf, property, setActions, setDependsOn, setDescription, setDidWork, setEnabled, setFinalizedBy, setGroup, setMustRunAfter, setOnlyIf, setOnlyIf, setProperty, setShouldRunAfter, shouldRunAfter, usesServiceappendParallelSafeAction, getAsDynamicObject, getConvention, getIdentityPath, getImpliesSubProjects, getOnlyIf, getRequiredServices, getServices, getSharedResources, getStandardOutputCapture, getTaskActions, getTaskIdentity, getTemporaryDirFactory, hasTaskActions, injectIntoNewInstance, isEnabled, isHasCustomActions, prependParallelSafeAction, replaceLogger, setImpliesSubProjects@Inject
public Cpd(org.gradle.api.model.ObjectFactory objectFactory,
org.gradle.api.provider.ProviderFactory providerFactory,
org.gradle.workers.WorkerExecutor workerExecutor)
public void run()
@InputFiles @SkipWhenEmpty @PathSensitive(value=RELATIVE) public org.gradle.api.file.FileTree getSource()
getSource in class org.gradle.api.tasks.SourceTaskpublic CpdReports reports(@DelegatesTo(value=CpdReports.class,strategy=1) groovy.lang.Closure closure)
reports in interface org.gradle.api.reporting.Reporting<CpdReports>public CpdReports getReports()
getReports in interface org.gradle.api.reporting.Reporting<CpdReports>public CpdReports reports(org.gradle.api.Action<? super CpdReports> action)
reports in interface org.gradle.api.reporting.Reporting<CpdReports>@Input @Optional public java.lang.String getEncoding()
CpdExtension.getEncoding().
Example: encoding = UTF-8
public void setEncoding(java.lang.String encoding)
@Input public boolean getIgnoreAnnotations()
Example: ignoreAnnotations = true
public void setIgnoreAnnotations(boolean ignoreAnnotations)
@Input public boolean getIgnoreFailures()
Example: ignoreFailures = true
getIgnoreFailures in interface org.gradle.api.tasks.VerificationTaskpublic void setIgnoreFailures(boolean ignoreFailures)
setIgnoreFailures in interface org.gradle.api.tasks.VerificationTask@Input public boolean getIgnoreIdentifiers()
Example: ignoreIdentifiers = true
public void setIgnoreIdentifiers(boolean ignoreIdentifiers)
@Input public boolean getIgnoreLiterals()
foo=42; and
foo=43; will be seen as equivalent.
Example: ignoreLiterals = true
public void setIgnoreLiterals(boolean ignoreLiterals)
@Input public java.lang.String getLanguage()
Example: language = 'java'
public void setLanguage(java.lang.String language)
@Input public java.lang.Integer getMinimumTokenCount()
CpdExtension.getMinimumTokenCount().
Example: minimumTokenCount = 25
public void setMinimumTokenCount(java.lang.Integer minimumTokenCount)
@Classpath public org.gradle.api.file.FileCollection getPmdClasspath()
public void setPmdClasspath(org.gradle.api.file.FileCollection pmdClasspath)
@Input public boolean getSkipDuplicateFiles()
Example: skipDuplicateFiles = true
public void setSkipDuplicateFiles(boolean skipDuplicateFiles)
@Input public boolean getSkipLexicalErrors()
Example: skipLexicalErrors = true
public void setSkipLexicalErrors(boolean skipLexicalErrors)
@Input public boolean getSkipBlocks()
skipBlocksPattern.
Example: skipBlocks = false
skipBlocksPatternpublic void setSkipBlocks(boolean skipBlocks)
@Input public java.lang.String getSkipBlocksPattern()
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.
Example: skipBlocksPattern = '#include <|>'
skipBlockspublic void setSkipBlocksPattern(java.lang.String skipBlocksPattern)