Package net.sourceforge.pmd
Class PMD
- java.lang.Object
-
- net.sourceforge.pmd.PMD
-
public class PMD extends java.lang.ObjectThis 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.
-
-
Field Summary
Fields Modifier and Type Field Description protected PMDConfigurationconfigurationContains the configuration with which this PMD instance has been created.static java.lang.StringEOLThe line delimiter used by PMD in outputs.static java.lang.StringSUPPRESS_MARKERThe default suppress marker string.static java.lang.StringVERSIONDeprecated.UsePMDVersion.VERSIONinstead.
-
Constructor Summary
Constructors Constructor Description PMD()Create a PMD instance using a default Configuration.PMD(PMDConfiguration configuration)Create a PMD instance using the specified Configuration.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static intdoPMD(PMDConfiguration configuration)This method is the main entry point for command line usage.static java.util.List<DataSource>getApplicableFiles(PMDConfiguration configuration, java.util.Set<Language> languages)Determines all the files, that should be analyzed by PMD.PMDConfigurationgetConfiguration()Get the runtime configuration.SourceCodeProcessorgetSourceCodeProcessor()Gets the source code processor.static java.util.List<DataSource>getURIDataSources(java.lang.String uriString)Parses the given string as a database uri and returns a list of datasources.static voidmain(java.lang.String[] args)Entry to invoke PMD as command line toolstatic RuleContextnewRuleContext(java.lang.String sourceCodeFilename, java.io.File sourceCodeFile)Creates a new rule context, initialized with a new, empty report.static ParserparserFor(LanguageVersion languageVersion, PMDConfiguration configuration)Helper method to get a configured parser for the requested language.static voidprocessFiles(PMDConfiguration configuration, RuleSetFactory ruleSetFactory, java.util.List<DataSource> files, RuleContext ctx, java.util.List<Renderer> renderers)Run PMD on a list of files using multiple threads - if more than one is availablestatic intrun(java.lang.String[] args)Parses the command line arguments and executes PMD.
-
-
-
Field Detail
-
EOL
public static final java.lang.String EOL
The line delimiter used by PMD in outputs. Usually the platform specific line separator.
-
SUPPRESS_MARKER
public static final java.lang.String SUPPRESS_MARKER
The default suppress marker string.- See Also:
- Constant Field Values
-
configuration
protected final PMDConfiguration configuration
Contains the configuration with which this PMD instance has been created.
-
VERSION
@Deprecated public static final java.lang.String VERSION
Deprecated.UsePMDVersion.VERSIONinstead.Constant that contains always the current version of PMD.
-
-
Constructor Detail
-
PMD
public PMD()
Create a PMD instance using a default Configuration. Changes to the configuration may be required.
-
PMD
public PMD(PMDConfiguration configuration)
Create a PMD instance using the specified Configuration.- Parameters:
configuration- The runtime Configuration of PMD to use.
-
-
Method Detail
-
getURIDataSources
public static java.util.List<DataSource> getURIDataSources(java.lang.String uriString) throws PMDException
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
public static Parser parserFor(LanguageVersion languageVersion, PMDConfiguration configuration)
Helper 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
public PMDConfiguration getConfiguration()
Get the runtime configuration. The configuration can be modified to affect how PMD behaves.- Returns:
- The configuration.
- See Also:
PMDConfiguration
-
getSourceCodeProcessor
public SourceCodeProcessor getSourceCodeProcessor()
Gets the source code processor.- Returns:
- SourceCodeProcessor
-
doPMD
public static int doPMD(PMDConfiguration configuration)
This method is the main entry point for command line usage.- Parameters:
configuration- the configure to use- Returns:
- number of violations found.
-
newRuleContext
public static RuleContext newRuleContext(java.lang.String sourceCodeFilename, java.io.File sourceCodeFile)
Creates 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
public static void processFiles(PMDConfiguration configuration, RuleSetFactory ruleSetFactory, java.util.List<DataSource> files, RuleContext ctx, java.util.List<Renderer> renderers)
Run PMD on a list of files using multiple threads - if more than one is available- Parameters:
configuration- ConfigurationruleSetFactory- RuleSetFactoryfiles- List ofDataSourcesctx- RuleContextrenderers- List ofRenderers
-
getApplicableFiles
public static java.util.List<DataSource> getApplicableFiles(PMDConfiguration configuration, java.util.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
DataSourceof files
-
main
public static void main(java.lang.String[] args)
Entry to invoke PMD as command line tool- Parameters:
args- command line arguments
-
run
public static int run(java.lang.String[] args)
Parses the command line arguments and executes PMD.- Parameters:
args- command line arguments- Returns:
- the exit code, where
0means successful execution,1means error,4means there have been violations found.
-
-