Class PMD


  • public class PMD
    extends Object
    Entry point for PMD's CLI. Use runPmd(PMDConfiguration) or runPmd(String...) to mimic a CLI run. This class is not a supported programmatic API anymore, use PmdAnalysis 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.

    • Constructor Detail

      • PMD

        @Deprecated
        public PMD()
        Deprecated.
        Just use the static methods, and maintain your PMDConfiguration 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 your PMDConfiguration separately.
        Create a PMD instance using the specified Configuration.
        Parameters:
        configuration - The runtime Configuration of PMD to use.
    • Method Detail

      • parserFor

        @Deprecated
        @InternalApi
        public static Parser parserFor​(LanguageVersion languageVersion,
                                       PMDConfiguration configuration)
        Deprecated.
        This is internal
        Helper method to get a configured parser for the requested language. The parser is configured based on the given PMDConfiguration.
        Parameters:
        languageVersion - the requested language
        configuration - the given configuration
        Returns:
        the pre-configured parser
      • getConfiguration

        @Deprecated
        public PMDConfiguration getConfiguration()
        Deprecated.
        Don't create a PMD instance just to create a PMDConfiguration
        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 internal
        Gets the source code processor.
        Returns:
        SourceCodeProcessor
      • doPMD

        @Deprecated
        @InternalApi
        public static int doPMD​(PMDConfiguration configuration)
        Deprecated.
        Use runPmd(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 useful
        Creates a new rule context, initialized with a new, empty report.
        Parameters:
        sourceCodeFilename - the source code filename
        sourceCodeFile - the source code file
        Returns:
        the rule context
      • processFiles

        @Deprecated
        public static Report processFiles​(PMDConfiguration configuration,
                                          List<RuleSet> rulesets,
                                          Collection<? extends DataSource> files,
                                          List<Renderer> renderers)
        Deprecated.
        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 parameters
        rulesets - Parsed rulesets
        files - 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. Use PmdAnalysis.
        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 files
        languages - 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 invoke System.exit(int).
        Parameters:
        args - command line arguments
      • run

        @Deprecated
        public static int run​(String[] args)
        Deprecated.
        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.