Class PmdOperation
- Since:
- 1.0
- Author:
- Erik C. Thauvin
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionaddExcludes
(Path... excludes) Adds paths to exclude from the analysis.addExcludes
(Collection<Path> excludes) Adds paths to exclude from the analysis.addExcludesFiles
(File... excludes) Adds paths to exclude from the analysis.addExcludesFiles
(Collection<File> excludes) Adds paths to exclude from the analysis.addExcludesStrings
(String... excludes) Adds paths to exclude from the analysis.addExcludesStrings
(Collection<String> excludes) Adds paths to exclude from the analysis.addInputPaths
(File... inputPath) Adds paths to source files, or directories containing source files to analyze.addInputPaths
(String... inputPath) Adds paths to source files, or directories containing source files to analyze.addInputPaths
(Path... inputPath) Adds paths to source files, or directories containing source files to analyze.\addInputPaths
(Collection<Path> inputPath) Adds paths to source files, or directories containing source files to analyze.addInputPathsFiles
(Collection<File> inputPath) Adds paths to source files, or directories containing source files to analyze.addInputPathsStrings
(Collection<String> inputPath) Adds paths to source files, or directories containing source files to analyze.addRuleSet
(String... ruleSet) Adds new rule set paths.addRuleSet
(Collection<String> ruleSet) Adds new rule set paths.Sets the location of the cache file for incremental analysis.Sets the location of the cache file for incremental analysis.Sets the location of the cache file for incremental analysis.defaultLanguageVersions
(Collection<LanguageVersion> languageVersion) Sets the default language version to be used for all input files.defaultLanguageVersions
(LanguageVersion... languageVersion) Sets the default language version to be used for all input files.Specifies the character set encoding of the source code files.Specifies the character set encoding of the source code files.excludes()
Returns the paths to exclude from the analysis.Sets paths to exclude from the analysis.excludes
(Collection<Path> excludes) Sets paths to exclude from the analysis.excludesFiles
(File... excludes) Sets paths to exclude from the analysis.excludesFiles
(Collection<File> excludes) Sets paths to exclude from the analysis.excludesStrings
(String... excludes) Sets paths to exclude from the analysis.excludesStrings
(Collection<String> excludes) Sets paths to exclude from the analysis.void
execute()
Performs the PMD code analysis operation.failOnError
(boolean failOnError) Sets whether the build will exit on recoverable errors.failOnViolation
(boolean failOnViolation) Sets whether the build will continue on violations.forceLanguageVersion
(LanguageVersion languageVersion) Forces a language to be used for all input files, irrespective of file names.fromProject
(BaseProject project) Configures a PMD operation from aBaseProject
.ignoreFile
(File ignoreFile) Sets the path to the file containing a list of files to ignore, one path per line.ignoreFile
(String ignoreFile) Sets the path to the file containing a list of files to ignore, one path per line.ignoreFile
(Path ignoreFile) Sets the path to the file containing a list of files to ignore, one path per line.includeLineNumber
(boolean includeLineNumber) Enables or disables including the line number for the beginning of the violation in the analyzed source file URI.incrementalAnalysis
(boolean incrementalAnalysis) Enables or disables incremental analysis.initConfiguration
(String commandName) Creates a new initialized configuration.Returns paths to source files, or directories containing source files to analyze.inputPaths
(File... inputPath) Sets paths to source files, or directories containing source files to analyze.inputPaths
(String... inputPath) Sets paths to source files, or directories containing source files to analyze.inputPaths
(Path... inputPath) Sets paths to source files, or directories containing source files to analyze.inputPaths
(Collection<Path> inputPath) Sets paths to source files, or directories containing source files to analyze.inputPathsFiles
(Collection<File> inputPath) Sets paths to source files, or directories containing source files to analyze.inputPathsStrings
(Collection<String> inputPath) Sets paths to source files, or directories containing source files to analyze.Returns the default language versions.languageVersions
(Collection<LanguageVersion> languageVersions) Sets the default language versions.languageVersions
(LanguageVersion... languageVersion) Sets the default language versions.minimumPriority
(RulePriority priority) Sets the minimum priority threshold when loading Rules from RuleSets.int
performPmdAnalysis
(String commandName, PMDConfiguration config) Performs the PMD analysis with the given config.Returns the prepended classpath.prependAuxClasspath
(String... classpath) Prepend the specified classpath like string to the current ClassLoader of the configuration.Returns paths to shorten paths that are output in the report.relativizeRoots
(File... relativeRoot) Adds several paths to shorten paths that are output in the report.relativizeRoots
(String... relativeRoot) Adds several paths to shorten paths that are output in the report.relativizeRoots
(Path... relativeRoot) Adds several paths to shorten paths that are output in the report.relativizeRoots
(Collection<Path> relativeRoot) Adds several paths to shorten paths that are output in the report.relativizeRootsFiles
(Collection<File> relativeRoot) Adds several paths to shorten paths that are output in the report.relativizeRootsStrings
(Collection<String> relativeRoot) Adds several paths to shorten paths that are output in the report.Returns the path to the report page.reportFile
(File reportFile) Sets the path to the report page.reportFile
(String reportFile) Sets the path to the report page.reportFile
(Path reportFile) Sets the path to the report page.reportFormat
(String reportFormat) Sets the output format of the analysis report.reportProperties
(Properties reportProperties) Sets the Report properties.ruleSets()
Returns the rule set paths.Sets new rule set paths, disregarding any previous entries.ruleSets
(Collection<String> ruleSet) Sets new rule set paths, disregarding any previous entries.showSuppressed
(boolean showSuppressed) Enables or disables adding the suppressed rule violations to the report.suppressedMarker
(String suppressedMarker) Specifies the comment token that marks lines which should be ignored.threads
(int threads) Sets the number of threads to be used.Sets the input URI to process for source code objects.Methods inherited from class rife.bld.operations.AbstractOperation
executeOnce, executeOnce, silent, silent
-
Field Details
-
RULE_SET_DEFAULT
The default rule set.Set to:
rulesets/java/quickstart.xml
- See Also:
-
-
Constructor Details
-
PmdOperation
public PmdOperation()
-
-
Method Details
-
addExcludes
Adds paths to exclude from the analysis.- Parameters:
excludes
- one or more paths to exclude- Returns:
- this operation
- Since:
- 1.2.0
- See Also:
-
addExcludes
Adds paths to exclude from the analysis.- Parameters:
excludes
- paths to exclude- Returns:
- this operation
- Since:
- 1.2.0
- See Also:
-
addExcludesFiles
Adds paths to exclude from the analysis.- Parameters:
excludes
- one or more paths to exclude- Returns:
- this operation
- Since:
- 1.2.0
- See Also:
-
addExcludesFiles
Adds paths to exclude from the analysis.- Parameters:
excludes
- one or more paths to exclude- Returns:
- this operation
- Since:
- 1.2.0
- See Also:
-
addExcludesStrings
Adds paths to exclude from the analysis.- Parameters:
excludes
- one or more paths to exclude- Returns:
- this operation
- Since:
- 1.2.0
- See Also:
-
addExcludesStrings
Adds paths to exclude from the analysis.- Parameters:
excludes
- one or more paths to exclude- Returns:
- this operation
- Since:
- 1.2.0
- See Also:
-
addInputPaths
Adds paths to source files, or directories containing source files to analyze.\- Parameters:
inputPath
- one or more paths- Returns:
- this operation
- See Also:
-
addInputPaths
Adds paths to source files, or directories containing source files to analyze.- Parameters:
inputPath
- one or more paths- Returns:
- this operation
- See Also:
-
addInputPaths
Adds paths to source files, or directories containing source files to analyze.- Parameters:
inputPath
- one or more paths- Returns:
- this operation
- See Also:
-
addInputPaths
Adds paths to source files, or directories containing source files to analyze.- Parameters:
inputPath
- a collection of input paths- Returns:
- this operation
- See Also:
-
addInputPathsFiles
Adds paths to source files, or directories containing source files to analyze.- Parameters:
inputPath
- a collection of input paths- Returns:
- this operation
- See Also:
-
addInputPathsStrings
Adds paths to source files, or directories containing source files to analyze.- Parameters:
inputPath
- a collection of input paths- Returns:
- this operation
- See Also:
-
addRuleSet
Adds new rule set paths.The built-in rule set paths are:
rulesets/java/quickstart.xml
category/java/bestpractices.xml
category/java/codestyle.xml
category/java/design.xml
category/java/documentation.xml
category/java/errorprone.xml
category/java/multithreading.xml
category/java/performance.xml
category/java/security.xml
- Parameters:
ruleSet
- one or more rule set- Returns:
- this operation
- See Also:
-
addRuleSet
Adds new rule set paths.The built-in rule set paths are:
rulesets/java/quickstart.xml
category/java/bestpractices.xml
category/java/codestyle.xml
category/java/design.xml
category/java/documentation.xml
category/java/errorprone.xml
category/java/multithreading.xml
category/java/performance.xml
category/java/security.xml
- Parameters:
ruleSet
- a collection of rule set paths- Returns:
- this operation
- See Also:
-
cache
Sets the location of the cache file for incremental analysis. -
cache
Sets the location of the cache file for incremental analysis. -
cache
Sets the location of the cache file for incremental analysis. -
defaultLanguageVersions
Sets the default language version to be used for all input files.- Parameters:
languageVersion
- one or more language version- Returns:
- this operation
-
defaultLanguageVersions
Sets the default language version to be used for all input files.- Parameters:
languageVersion
- a collection language versions- Returns:
- this operation
-
encoding
Specifies the character set encoding of the source code files. The default is
UTF-8
.The valid values are the standard character sets of
Charset
. -
encoding
-
excludes
Sets paths to exclude from the analysis.- Parameters:
excludes
- one or more paths to exclude- Returns:
- this operation
- See Also:
-
excludes
Sets paths to exclude from the analysis.- Parameters:
excludes
- paths to exclude- Returns:
- this operation
- See Also:
-
excludes
Returns the paths to exclude from the analysis.- Returns:
- the exclude paths
-
excludesFiles
Sets paths to exclude from the analysis.- Parameters:
excludes
- one or more paths to exclude- Returns:
- this operation
- Since:
- 1.2.0
- See Also:
-
excludesFiles
Sets paths to exclude from the analysis.- Parameters:
excludes
- one or more paths to exclude- Returns:
- this operation
- Since:
- 1.2.0
- See Also:
-
excludesStrings
Sets paths to exclude from the analysis.- Parameters:
excludes
- one or more paths to exclude- Returns:
- this operation
- Since:
- 1.2.0
- See Also:
-
excludesStrings
Sets paths to exclude from the analysis.- Parameters:
excludes
- one or more paths to exclude- Returns:
- this operation
- Since:
- 1.2.0
- See Also:
-
execute
Performs the PMD code analysis operation.- Specified by:
execute
in classAbstractOperation<PmdOperation>
- Throws:
Exception
-
failOnError
Sets whether the build will exit on recoverable errors.Default is:
true
Note: If only violations are found, see
failOnViolation
- Parameters:
failOnError
- whether to exit and fail the build if recoverable errors occurred- Returns:
- this operation
- See Also:
-
failOnViolation
Sets whether the build will continue on violations.Note: If additionally recoverable errors occurred, see
failOnError
- Parameters:
failOnViolation
- whether to exit and fail the build if violations are found- Returns:
- this operation
-
forceLanguageVersion
Forces a language to be used for all input files, irrespective of file names.- Parameters:
languageVersion
- the language version- Returns:
- this operation
-
fromProject
Configures a PMD operation from aBaseProject
.The defaults are:
- cache=
build/pmd/pmd-cache
- encoding=
UTF-9
- incrementAnalysis=
true
- inputPaths=
[src/main, src/test]
- reportFile=
build/pmd/pmd-report-txt
- reportFormat=
text
- rulePriority=
LOW
- ruleSets=
[rulesets/java/quickstart.xml]
- suppressedMarker=
NOPMD
- Parameters:
project
- the project- Returns:
- this operation
- cache=
-
ignoreFile
Sets the path to the file containing a list of files to ignore, one path per line.- Parameters:
ignoreFile
- the ignore file path- Returns:
- this operation
-
ignoreFile
Sets the path to the file containing a list of files to ignore, one path per line.- Parameters:
ignoreFile
- the ignore file path- Returns:
- this operation
-
ignoreFile
Sets the path to the file containing a list of files to ignore, one path per line.- Parameters:
ignoreFile
- the ignore file path- Returns:
- this operation
-
includeLineNumber
Enables or disables including the line number for the beginning of the violation in the analyzed source file URI.While clicking on the URI works in IntelliJ IDEA, Visual Studio Code, etc.; it might not in terminal emulators.
Default:
TRUE
-
incrementalAnalysis
Enables or disables incremental analysis. -
initConfiguration
Creates a new initialized configuration.- Parameters:
commandName
- the command name- Returns:
- this operation
-
inputPaths
Sets paths to source files, or directories containing source files to analyze.- Parameters:
inputPath
- one or more paths- Returns:
- this operation
- See Also:
-
inputPaths
Sets paths to source files, or directories containing source files to analyze.Previous entries are disregarded.
- Parameters:
inputPath
- one or more paths- Returns:
- this operation
- See Also:
-
inputPaths
Sets paths to source files, or directories containing source files to analyze.Previous entries are disregarded.
- Parameters:
inputPath
- one or more paths- Returns:
- this operation
- See Also:
-
inputPaths
Sets paths to source files, or directories containing source files to analyze.Previous entries are disregarded.
- Parameters:
inputPath
- a collection of input paths- Returns:
- this operation
- See Also:
-
inputPaths
Returns paths to source files, or directories containing source files to analyze.- Returns:
- the input paths
-
inputPathsFiles
Sets paths to source files, or directories containing source files to analyze.Previous entries are disregarded.
- Parameters:
inputPath
- a collection of input paths- Returns:
- this operation
- See Also:
-
inputPathsStrings
Sets paths to source files, or directories containing source files to analyze.Previous entries are disregarded.
- Parameters:
inputPath
- a collection of input paths- Returns:
- this operation
- See Also:
-
languageVersions
Sets the default language versions.- Parameters:
languageVersion
- one or more language versions- Returns:
- this operation
-
languageVersions
Sets the default language versions.- Parameters:
languageVersions
- a collection language versions- Returns:
- this operation
-
languageVersions
Returns the default language versions.- Returns:
- the language versions
-
minimumPriority
Sets the minimum priority threshold when loading Rules from RuleSets.- Returns:
- this operation
-
performPmdAnalysis
public int performPmdAnalysis(String commandName, PMDConfiguration config) throws ExitStatusException Performs the PMD analysis with the given config.- Parameters:
commandName
- the command nameconfig
- the configuration- Returns:
- the number of violations
- Throws:
ExitStatusException
- if an error occurs
-
prependAuxClasspath
Prepend the specified classpath like string to the current ClassLoader of the configuration. If no ClassLoader is currently configured, the ClassLoader used to load the PMDConfiguration class will be used as the parent ClassLoader of the created ClassLoader.If the classpath String looks like a URL to a file (i.e. starts with
file://
) the file will be read with each line representing an entry on the classpath.- Parameters:
classpath
- one or more classpath- Returns:
- this operation
-
prependAuxClasspath
Returns the prepended classpath.- Returns:
- the classpath
-
relativizeRoots
Adds several paths to shorten paths that are output in the report.- Parameters:
relativeRoot
- one or more relative root paths- Returns:
- this operation
- See Also:
-
relativizeRoots
Adds several paths to shorten paths that are output in the report.- Parameters:
relativeRoot
- one or more relative root paths- Returns:
- this operation
- See Also:
-
relativizeRoots
Adds several paths to shorten paths that are output in the report.- Parameters:
relativeRoot
- one or more relative root paths- Returns:
- this operation
- See Also:
-
relativizeRoots
Adds several paths to shorten paths that are output in the report.- Parameters:
relativeRoot
- a collection of relative root paths- Returns:
- this operation
- See Also:
-
relativizeRoots
Returns paths to shorten paths that are output in the report.- Returns:
- the relative root paths
-
relativizeRootsFiles
Adds several paths to shorten paths that are output in the report.- Parameters:
relativeRoot
- a collection of relative root paths- Returns:
- this operation
- See Also:
-
relativizeRootsStrings
Adds several paths to shorten paths that are output in the report.- Parameters:
relativeRoot
- a collection of relative root paths- Returns:
- this operation
- See Also:
-
reportFile
Sets the path to the report page.- Parameters:
reportFile
- the report file path- Returns:
- this operation
-
reportFile
Sets the path to the report page.- Parameters:
reportFile
- the report file path- Returns:
- this operation
-
reportFile
Sets the path to the report page.- Parameters:
reportFile
- the report file path- Returns:
- this operation
-
reportFile
Returns the path to the report page.- Returns:
- the path
-
reportFormat
Sets the output format of the analysis report. The default istext
.- Parameters:
reportFormat
- the report format- Returns:
- this operation
-
reportProperties
Sets the Report properties. These are used to create the Renderer.- Parameters:
reportProperties
- the report properties- Returns:
- this operation
-
ruleSets
Sets new rule set paths, disregarding any previous entries.The built-in rule set paths are:
rulesets/java/quickstart.xml
category/java/bestpractices.xml
category/java/codestyle.xml
category/java/design.xml
category/java/documentation.xml
category/java/errorprone.xml
category/java/multithreading.xml
category/java/performance.xml
category/java/security.xml
- Parameters:
ruleSet
- one or more rule set- Returns:
- this operation
- See Also:
-
ruleSets
Sets new rule set paths, disregarding any previous entries.The built-in rule set paths are:
rulesets/java/quickstart.xml
category/java/bestpractices.xml
category/java/codestyle.xml
category/java/design.xml
category/java/documentation.xml
category/java/errorprone.xml
category/java/multithreading.xml
category/java/performance.xml
category/java/security.xml
- Parameters:
ruleSet
- a collection of rule set paths- Returns:
- this operation
- See Also:
-
ruleSets
Returns the rule set paths.- Returns:
- the rule sets
-
showSuppressed
Enables or disables adding the suppressed rule violations to the report.- Parameters:
showSuppressed
-true
orfalse
- Returns:
- this operation
-
suppressedMarker
Specifies the comment token that marks lines which should be ignored. The default isNOPMD
.- Parameters:
suppressedMarker
- the suppressed marker- Returns:
- this operation
-
threads
Sets the number of threads to be used. The default is1
.- Parameters:
threads
- the number of threads- Returns:
- this operation
-
uri
Sets the input URI to process for source code objects.- Parameters:
inputUri
- the input URI- Returns:
- this operation
-