Package rife.bld.extension
Class PmdOperation
Performs static code analysis with PMD.
- Since:
- 1.0
- Author:
- Erik C. Thauvin
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionSets 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.collectFilesRecursively(boolean collectFilesRecursively) When specified, any directory mentioned withinputPaths()will only be searched for files that are direct children.Returns the default language versions.final PmdOperationdefaultLanguageVersions(Collection<LanguageVersion> languageVersions) Sets the default language version to be used for all input files.defaultLanguageVersions(LanguageVersion... languageVersions) 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.final PmdOperationexcludes(Collection<Path> paths) Sets paths to exclude from the analysis.excludesFiles(File... files) Sets paths to exclude from the analysis.final PmdOperationexcludesFiles(Collection<File> files) Sets paths to exclude from the analysis.excludesStrings(String... excludes) Sets paths to exclude from the analysis.final PmdOperationexcludesStrings(Collection<String> excludes) Sets paths to exclude from the analysis.voidexecute()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 file) 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 path) Sets the path to the file containing a list of files to ignore, one path per line.includeLineNumber(boolean includeLineNumber) Enables or disables line number in source file URIs.incrementalAnalysis(boolean incrementalAnalysis) Enables or disables incremental analysis.Returns paths to source files or directories containing source files to analyze.inputPaths(File... files) Sets paths to source files or directories containing source files to analyze.inputPaths(String... inputPaths) Sets paths to source files or directories containing source files to analyze.inputPaths(Path... paths) Sets paths to source files or directories containing source files to analyze.final PmdOperationinputPaths(Collection<Path> paths) Sets paths to source files or directories containing source files to analyze.final PmdOperationinputPathsFiles(Collection<File> files) Sets paths to source files or directories containing source files to analyze.inputPathsStrings(Collection<String> inputPaths) Sets paths to source files or directories containing source files to analyze.minimumPriority(RulePriority priority) Sets the minimum priority threshold when loading Rules from RuleSets.performAnalysis(PMDConfiguration config) Performs the PMD analysis with the given config.Returns the prepended classpath.prependAuxClasspath(String... classpaths) Prepend the specified classpaths-like string to the current ClassLoader of the configuration.Returns paths to shorten paths that are output in the report.relativizeRoots(File... roots) Adds several paths to shorten paths that are output in the report.relativizeRoots(String... roots) Adds several paths to shorten paths that are output in the report.relativizeRoots(Path... roots) Adds several paths to shorten paths that are output in the report.final PmdOperationrelativizeRoots(Collection<Path> roots) Adds several paths to shorten paths that are output in the report.final PmdOperationrelativizeRootsFiles(Collection<File> roots) Adds several paths to shorten paths that are output in the report.final PmdOperationrelativizeRootsStrings(Collection<String> roots) Adds several paths to shorten paths that are output in the report.Returns the path to the report file.reportFile(File file) Sets the path to the report page.reportFile(String reportFile) Sets the path to the report page.reportFile(Path path) Sets the path to the report page.reportFormat(String format) Sets the output format of the analysis report.reportProperties(Properties properties) Sets the Report properties.ruleSets()Returns the rule set paths.Sets rule set paths.final PmdOperationruleSets(Collection<String> ruleSets) Sets rule set paths.final PmdOperationSets rule set paths.final PmdOperationruleSetsRules(Collection<JavaRules> ruleSets) Sets rule set paths.showSuppressed(boolean showSuppressed) Enables or disables adding the suppressed rule violations to the report.suppressedMarker(String marker) 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
-
Constructor Details
-
PmdOperation
public PmdOperation()
-
-
Method Details
-
execute
Performs the PMD code analysis operation.- Specified by:
executein classAbstractOperation<PmdOperation>- Throws:
Exception- if the analysis fails to executeExitStatusException- if violations or errors occur andfailOnViolationorfailOnErroris true
-
cache
Sets the location of the cache file for incremental analysis.- Parameters:
path- the cache file path- Returns:
- this operation
- Throws:
NullPointerException- ifpathisnull- See Also:
-
cache
Sets the location of the cache file for incremental analysis.- Parameters:
file- the cache file- Returns:
- this operation
- Throws:
NullPointerException- iffileisnull- See Also:
-
cache
Sets the location of the cache file for incremental analysis.- Parameters:
cache- the cache file path- Returns:
- this operation
- Throws:
NullPointerException- ifcacheisnullIllegalArgumentException- ifcacheis empty- See Also:
-
collectFilesRecursively
When specified, any directory mentioned withinputPaths()will only be searched for files that are direct children. By default, subdirectories are recursively included.- Parameters:
collectFilesRecursively- whether to collect files recursively or not- Returns:
- this operation
- Since:
- 1.3.0
-
defaultLanguageVersions
Sets the default language version to be used for all input files.- Parameters:
languageVersions- one or more language versions- Returns:
- this operation
- Throws:
NullPointerException- iflanguageVersionsisnullIllegalArgumentException- iflanguageVersionsis empty, or containsnullelements- See Also:
-
defaultLanguageVersions
public final PmdOperation defaultLanguageVersions(@NonNull Collection<LanguageVersion> languageVersions) Sets the default language version to be used for all input files.- Parameters:
languageVersions- a collection of language versions- Returns:
- this operation
- Throws:
NullPointerException- iflanguageVersionsisnullIllegalArgumentException- iflanguageVersionsis empty, or containsnullelements- See Also:
-
defaultLanguageVersions
Returns the default language versions.- Returns:
- the language versions
- See Also:
-
encoding
Specifies the character set encoding of the source code files. The default isUTF-8.The valid values are the standard character sets of
Charset.- Parameters:
encoding- the encoding name- Returns:
- this operation
- Throws:
NullPointerException- ifencodingisnullIllegalArgumentException- ifencodingis empty- See Also:
-
encoding
Specifies the character set encoding of the source code files. The default isUTF-8.The valid values are the standard character sets of
Charset.- Parameters:
encoding- the charset- Returns:
- this operation
- Throws:
NullPointerException- ifencodingisnull- See Also:
-
excludes
Returns the paths to exclude from the analysis.- Returns:
- the exclude paths
- See Also:
-
excludes
Sets paths to exclude from the analysis.- Parameters:
paths- one or more paths to exclude- Returns:
- this operation
- Throws:
NullPointerException- ifpathsisnullIllegalArgumentException- ifpathsis empty, or containsnullelements- See Also:
-
excludes
Sets paths to exclude from the analysis.- Parameters:
paths- paths to exclude- Returns:
- this operation
- Throws:
NullPointerException- ifpathsisnullIllegalArgumentException- ifpathsis empty, or containsnullelements- See Also:
-
excludesFiles
Sets paths to exclude from the analysis.- Parameters:
files- one or more paths to exclude- Returns:
- this operation
- Throws:
NullPointerException- iffilesisnullIllegalArgumentException- iffilesis empty, or containsnullelements- Since:
- 1.2
- See Also:
-
excludesFiles
Sets paths to exclude from the analysis.- Parameters:
files- a collection of paths to exclude- Returns:
- this operation
- Throws:
NullPointerException- iffilesisnullIllegalArgumentException- iffilesis empty, or containsnullelements- Since:
- 1.2
- See Also:
-
excludesStrings
Sets paths to exclude from the analysis.- Parameters:
excludes- one or more paths to exclude- Returns:
- this operation
- Throws:
NullPointerException- ifexcludesisnullIllegalArgumentException- ifexcludesis empty, or containsnullor empty elements- Since:
- 1.2
- See Also:
-
excludesStrings
Sets paths to exclude from the analysis.- Parameters:
excludes- a collection of paths to exclude- Returns:
- this operation
- Throws:
NullPointerException- ifexcludesisnullIllegalArgumentException- ifexcludesis empty, or containsnullor empty elements- Since:
- 1.2
- See Also:
-
failOnError
Sets whether the build will exit on recoverable errors.Default is:
trueNote: 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
- See Also:
-
forceLanguageVersion
Forces a language to be used for all input files, irrespective of file names.- Parameters:
languageVersion- the language version- Returns:
- this operation
- Throws:
NullPointerException- iflanguageVersionisnull
-
fromProject
Configures a PMD operation from aBaseProject.The defaults are:
- cache=
build/pmd/pmd-cache, if not already set - encoding=
UTF-8 - incrementalAnalysis=
true - inputPaths=
[src/main, src/test], if not already set - reportFile=
build/pmd/pmd-report.txt, if not already set - reportFormat=
text - rulePriority=
LOW - ruleSets=
JavaRules.QUICK_START, if not already set - suppressedMarker=
NOPMD - threads=1
- Parameters:
project- the project- Returns:
- this operation
- Throws:
NullPointerException- ifprojectisnull
- cache=
-
ignoreFile
Sets the path to the file containing a list of files to ignore, one path per line.- Parameters:
path- the ignore file path- Returns:
- this operation
- Throws:
NullPointerException- ifpathisnull- See Also:
-
ignoreFile
Sets the path to the file containing a list of files to ignore, one path per line.- Parameters:
file- the ignore file- Returns:
- this operation
- Throws:
NullPointerException- iffileisnull- See Also:
-
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
- Throws:
NullPointerException- ifignoreFileisnullIllegalArgumentException- ifignoreFileis empty- See Also:
-
includeLineNumber
Enables or disables line number in source file URIs.While clicking on the URI works in IntelliJ IDEA, Visual Studio Code, etc.; it might not in terminal emulators.
Default:
true- Parameters:
includeLineNumber- whether to include the line number in source file URIs- Returns:
- this operation
-
incrementalAnalysis
Enables or disables incremental analysis.- Parameters:
incrementalAnalysis- whether to enable incremental analysis- Returns:
- this operation
-
inputPaths
Returns paths to source files or directories containing source files to analyze.- Returns:
- the input paths
- See Also:
-
inputPaths
Sets paths to source files or directories containing source files to analyze.- Parameters:
paths- one or more paths- Returns:
- this operation
- Throws:
NullPointerException- ifpathsisnullIllegalArgumentException- ifpathsis empty, or containsnullelements- See Also:
-
inputPaths
Sets paths to source files or directories containing source files to analyze.- Parameters:
files- one or more paths- Returns:
- this operation
- Throws:
NullPointerException- iffilesisnullIllegalArgumentException- iffilesis empty, or containsnullelements- See Also:
-
inputPaths
Sets paths to source files or directories containing source files to analyze.- Parameters:
inputPaths- one or more paths- Returns:
- this operation
- Throws:
NullPointerException- ifinputPathsisnullIllegalArgumentException- ifinputPathsis empty, or containsnullor empty elements- See Also:
-
inputPaths
Sets paths to source files or directories containing source files to analyze.- Parameters:
paths- a collection of input paths- Returns:
- this operation
- Throws:
NullPointerException- ifpathsisnullIllegalArgumentException- ifpathsis empty, or containsnullelements- See Also:
-
inputPathsFiles
Sets paths to source files or directories containing source files to analyze.- Parameters:
files- a collection of input paths- Returns:
- this operation
- Throws:
NullPointerException- iffilesisnullIllegalArgumentException- iffilesis empty, or containsnullelements- See Also:
-
inputPathsStrings
Sets paths to source files or directories containing source files to analyze.- Parameters:
inputPaths- a collection of input paths- Returns:
- this operation
- Throws:
NullPointerException- ifinputPathsisnullIllegalArgumentException- ifinputPathsis empty, or containsnullor empty elements- See Also:
-
minimumPriority
Sets the minimum priority threshold when loading Rules from RuleSets.- Parameters:
priority- the minimum rule priority- Returns:
- this operation
- Throws:
NullPointerException- ifpriorityisnull
-
performAnalysis
public PmdAnalysisResults performAnalysis(@NonNull PMDConfiguration config) throws ExitStatusException Performs the PMD analysis with the given config.- Parameters:
config- the configuration- Returns:
- the analysis results
- Throws:
NullPointerException- ifconfigisnullExitStatusException- if violations or errors occur andfailOnViolationorfailOnErroris true
-
prependAuxClasspath
Prepend the specified classpaths-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 classpaths 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 classpaths.- Parameters:
classpaths- one or more classpaths entries- Returns:
- this operation
- Throws:
NullPointerException- ifclasspathsisnullIllegalArgumentException- ifclasspathsis empty, or containsnullelements- See Also:
-
prependAuxClasspath
Returns the prepended classpath.- Returns:
- the classpath
- See Also:
-
relativizeRoots
Adds several paths to shorten paths that are output in the report.- Parameters:
roots- one or more relative root paths- Returns:
- this operation
- Throws:
NullPointerException- ifrootsisnullIllegalArgumentException- ifrootsis empty, or containsnullelements- See Also:
-
relativizeRoots
Adds several paths to shorten paths that are output in the report.- Parameters:
roots- one or more relative root paths- Returns:
- this operation
- Throws:
NullPointerException- ifrootsisnullIllegalArgumentException- ifrootsis empty, or containsnullorvelements- See Also:
-
relativizeRoots
Adds several paths to shorten paths that are output in the report.- Parameters:
roots- one or more relative root paths- Returns:
- this operation
- Throws:
NullPointerException- ifrootsisnullIllegalArgumentException- ifrootsis empty, or containsnullor empty elements- See Also:
-
relativizeRoots
Adds several paths to shorten paths that are output in the report.- Parameters:
roots- a collection of relative root paths- Returns:
- this operation
- Throws:
NullPointerException- ifrootsisnullIllegalArgumentException- ifrootsis empty, or containsnullelements- See Also:
-
relativizeRoots
Returns paths to shorten paths that are output in the report.- Returns:
- the relative root paths
- See Also:
-
relativizeRootsFiles
Adds several paths to shorten paths that are output in the report.- Parameters:
roots- a collection of relative root paths- Returns:
- this operation
- Throws:
NullPointerException- ifrootsisnullIllegalArgumentException- ifrootsis empty, or containsnullelements- See Also:
-
relativizeRootsStrings
Adds several paths to shorten paths that are output in the report.- Parameters:
roots- a collection of relative root paths- Returns:
- this operation
- Throws:
NullPointerException- ifrootsisnullIllegalArgumentException- ifrootsis empty, or containsnullor empty elements- See Also:
-
reportFile
Sets the path to the report page.- Parameters:
path- the report file path- Returns:
- this operation
- Throws:
NullPointerException- ifpathisnull- See Also:
-
reportFile
Sets the path to the report page.- Parameters:
file- the report file- Returns:
- this operation
- Throws:
NullPointerException- iffileisnull- See Also:
-
reportFile
Sets the path to the report page.- Parameters:
reportFile- the report file path- Returns:
- this operation
- Throws:
NullPointerException- ifreportFileisnullIllegalArgumentException- ifreportFileis empty- See Also:
-
reportFile
Returns the path to the report file.- Returns:
- the report file path
- See Also:
-
reportFormat
Sets the output format of the analysis report. The default istext.- Parameters:
format- the report format- Returns:
- this operation
- Throws:
NullPointerException- ifformatisnullIllegalArgumentException- ifformatis empty
-
reportProperties
Sets the Report properties. These are used to create the Renderer.- Parameters:
properties- the report properties- Returns:
- this operation
- Throws:
NullPointerException- ifpropertiesisnull
-
ruleSets
Returns the rule set paths.- Returns:
- the rule sets
- See Also:
-
ruleSets
Sets rule set paths.- Parameters:
ruleSets- one or more rule set paths- Returns:
- this operation
- Throws:
NullPointerException- ifruleSetsisnullIllegalArgumentException- ifruleSetsis empty, or containsnullor empty elements- See Also:
-
ruleSets
Sets rule set paths.- Parameters:
ruleSets- a collection of rule set paths- Returns:
- this operation
- Throws:
NullPointerException- ifruleSetsisnullIllegalArgumentException- ifruleSetsis empty, or containsnullor empty elements- See Also:
-
ruleSets
Sets rule set paths.- Parameters:
ruleSets- one or more rule sets- Returns:
- this operation
- Throws:
NullPointerException- ifruleSetsisnullIllegalArgumentException- ifruleSetsis empty, or containsnullelements- Since:
- 1.5
- See Also:
-
ruleSetsRules
Sets rule set paths.- Parameters:
ruleSets- a collection of rule sets- Returns:
- this operation
- Throws:
NullPointerException- ifruleSetsisnullIllegalArgumentException- ifruleSetsis empty, or containsnullelements- Since:
- 1.5
- See Also:
-
showSuppressed
Enables or disables adding the suppressed rule violations to the report.- Parameters:
showSuppressed- whether to add suppressed violations to the report- Returns:
- this operation
-
suppressedMarker
Specifies the comment token that marks lines which should be ignored. The default isNOPMD.- Parameters:
marker- the suppressed marker token- Returns:
- this operation
- Throws:
NullPointerException- ifmarkerisnullIllegalArgumentException- ifmarkeris empty
-
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
- Throws:
NullPointerException- ifinputUriisnull
-