PMD scans Java source code and looks for potential problems including possible bugs, dead or duplicate code, or suboptimal code. PMD is a powerful tool and is used by Software Engineers in industry as well as students learning to write Java.
PMD is best run from an IDE (integrated development environment). The PMD plug-in for BlueJ only tests two rule-sets: basic and unused code. However, it is the easiest way to use PMD, and so these rulesets will be the (only) ones we use for marking at the moment. You run PMD from BlueJ as follows:
PMD
then click on Check code
from the menu. The PMD plug-in for BlueJ is incomplete in that it does not allow you to check all the PMD rule sets. For lab marking, that is all you have to do: if you get the BlueJ message "No problems found!" then you will get full marks for style.
More adventurous students may wish to run PMD from the command line in order to try out different rule sets and different feedback formats. You do this as follows:
cd H:\Lab_Work\lab06\
If you don't know your directory name, try Open Recent in BlueJ and it will show you the full path for recent project directories. C:\bin\pmd-4.2.5\bin\pmd MyClass.java text basic,design,unusedcode
MyClass.java
is the name of the source file you want to checktext
is the format for PMD output format. You could also generate output as html using, C:\bin\pmd-4.2.5\bin\pmd MyClass.java html basic,unusedcode > report.htmlThen view your report by opening it in your favourite browser. For example, in the terminal type
explorer report.html
basic,braces,codesize,coupling,design,imports,naming,optimizations,strings,typeresolution,unusedcode.If you get many errors then it is much easier to check just one or two rulesets at a time.
A local CSSE copy of the including descriptions of all the rules is available by clicking on the link.
You can find out more about the rulesets and download PMD to run at home from