Package net.sourceforge.pmd
Class PMD
- java.lang.Object
-
- net.sourceforge.pmd.PMD
-
public class PMD extends Object
Entry point for PMD's CLI. UserunPmd(PMDConfiguration)
orrunPmd(String...)
to mimic a CLI run. This class is not a supported programmatic API anymore, usePmdAnalysis
for fine control over the PMD integration and execution.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
Deprecated.static String
SUPPRESS_MARKER
Deprecated.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)
Deprecated.This may leak resources and should not be used directly.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)
Deprecated.UsePmdAnalysis
static void
processFiles(PMDConfiguration configuration, RuleSetFactory ruleSetFactory, List<DataSource> files, RuleContext ctx, List<Renderer> renderers)
Deprecated.UsePmdAnalysis
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
@Deprecated public static final String EOL
Deprecated.The line delimiter used by PMD in outputs. Usually the platform specific line separator.
-
SUPPRESS_MARKER
@Deprecated public static final String SUPPRESS_MARKER
Deprecated.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. This classPMD
should not be instantiated or subclassed. If you need a PMDConfiguration, create aPMDConfiguration
instance directly.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 @InternalApi public static int doPMD(PMDConfiguration configuration)
Deprecated.UserunPmd(PMDConfiguration)
. Note that the return value of doPMD changed in PMD 6.44.0 to return -1 in case of error. Previously zero was returned in that case.This method is the main entry point for command line usage.- Parameters:
configuration
- the configuration to use- Returns:
- number of violations found. Returns -1 in case of error.
-
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.UsePmdAnalysis
Run 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
@Deprecated public static Report processFiles(PMDConfiguration configuration, List<RuleSet> rulesets, Collection<? extends DataSource> files, List<Renderer> renderers)
Deprecated.UsePmdAnalysis
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
@Deprecated public static List<DataSource> getApplicableFiles(PMDConfiguration configuration, Set<Language> languages)
Deprecated.This may leak resources and should not be used directly. UsePmdAnalysis
.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
.
-
-