Package net.sourceforge.pmd
Class PMD
- java.lang.Object
-
- net.sourceforge.pmd.PMD
-
public class PMD extends Object
This is the main class for interacting with PMD. The primary flow of all Rule process is controlled via interactions with this class. A command line interface is supported, as well as a programmatic API for integrating PMD with other software such as IDEs and Ant.Main entrypoints are:
main(String[])
which exits the java processrunPmd(String...)
which returns aPMD.StatusCode
runPmd(PMDConfiguration)
processFiles(PMDConfiguration, List, Collection, List)
Warning: This class is not intended to be instantiated or subclassed. It will be made final in PMD7.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
PMD.StatusCode
Represents status codes that are used as exit codes during CLI runs.
-
Field Summary
Fields Modifier and Type Field Description protected PMDConfiguration
configuration
Deprecated.this configuration field is unused and will be removed.static String
EOL
The line delimiter used by PMD in outputs.static String
SUPPRESS_MARKER
The default suppress marker string.static String
VERSION
Deprecated.UsePMDVersion.VERSION
instead.
-
Constructor Summary
Constructors Constructor Description PMD()
Deprecated.Just use the static methods, and maintain yourPMDConfiguration
separately.PMD(PMDConfiguration configuration)
Deprecated.Just use the static methods, and maintain yourPMDConfiguration
separately.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description static int
doPMD(PMDConfiguration configuration)
Deprecated.static List<DataSource>
getApplicableFiles(PMDConfiguration configuration, Set<Language> languages)
Determines all the files, that should be analyzed by PMD.PMDConfiguration
getConfiguration()
Deprecated.Don't create a PMD instance just to create aPMDConfiguration
SourceCodeProcessor
getSourceCodeProcessor()
Deprecated.Source code processor is internalstatic List<DataSource>
getURIDataSources(String uriString)
Deprecated.Will be hidden as part of the parsing ofgetApplicableFiles(PMDConfiguration, Set)
static void
main(String[] args)
Entry to invoke PMD as command line tool.static RuleContext
newRuleContext(String sourceCodeFilename, File sourceCodeFile)
Deprecated.Not usefulstatic Parser
parserFor(LanguageVersion languageVersion, PMDConfiguration configuration)
Deprecated.This is internalstatic Report
processFiles(PMDConfiguration configuration, List<RuleSet> rulesets, Collection<? extends DataSource> files, List<Renderer> renderers)
Run PMD using the given configuration.static void
processFiles(PMDConfiguration configuration, RuleSetFactory ruleSetFactory, List<DataSource> files, RuleContext ctx, List<Renderer> renderers)
Deprecated.UseprocessFiles(PMDConfiguration, List, Collection, List)
so as not to depend onRuleSetFactory
.static int
run(String[] args)
Deprecated.UserunPmd(String...)
.static PMD.StatusCode
runPmd(String... args)
Parses the command line arguments and executes PMD.static PMD.StatusCode
runPmd(PMDConfiguration configuration)
Execute PMD from a configuration.
-
-
-
Field Detail
-
EOL
public static final String EOL
The line delimiter used by PMD in outputs. Usually the platform specific line separator.
-
SUPPRESS_MARKER
public static final String SUPPRESS_MARKER
The default suppress marker string.- See Also:
- Constant Field Values
-
configuration
@Deprecated protected final PMDConfiguration configuration
Deprecated.this configuration field is unused and will be removed. The classPMD
should not be instantiated or subclassed.Contains the configuration with which this PMD instance has been created.
-
VERSION
@Deprecated public static final String VERSION
Deprecated.UsePMDVersion.VERSION
instead.Constant that contains always the current version of PMD.
-
-
Constructor Detail
-
PMD
@Deprecated public PMD()
Deprecated.Just use the static methods, and maintain yourPMDConfiguration
separately.Create a PMD instance using a default Configuration. Changes to the configuration may be required.
-
PMD
@Deprecated public PMD(PMDConfiguration configuration)
Deprecated.Just use the static methods, and maintain yourPMDConfiguration
separately.Create a PMD instance using the specified Configuration.- Parameters:
configuration
- The runtime Configuration of PMD to use.
-
-
Method Detail
-
getURIDataSources
@Deprecated public static List<DataSource> getURIDataSources(String uriString) throws PMDException
Deprecated.Will be hidden as part of the parsing ofgetApplicableFiles(PMDConfiguration, Set)
Parses the given string as a database uri and returns a list of datasources.- Parameters:
uriString
- the URI to parse- Returns:
- list of data sources
- Throws:
PMDException
- if the URI couldn't be parsed- See Also:
DBURI
-
parserFor
@Deprecated @InternalApi public static Parser parserFor(LanguageVersion languageVersion, PMDConfiguration configuration)
Deprecated.This is internalHelper method to get a configured parser for the requested language. The parser is configured based on the givenPMDConfiguration
.- Parameters:
languageVersion
- the requested languageconfiguration
- the given configuration- Returns:
- the pre-configured parser
-
getConfiguration
@Deprecated public PMDConfiguration getConfiguration()
Deprecated.Don't create a PMD instance just to create aPMDConfiguration
Get the runtime configuration. The configuration can be modified to affect how PMD behaves.- Returns:
- The configuration.
- See Also:
PMDConfiguration
-
getSourceCodeProcessor
@Deprecated public SourceCodeProcessor getSourceCodeProcessor()
Deprecated.Source code processor is internalGets the source code processor.- Returns:
- SourceCodeProcessor
-
doPMD
@Deprecated public static int doPMD(PMDConfiguration configuration)
Deprecated.This method is the main entry point for command line usage.- Parameters:
configuration
- the configuration to use- Returns:
- number of violations found.
-
newRuleContext
@Deprecated public static RuleContext newRuleContext(String sourceCodeFilename, File sourceCodeFile)
Deprecated.Not usefulCreates a new rule context, initialized with a new, empty report.- Parameters:
sourceCodeFilename
- the source code filenamesourceCodeFile
- the source code file- Returns:
- the rule context
-
processFiles
@Deprecated public static void processFiles(PMDConfiguration configuration, RuleSetFactory ruleSetFactory, List<DataSource> files, RuleContext ctx, List<Renderer> renderers)
Deprecated.UseprocessFiles(PMDConfiguration, List, Collection, List)
so as not to depend onRuleSetFactory
. Note that this sorts the list of data sources in-place, which won't be fixedRun PMD on a list of files using multiple threads - if more than one is available- Parameters:
configuration
- ConfigurationruleSetFactory
- RuleSetFactoryfiles
- List ofDataSource
sctx
- RuleContextrenderers
- List ofRenderer
s
-
processFiles
public static Report processFiles(PMDConfiguration configuration, List<RuleSet> rulesets, Collection<? extends DataSource> files, List<Renderer> renderers)
Run PMD using the given configuration. This replaces the other overload.- Parameters:
configuration
- Configuration for the run. Note that the files, and rulesets, are ignored, as they are supplied as parametersrulesets
- Parsed rulesetsfiles
- Files to process, will be closed by this method.renderers
- Renderers that render the report- Returns:
- Report in which violations are accumulated
- Throws:
RuntimeException
- If processing fails
-
getApplicableFiles
public static List<DataSource> getApplicableFiles(PMDConfiguration configuration, Set<Language> languages)
Determines all the files, that should be analyzed by PMD.- Parameters:
configuration
- contains either the file path or the DB URI, from where to load the fileslanguages
- used to filter by file extension- Returns:
- List of
DataSource
of files
-
main
public static void main(String[] args)
Entry to invoke PMD as command line tool. Note that this will invokeSystem.exit(int)
.- Parameters:
args
- command line arguments
-
run
@Deprecated public static int run(String[] args)
Deprecated.UserunPmd(String...)
.Parses the command line arguments and executes PMD. Returns the exit code without exiting the VM.- Parameters:
args
- command line arguments- Returns:
- the exit code, where
0
means successful execution,1
means error,4
means there have been violations found.
-
runPmd
public static PMD.StatusCode runPmd(String... args)
Parses the command line arguments and executes PMD. Returns the status code without exiting the VM. Note that the arguments parsing may itself fail and produce aPMD.StatusCode.ERROR
. This will print the error message to standard error.- Parameters:
args
- command line arguments- Returns:
- the status code. Note that
PMDConfiguration.isFailOnViolation()
(flag--failOnViolation
) may turn anPMD.StatusCode.OK
into aPMD.StatusCode.VIOLATIONS_FOUND
.
-
runPmd
public static PMD.StatusCode runPmd(PMDConfiguration configuration)
Execute PMD from a configuration. Returns the status code without exiting the VM. This is the main entry point to run a full PMD run with a manually created configuration.- Parameters:
configuration
- Configuration to run- Returns:
- the status code. Note that
PMDConfiguration.isFailOnViolation()
(flag--failOnViolation
) may turn anPMD.StatusCode.OK
into aPMD.StatusCode.VIOLATIONS_FOUND
.
-
-