26-March-2022 - 6.44.0-SNAPSHOT
The PMD team is pleased to announce PMD 6.44.0-SNAPSHOT.
This is a minor release.
New and noteworthy
New programmatic API
This release introduces a new programmatic API to replace the inflexible PMD
class.
Programmatic execution of PMD should now be done with a PMDConfiguration
and a PmdAnalysis
, for instance:
PMDConfiguration config = new PMDConfiguration();
config.setDefaultLanguageVersion(LanguageRegistry.findLanguageByTerseName("java").getVersion("11"));
config.setInputPaths("src/main/java");
config.prependAuxClasspath("target/classes");
config.setMinimumPriority(RulePriority.HIGH);
config.addRuleSet("rulesets/java/quickstart.xml");
config.setReportFormat("xml");
config.setReportFile("target/pmd-report.xml");
try (PmdAnalysis pmd = PmdAnalysis.create(config)) {
// note: don't use `config` once a PmdAnalysis has been created.
// optional: add more rulesets
pmd.addRuleSet(pmd.newRuleSetLoader().loadFromResource("custom-ruleset.xml"));
// optional: add more files
pmd.files().addFile(Paths.get("src", "main", "more-java", "ExtraSource.java"));
// optional: add more renderers
pmd.addRenderer(renderer);
// or just call PMD
pmd.performAnalysis();
}
The PMD
class still supports methods related to CLI execution: runPmd
and main
.
All other members are now deprecated for removal.
The CLI itself remains compatible, if you run PMD via command-line, no action is required on your part.
Fixed Issues
- apex-performance
- #3773: [apex] EagerlyLoadedDescribeSObjectResult false positives with SObjectField.getDescribe()
- core
- #3299: [core] Deprecate system properties of PMDCommandLineInterface
- doc
- #3812: [doc] Documentation website table of contents broken on pages with many subheadings
API Changes
Deprecated API
- Several members of
PMD
have been newly deprecated, including:PMD#EOL
: useSystem#lineSeparator()
PMD#SUPPRESS_MARKER
: useDEFAULT_SUPPRESS_MARKER
PMD#processFiles
: use the new programmatic APIPMD#getApplicableFiles
: is internal
PMDConfiguration#prependClasspath
is deprecated in favour ofprependAuxClasspath
.PMDConfiguration#setRuleSets
andgetRuleSets
are deprecated. Use insteadsetRuleSets
,addRuleSet
, andgetRuleSetPaths
.- Several members of
BaseCLITest
have been deprecated with replacements. - Several members of
PMDCommandLineInterface
have been explicitly deprecated. The whole class however was deprecated long ago already with 6.30.0. It is internal API and should not be used.
Experimental APIs
-
Together with the new programmatic API the interface
TextFile
has been added as experimental. It intends to replaceDataSource
andSourceCode
in the long term.This interface will change in PMD 7 to support read/write operations and other things. You don’t need to use it in PMD 6, as
FileCollector
decouples you from this. A file collector is available throughPmdAnalysis#files
.
External Contributions
- #3773: [apex] EagerlyLoadedDescribeSObjectResult false positives with SObjectField.getDescribe() - @filiprafalowicz
- #3836: [doc] Make TOC scrollable when too many subheadings - @JerritEic