New rule list for each PMD release

13 Feb 2006

Elliotte Rusty Harold had an excellent suggestion for PMD - provide a ruleset that lists the rules that are new in each release. Done and done, now you can run PMD and get a nice list. For example, to see what rules were new in PMD 3.4, just reference the rulesets/releases/34.xml ruleset:

$ ./pmd.sh Bar.java text rulesets/releases/34.xml -debug
In JDK 1.4 mode
Loaded rule AvoidEnumAsIdentifier
Loaded rule AvoidDecimalLiteralsInBigDecimalConstructor
Loaded rule ReplaceEnumerationWithIterator
Loaded rule AvoidAssertAsIdentifier
Loaded rule UseStringBufferLength
Loaded rule UncommentedEmptyConstructor
Loaded rule DefaultPackage
Loaded rule MisleadingVariableName
Loaded rule ReplaceVectorWithList
Loaded rule ReplaceHashtableWithMap
Loaded rule UncommentedEmptyMethod
Loaded rule ClassCastExceptionWithToArray
Loaded rule NonThreadSafeSingleton
Processing /home/tom/pmd/pmd/bin/Bar.java
No problems found!

and for the latest release, 3.5, simply change the ruleset name:

$ ./pmd.sh Bar.java text rulesets/releases/35.xml -debug
In JDK 1.4 mode
Loaded rule UseAssertNullInsteadOfAssertTrue
Loaded rule IntegerInstantiation
Loaded rule MisplacedNullCheck
Loaded rule UseArraysAsList
Loaded rule AppendCharacterWithChar
Loaded rule UseIndexOfChar
Loaded rule ConsecutiveLiteralAppends
Loaded rule UselessOperationOnImmutable
Loaded rule BooleanInversion
Loaded rule UnusedNullCheckInEquals
Loaded rule AvoidConstantsInterface
Loaded rule AvoidArrayLoops
Processing /home/tom/pmd/pmd/bin/Bar.java
No problems found!

The same thing works with the Ant task; just run Ant with the -v flag. I've added "release rulesets" back to PMD v3.3, and I'll continue to fill in the gaps for previous releases. Good times!