Package net.sourceforge.pmd
Class AbstractConfiguration
java.lang.Object
net.sourceforge.pmd.AbstractConfiguration
- Direct Known Subclasses:
CPDConfiguration
,PMDConfiguration
,TreeExportConfiguration
Base configuration class for both PMD and CPD.
- Author:
- Brian Remedios
-
Constructor Summary
ConstructorsModifierConstructorDescriptionprotected
AbstractConfiguration
(LanguageRegistry languageRegistry, PmdReporter messageReporter) -
Method Summary
Modifier and TypeMethodDescriptionvoid
addInputPath
(@NonNull Path inputPath) Add an input path.void
addRelativizeRoot
(Path path) Set the path used to shorten paths output in the report.void
addRelativizeRoots
(List<Path> paths) Add several paths to shorten paths that are output in the report.protected void
Check that it is correct to use the given language with this configuration.boolean
void
collectFilesRecursively
(boolean collectRecursive) Get the LanguageVersion specified by the force-language parameter.@Nullable Path
Returns the path to the file list exclude file.@Nullable Path
Returns the path to the file list include file.Returns the list of input paths to explore.@NonNull LanguagePropertyBundle
getLanguageProperties
(Language language) Returns a mutable bundle of language properties that are associated to the given language (always the same for a given language).Get the LanguageVersionDiscoverer, used to determine the LanguageVersion of a source file.@Nullable LanguageVersion
getLanguageVersionOfFile
(String fileName) Get the LanguageVersion of the source file with given name.Returns the paths used to shorten paths output in the report.@NonNull PmdReporter
Returns the message reporter that is to be used while running the analysis.@Nullable Path
Get the file to which the report should render.Get the character encoding of source files.getUri()
Get the input URI to process for source code objects.boolean
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.).boolean
Whether PMD should exit with status 4 (the default behavior, true) if violations are found or just with 0 (to not break the build, e.g.).boolean
Is the force-language parameter set to anything?void
setDefaultLanguageVersion
(LanguageVersion languageVersion) Set the given LanguageVersion as the current default for its Language.void
setDefaultLanguageVersions
(List<LanguageVersion> languageVersions) Set the given LanguageVersions as the current default for their Languages.void
setExcludes
(List<Path> excludes) void
setFailOnError
(boolean failOnError) Sets 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.).void
setFailOnViolation
(boolean failOnViolation) Sets whether PMD should exit with status 4 (the default behavior, true) if violations are found or just with 0 (to not break the build, e.g.).void
setForceLanguageVersion
(@Nullable LanguageVersion forceLanguageVersion) Set the LanguageVersion specified by the force-language parameter.void
setIgnoreFilePath
(Path ignoreFilePath) The input file path points to a single file, which contains a comma-separated list of source file names to ignore.void
setInputFilePath
(Path inputFilePath) The input file path points to a single file, which contains a comma-separated list of source file names to process.void
setInputPathList
(List<Path> inputPaths) Set the input paths to the given list of paths.void
setInputUri
(URI inputUri) Set the input URI to process for source code objects.void
Make it so that the only extensions that are considered are those of the given language.void
setReporter
(@NonNull PmdReporter reporter) Sets the message reporter that is to be used while running the analysis.void
setReportFile
(@Nullable Path reportFile) Set the file to which the report should render.void
setSourceEncoding
(Charset sourceEncoding) Set the character encoding of source files.
-
Constructor Details
-
AbstractConfiguration
-
-
Method Details
-
getSourceEncoding
Get the character encoding of source files.- Returns:
- The character encoding.
-
setSourceEncoding
Set the character encoding of source files.- Parameters:
sourceEncoding
- The character encoding.
-
getLanguageProperties
Returns a mutable bundle of language properties that are associated to the given language (always the same for a given language).- Parameters:
language
- A language, which must be registered
-
getLanguageRegistry
-
getReporter
Returns the message reporter that is to be used while running the analysis. -
setReporter
Sets the message reporter that is to be used while running the analysis.- Parameters:
reporter
- A non-null message reporter
-
getLanguageVersionDiscoverer
Get the LanguageVersionDiscoverer, used to determine the LanguageVersion of a source file.- Returns:
- The LanguageVersionDiscoverer.
-
getForceLanguageVersion
Get the LanguageVersion specified by the force-language parameter. This overrides detection based on file extensions- Returns:
- The LanguageVersion.
-
isForceLanguageVersion
public boolean isForceLanguageVersion()Is the force-language parameter set to anything?- Returns:
- true if $
getForceLanguageVersion()
is not null
-
setForceLanguageVersion
Set the LanguageVersion specified by the force-language parameter. This overrides detection based on file extensions- Parameters:
forceLanguageVersion
- the language version
-
setOnlyRecognizeLanguage
Make it so that the only extensions that are considered are those of the given language. This is different fromsetForceLanguageVersion(LanguageVersion)
because that one will assign the given language version to all files irrespective of extension. This method, on the other hand, will ignore files that do not match the given language.- Parameters:
lang
- A language
-
setDefaultLanguageVersion
Set the given LanguageVersion as the current default for its Language.- Parameters:
languageVersion
- the LanguageVersion
-
setDefaultLanguageVersions
Set the given LanguageVersions as the current default for their Languages.- Parameters:
languageVersions
- The LanguageVersions.
-
checkLanguageIsAcceptable
Check that it is correct to use the given language with this configuration.- Throws:
UnsupportedOperationException
- if the language isn't supported.
-
getLanguageVersionOfFile
Get the LanguageVersion of the source file with given name. This depends on the fileName extension, and the java version.For compatibility with older code that does not always pass in a correct filename, unrecognized files are assumed to be java files.
- Parameters:
fileName
- Name of the file, can be absolute, or simple.- Returns:
- the LanguageVersion
-
addRelativizeRoot
Set the path used to shorten paths output in the report. The path does not need to exist. If it exists, it must point to a directory and not a file. SeegetRelativizeRoots()
for the interpretation.If several paths are added, the shortest paths possible are built.
- Parameters:
path
- A path- Throws:
IllegalArgumentException
- If the path points to a file, and not a directoryNullPointerException
- If the path is null
-
addRelativizeRoots
Add several paths to shorten paths that are output in the report. SeeaddRelativizeRoot(Path)
.- Parameters:
paths
- A list of non-null paths- Throws:
IllegalArgumentException
- If any path points to a file, and not a directoryNullPointerException
- If the list, or any path in the list is null
-
getRelativizeRoots
Returns the paths used to shorten paths output in the report.- If the list is empty, then paths are not touched
- If the list is non-empty, then source file paths are relativized with all the items in the list. The shortest of these relative paths is taken as the display name of the file.
-
getUri
Get the input URI to process for source code objects.- Returns:
- URI
-
setInputUri
Set the input URI to process for source code objects.- Parameters:
inputUri
- a single URI
-
getInputPathList
Returns the list of input paths to explore. This is an unmodifiable list. -
setInputPathList
Set the input paths to the given list of paths.- Throws:
NullPointerException
- If the parameter is null or contains a null value
-
addInputPath
Add an input path. It is not split on commas.- Throws:
NullPointerException
- If the parameter is null
-
getInputFile
Returns the path to the file list include file. -
getIgnoreFile
Returns the path to the file list exclude file. -
setInputFilePath
The input file path points to a single file, which contains a comma-separated list of source file names to process.- Parameters:
inputFilePath
- path to the file
-
setIgnoreFilePath
The input file path points to a single file, which contains a comma-separated list of source file names to ignore.- Parameters:
ignoreFilePath
- path to the file
-
getExcludes
-
setExcludes
-
collectFilesRecursively
public boolean collectFilesRecursively() -
collectFilesRecursively
public void collectFilesRecursively(boolean collectRecursive) -
getReportFilePath
Get the file to which the report should render. If null, the report is rendered on stdout.- Returns:
- The file to which to render.
- Since:
- 7.14.0 (was previously only available on
PMDConfiguration
)
-
setReportFile
Set the file to which the report should render.- Parameters:
reportFile
- the file to set- Since:
- 7.14.0 (was previously only available on
PMDConfiguration
)
-
isFailOnViolation
public boolean isFailOnViolation()Whether PMD should exit with status 4 (the default behavior, true) if violations are found or just with 0 (to not break the build, e.g.).Note: If additionally recoverable errors occurred, the exit status is 5. See
isFailOnError()
.- Returns:
- failOnViolation
- Since:
- 6.0.0
- See Also:
-
setFailOnViolation
public void setFailOnViolation(boolean failOnViolation) Sets whether PMD should exit with status 4 (the default behavior, true) if violations are found or just with 0 (to not break the build, e.g.).Note: If additionally recoverable errors occurred, the exit status is 5. See
isFailOnError()
.- Parameters:
failOnViolation
- whether to exit with 4 and fail the build if violations are found.- Since:
- 6.0.0
- See Also:
-
isFailOnError
public boolean isFailOnError()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.).Note: If only violations are found, the exit status is 4. See
isFailOnViolation()
.- Returns:
- failOnError
- Since:
- 7.3.0
- See Also:
-
setFailOnError
public void setFailOnError(boolean failOnError) Sets 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.).Note: If only violations are found, the exit status is 4. See
isFailOnViolation()
.- Parameters:
failOnError
- whether to exit with 5 and fail the build if recoverable errors occurred.- Since:
- 7.3.0
- See Also:
-