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 protectedAbstractConfiguration(LanguageRegistry languageRegistry, MessageReporter messageReporter)
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description voidaddInputPath(@NonNull Path inputPath)Add an input path.voidaddRelativizeRoot(Path path)Set the path used to shorten paths output in the report.voidaddRelativizeRoots(List<Path> paths)Add several paths to shorten paths that are output in the report.booleancollectFilesRecursively()voidcollectFilesRecursively(boolean collectRecursive)List<Path>getExcludes()LanguageVersiongetForceLanguageVersion()Get the LanguageVersion specified by the force-language parameter.@Nullable PathgetIgnoreFile()Returns the path to the file list exclude file.@Nullable PathgetInputFile()Returns the path to the file list include file.@NonNull List<Path>getInputPathList()Returns the list of input paths to explore.@NonNull LanguagePropertyBundlegetLanguageProperties(Language language)Returns a mutable bundle of language properties that are associated to the given language (always the same for a given language).LanguageRegistrygetLanguageRegistry()LanguageVersionDiscoverergetLanguageVersionDiscoverer()Get the LanguageVersionDiscoverer, used to determine the LanguageVersion of a source file.@Nullable LanguageVersiongetLanguageVersionOfFile(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 MessageReportergetReporter()Returns the message reporter that is to be used while running the analysis.CharsetgetSourceEncoding()Get the character encoding of source files.URIgetUri()Get the input URI to process for source code objects.booleanisForceLanguageVersion()Is the force-language parameter set to anything?voidsetDefaultLanguageVersion(LanguageVersion languageVersion)Set the given LanguageVersion as the current default for it's Language.voidsetDefaultLanguageVersions(List<LanguageVersion> languageVersions)Set the given LanguageVersions as the current default for their Languages.voidsetExcludes(List<Path> excludes)voidsetForceLanguageVersion(@Nullable LanguageVersion forceLanguageVersion)Set the LanguageVersion specified by the force-language parameter.voidsetIgnoreFilePath(String ignoreFilePath)Deprecated.voidsetIgnoreFilePath(Path ignoreFilePath)The input file path points to a single file, which contains a comma-separated list of source file names to ignore.voidsetInputFilePath(String inputFilePath)Deprecated.voidsetInputFilePath(Path inputFilePath)The input file path points to a single file, which contains a comma-separated list of source file names to process.voidsetInputPathList(List<Path> inputPaths)Set the input paths to the given list of paths.voidsetInputPaths(String inputPaths)Deprecated.voidsetInputUri(String inputUri)Deprecated.UsesetInputUri(URI)voidsetInputUri(URI inputUri)Set the input URI to process for source code objects.voidsetOnlyRecognizeLanguage(Language lang)Make it so that the only extensions that are considered are those of the given language.voidsetReporter(@NonNull MessageReporter reporter)Sets the message reporter that is to be used while running the analysis.voidsetSourceEncoding(Charset sourceEncoding)Set the character encoding of source files.
-
-
-
Constructor Detail
-
AbstractConfiguration
protected AbstractConfiguration(LanguageRegistry languageRegistry, MessageReporter 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 MessageReporter getReporter()
Returns the message reporter that is to be used while running the analysis.
-
setReporter
public void setReporter(@NonNull MessageReporter 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.
-
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.
-
setInputPaths
@Deprecated public void setInputPaths(String inputPaths)
Deprecated.Set the comma separated list of input paths to process for source files.- Parameters:
inputPaths- The comma separated list.- Throws:
NullPointerException- If the parameter is null
-
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
@Deprecated public void setInputFilePath(String inputFilePath)
Deprecated.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
-
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
@Deprecated public void setIgnoreFilePath(String ignoreFilePath)
Deprecated.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
-
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
-
setInputUri
@Deprecated public void setInputUri(String inputUri)
Deprecated.UsesetInputUri(URI)Set the input URI to process for source code objects.- Parameters:
inputUri- a single URI
-
collectFilesRecursively
public boolean collectFilesRecursively()
-
collectFilesRecursively
public void collectFilesRecursively(boolean collectRecursive)
-
-