Package de.aaschmid.gradle.plugins.cpd
Class Cpd
java.lang.Object
org.gradle.api.internal.AbstractTask
org.gradle.api.DefaultTask
org.gradle.api.internal.ConventionTask
org.gradle.api.tasks.SourceTask
de.aaschmid.gradle.plugins.cpd.Cpd
- All Implemented Interfaces:
Comparable<org.gradle.api.Task>,org.gradle.api.internal.DynamicObjectAware,org.gradle.api.internal.IConventionAware,org.gradle.api.internal.TaskInternal,org.gradle.api.Named,org.gradle.api.plugins.ExtensionAware,org.gradle.api.reporting.Reporting<CpdReports>,org.gradle.api.Task,org.gradle.api.tasks.util.PatternFilterable,org.gradle.api.tasks.VerificationTask,org.gradle.util.Configurable<org.gradle.api.Task>
@CacheableTask
public class Cpd
extends org.gradle.api.tasks.SourceTask
implements org.gradle.api.tasks.VerificationTask, org.gradle.api.reporting.Reporting<CpdReports>
Runs static code/paste (= duplication) detection on supplied source code files and generates a report of duplications found.
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')
}
- See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from interface org.gradle.api.Named
org.gradle.api.Named.Namer -
Field Summary
Fields inherited from interface org.gradle.api.Task
TASK_ACTION, TASK_CONSTRUCTOR_ARGS, TASK_DEPENDS_ON, TASK_DESCRIPTION, TASK_GROUP, TASK_NAME, TASK_OVERWRITE, TASK_TYPE -
Constructor Summary
ConstructorsConstructorDescriptionCpd(org.gradle.api.model.ObjectFactory objectFactory, org.gradle.api.provider.ProviderFactory providerFactory, org.gradle.workers.WorkerExecutor workerExecutor) -
Method Summary
Modifier and TypeMethodDescriptionstatic StringThe character set encoding (e.g., UTF-8) to use when reading the source code files but also when producing the report; defaults toCpdExtension.getEncoding().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.booleanWhether or not to allow the build to continue if there are warnings.booleanOption if CPD should ignore identifiers differences, i.e.booleanOption if CPD should ignore literal value differences when evaluating a duplicate block.Flag to select the appropriate language.A positive integer indicating the minimum token count to trigger a CPD match; defaults toCpdExtension.getMinimumTokenCount().protected org.gradle.api.tasks.util.internal.PatternSetFactoryorg.gradle.api.file.FileCollectionThe classpath containing the PMD library which contains the CPD library to be used.booleanEnables or disables skipping of blocks configured byskipBlocksPattern.Configures the pattern, to find the blocks to skip if enabled usingskipBlocks.booleanIgnore multiple copies of files of the same name and length in comparison.org.gradle.api.file.FileTreereports(groovy.lang.Closure closure) reports(org.gradle.api.Action<? super CpdReports> action) voidrun()voidsetEncoding(String encoding) voidsetFailOnError(boolean failOnError) voidsetFailOnViolation(boolean failOnViolation) voidsetIgnoreAnnotations(boolean ignoreAnnotations) voidsetIgnoreFailures(boolean ignoreFailures) voidsetIgnoreIdentifiers(boolean ignoreIdentifiers) voidsetIgnoreLiterals(boolean ignoreLiterals) voidsetLanguage(String language) voidsetMinimumTokenCount(Integer minimumTokenCount) voidsetPmdClasspath(org.gradle.api.file.FileCollection pmdClasspath) voidsetSkipBlocks(boolean skipBlocks) voidsetSkipBlocksPattern(String skipBlocksPattern) voidsetSkipDuplicateFiles(boolean skipDuplicateFiles) Methods inherited from class org.gradle.api.tasks.SourceTask
exclude, exclude, exclude, exclude, getExcludes, getIncludes, getPatternSet, include, include, include, include, setExcludes, setIncludes, setSource, setSource, sourceMethods inherited from class org.gradle.api.internal.ConventionTask
conventionMapping, conventionMapping, getConventionMappingMethods inherited from class org.gradle.api.DefaultTask
compareTo, 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, onlyIf, property, setActions, setDependsOn, setDescription, setDidWork, setEnabled, setFinalizedBy, setGroup, setMustRunAfter, setOnlyIf, setOnlyIf, setOnlyIf, setProperty, setShouldRunAfter, shouldRunAfter, usesServiceMethods inherited from class org.gradle.api.internal.AbstractTask
acceptServiceReferences, appendParallelSafeAction, doNotTrackState, doNotTrackStateIf, getAsDynamicObject, getIdentityPath, getImpliesSubProjects, getLifecycleDependencies, getOnlyIf, getReasonNotToTrackState, getReasonsNotToTrackState, getReasonTaskIsIncompatibleWithConfigurationCache, getRequiredServices, getServices, getSharedResources, getStandardOutputCapture, getTaskActions, getTaskIdentity, getTemporaryDirFactory, hasTaskActions, injectIntoNewInstance, isCompatibleWithConfigurationCache, isEnabled, isHasCustomActions, notCompatibleWithConfigurationCache, prependParallelSafeAction, restoreOnlyIf, restoreTaskActions, setImpliesSubProjectsMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.gradle.api.Task
doNotTrackState, notCompatibleWithConfigurationCache
-
Constructor Details
-
Cpd
@Inject public Cpd(org.gradle.api.model.ObjectFactory objectFactory, org.gradle.api.provider.ProviderFactory providerFactory, org.gradle.workers.WorkerExecutor workerExecutor)
-
-
Method Details
-
run
public void run() -
getPatternSetFactory
@Inject protected org.gradle.api.tasks.util.internal.PatternSetFactory getPatternSetFactory()- Specified by:
getPatternSetFactoryin classorg.gradle.api.tasks.SourceTask
-
getSource
@Nonnull @InputFiles @SkipWhenEmpty @PathSensitive(RELATIVE) public org.gradle.api.file.FileTree getSource()- Overrides:
getSourcein classorg.gradle.api.tasks.SourceTask
-
reports
@Nonnull public CpdReports reports(@Nonnull @DelegatesTo(value=CpdReports.class,strategy=1) groovy.lang.Closure closure) - Specified by:
reportsin interfaceorg.gradle.api.reporting.Reporting<CpdReports>
-
getReports
- Specified by:
getReportsin interfaceorg.gradle.api.reporting.Reporting<CpdReports>
-
reports
- Specified by:
reportsin interfaceorg.gradle.api.reporting.Reporting<CpdReports>
-
getEncoding
The character set encoding (e.g., UTF-8) to use when reading the source code files but also when producing the report; defaults toCpdExtension.getEncoding().Example:
encoding = UTF-8- Returns:
- the charset encoding
-
setEncoding
-
getIgnoreAnnotations
@Input public 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.Example:
ignoreAnnotations = true- Returns:
- if annotations should be ignored
-
setIgnoreAnnotations
public void setIgnoreAnnotations(boolean ignoreAnnotations) -
getIgnoreFailures
@Input public boolean getIgnoreFailures()Whether or not to allow the build to continue if there are warnings.Example:
ignoreFailures = true- Specified by:
getIgnoreFailuresin interfaceorg.gradle.api.tasks.VerificationTask
-
setIgnoreFailures
public void setIgnoreFailures(boolean ignoreFailures) - Specified by:
setIgnoreFailuresin interfaceorg.gradle.api.tasks.VerificationTask
-
getIgnoreIdentifiers
@Input public boolean getIgnoreIdentifiers()Option if CPD should ignore identifiers differences, i.e. variable names, methods names, and so forth, when evaluating a duplicate block.Example:
ignoreIdentifiers = true- Returns:
- whether identifiers should be ignored
-
setIgnoreIdentifiers
public void setIgnoreIdentifiers(boolean ignoreIdentifiers) -
getIgnoreLiterals
@Input public boolean getIgnoreLiterals()Option if CPD should ignore literal value differences when evaluating a duplicate block. This means e.g. thatfoo=42;andfoo=43;will be seen as equivalent.Example:
ignoreLiterals = true- Returns:
- whether literals should be ignored
-
setIgnoreLiterals
public void setIgnoreLiterals(boolean ignoreLiterals) -
getLanguage
Flag to select the appropriate language.Example:
language = 'java'- Returns:
- used language
-
setLanguage
-
getMinimumTokenCount
A positive integer indicating the minimum token count to trigger a CPD match; defaults toCpdExtension.getMinimumTokenCount().Example:
minimumTokenCount = 25- Returns:
- the minimum token cound
-
setMinimumTokenCount
-
getPmdClasspath
@Classpath public org.gradle.api.file.FileCollection getPmdClasspath()The classpath containing the PMD library which contains the CPD library to be used.- Returns:
- CPD libraries classpath
-
setPmdClasspath
public void setPmdClasspath(org.gradle.api.file.FileCollection pmdClasspath) -
getSkipDuplicateFiles
@Input public boolean getSkipDuplicateFiles()Ignore multiple copies of files of the same name and length in comparison.Example:
skipDuplicateFiles = true- Returns:
- whether duplicate files should be skipped
-
setSkipDuplicateFiles
public void setSkipDuplicateFiles(boolean skipDuplicateFiles) -
getFailOnError
@Input public boolean getFailOnError()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) -
getFailOnViolation
@Input public boolean getFailOnViolation()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) -
getSkipBlocks
@Input public boolean getSkipBlocks()Enables or disables skipping of blocks configured byskipBlocksPattern.Example:
skipBlocks = false- Returns:
- whether blocks should be skipped by a given pattern
- See Also:
-
skipBlocksPattern
-
setSkipBlocks
public void setSkipBlocks(boolean skipBlocks) -
getSkipBlocksPattern
Configures 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.Example:
skipBlocksPattern = '#include <|>'- Returns:
- the pattern used to skip blocks
- See Also:
-
skipBlocks
-
setSkipBlocksPattern
-
defaultCPDVersion
-