Package net.sourceforge.pmd
Class AbstractConfiguration
- java.lang.Object
-
- net.sourceforge.pmd.AbstractConfiguration
-
- Direct Known Subclasses:
CPDConfiguration
,PMDConfiguration
,TreeExportConfiguration
public abstract class AbstractConfiguration extends Object
Base configuration class for both PMD and CPD.- Author:
- Brian Remedios
-
-
Constructor Summary
Constructors Modifier Constructor Description protected
AbstractConfiguration(LanguageRegistry languageRegistry, PmdReporter messageReporter)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
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
checkLanguageIsAcceptable(Language lang)
Check that it is correct to use the given language with this configuration.boolean
collectFilesRecursively()
void
collectFilesRecursively(boolean collectRecursive)
List<Path>
getExcludes()
LanguageVersion
getForceLanguageVersion()
Get the LanguageVersion specified by the force-language parameter.@Nullable Path
getIgnoreFile()
Returns the path to the file list exclude file.@Nullable Path
getInputFile()
Returns the path to the file list include file.@NonNull List<Path>
getInputPathList()
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).LanguageRegistry
getLanguageRegistry()
LanguageVersionDiscoverer
getLanguageVersionDiscoverer()
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.List<Path>
getRelativizeRoots()
Returns the paths used to shorten paths output in the report.@NonNull PmdReporter
getReporter()
Returns the message reporter that is to be used while running the analysis.Charset
getSourceEncoding()
Get the character encoding of source files.URI
getUri()
Get the input URI to process for source code objects.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.).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.).boolean
isForceLanguageVersion()
Is the force-language parameter set to anything?void
setDefaultLanguageVersion(LanguageVersion languageVersion)
Set the given LanguageVersion as the current default for it's 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
setOnlyRecognizeLanguage(Language lang)
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
setSourceEncoding(Charset sourceEncoding)
Set the character encoding of source files.
-
-
-
Constructor Detail
-
AbstractConfiguration
protected AbstractConfiguration(LanguageRegistry languageRegistry, PmdReporter messageReporter)
-
-
Method Detail
-
getSourceEncoding
public Charset getSourceEncoding()
Get the character encoding of source files.- Returns:
- The character encoding.
-
setSourceEncoding
public void setSourceEncoding(Charset sourceEncoding)
Set the character encoding of source files.- Parameters:
sourceEncoding
- The character encoding.
-
getLanguageProperties
public @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).- Parameters:
language
- A language, which must be registered
-
getLanguageRegistry
public LanguageRegistry getLanguageRegistry()
-
getReporter
public @NonNull PmdReporter getReporter()
Returns the message reporter that is to be used while running the analysis.
-
setReporter
public void setReporter(@NonNull PmdReporter reporter)
Sets the message reporter that is to be used while running the analysis.- Parameters:
reporter
- A non-null message reporter
-
getLanguageVersionDiscoverer
public LanguageVersionDiscoverer getLanguageVersionDiscoverer()
Get the LanguageVersionDiscoverer, used to determine the LanguageVersion of a source file.- Returns:
- The LanguageVersionDiscoverer.
-
getForceLanguageVersion
public LanguageVersion 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
public void setForceLanguageVersion(@Nullable LanguageVersion forceLanguageVersion)
Set the LanguageVersion specified by the force-language parameter. This overrides detection based on file extensions- Parameters:
forceLanguageVersion
- the language version
-
setOnlyRecognizeLanguage
public void setOnlyRecognizeLanguage(Language lang)
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
public void setDefaultLanguageVersion(LanguageVersion languageVersion)
Set the given LanguageVersion as the current default for it's Language.- Parameters:
languageVersion
- the LanguageVersion
-
setDefaultLanguageVersions
public void setDefaultLanguageVersions(List<LanguageVersion> languageVersions)
Set the given LanguageVersions as the current default for their Languages.- Parameters:
languageVersions
- The LanguageVersions.
-
checkLanguageIsAcceptable
protected void checkLanguageIsAcceptable(Language lang) throws UnsupportedOperationException
Check that it is correct to use the given language with this configuration.- Throws:
UnsupportedOperationException
- if the language isn't supported.
-
getLanguageVersionOfFile
public @Nullable LanguageVersion getLanguageVersionOfFile(String fileName)
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
public void addRelativizeRoot(Path path)
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
public void addRelativizeRoots(List<Path> paths)
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
public List<Path> 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
public URI getUri()
Get the input URI to process for source code objects.- Returns:
- URI
-
setInputUri
public void setInputUri(URI inputUri)
Set the input URI to process for source code objects.- Parameters:
inputUri
- a single URI
-
getInputPathList
public @NonNull List<Path> getInputPathList()
Returns the list of input paths to explore. This is an unmodifiable list.
-
setInputPathList
public void setInputPathList(List<Path> inputPaths)
Set the input paths to the given list of paths.- Throws:
NullPointerException
- If the parameter is null or contains a null value
-
addInputPath
public void addInputPath(@NonNull Path inputPath)
Add an input path. It is not split on commas.- Throws:
NullPointerException
- If the parameter is null
-
getInputFile
public @Nullable Path getInputFile()
Returns the path to the file list include file.
-
getIgnoreFile
public @Nullable Path getIgnoreFile()
Returns the path to the file list exclude file.
-
setInputFilePath
public 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.- Parameters:
inputFilePath
- path to the file
-
setIgnoreFilePath
public 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.- Parameters:
ignoreFilePath
- path to the file
-
collectFilesRecursively
public boolean collectFilesRecursively()
-
collectFilesRecursively
public void collectFilesRecursively(boolean collectRecursive)
-
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:
isFailOnError()
-
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()
-
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:
isFailOnViolation()
-
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:
isFailOnViolation()
-
-