PMD
PMD is a source code analyzer. It finds common programming flaws like unused variables, empty catch blocks, unnecessary object creation, and so forth. It supports Java, JavaScript, XML, XSL. Additionally it includes CPD, the copy-paste-detector. CPD finds duplicated code in Java, C, C++, C#, PHP, Ruby, Fortran, JavaScript.

System requirements
  • Version 1.6.0 Build 27 GA5 (2013-02-17)
  • Enough memory, can be as high as -Xmx1024m


Result of a PMD testdrive on an eComStation machine with Open JDK


Installing PMD
Download pmd-bin-5.3.7.zip (29,0Mb). Also download the manual pmd-doc-5.3.7.zip (47,0Mb!). Create a folder (directory) "pmd537" or "pmd". Unzip the zip files to the subdirectory. That's it. Version 5.4.0 and up needs Java version 1.7 or better. Version 5.3.7 is released at April 30, 2016, so by no means dated!, see the PMD Web Site

The cmd files
This is not a program with some nice graphical user interface. Its more command line oriented. So there is not a real "fix it all" command file. I give an example with the following contents;
@echo off
set BEGINLIBPATH=[drive: java]\JAVA160\bin
set path=[drive: java]\JAVA160\bin
set CLASSPATH=
rem set OPTS=
[drive: pmd]
cd [drive: pmd]\pmd537
java -Duser.home=[drive: pmd]\pmd537 -classpath [drive: pmd]\pmd537\lib\* net.sourceforge.pmd.PMD 
-d [drive: greenfoot]\Greenfoot\scenarios\lunarlander\Lander.java -rulesets java-basic,java-design 
2>pmd537-bugs.txt
There is a space between "net.sourceforge.pmd.PMD" and "-d [drive: greenfoot]\..." and between "java-basic,java-design" and "2>pmd537-bugs.txt". Sometimes its handy to add ">results-pmd.txt" before "2>pmd537-bugs.txt", in this way the comments in the command session are saved when its more than will fit into a 80x25 screen.
The developer version of Java is on the same drive as PMD, only different folders (directories), one for Java, one for PMD and one for Greenfoot. Greenfoot is in test and there is something wrong with their Lunar module game, it crashes whatever you do. The references used in the cmd file;

  • [drive: java] = drive with Java
  • [drive: pmd] = drive with PMD
  • [drive: greenfoot] = drive with Greenfoot

should be replaced with real drive letters. Edit and save the file with a name of your choice or use the file from the distribution. This file is copied to the "pmd" folder (directory). Furthermore, different paths?, adjust according to your needs.
There are in the "\bin" map/directory a few "*.bat" files and a Linux sh file. The bat files are for Windows, but they are a nice start. You need to add parameters before executing the batch files. Without you get lots of errors. I only rebuild the "pmd.bat" file and this file is in the download file. I did try some others and didn't get errors in the bug file.

Parameters / options explained
  • The addition "2>pmd537-bugs.txt" ensures that errors are saved in the file "pmd537-bugs.txt". The 2 in "2>" is not a typo! If you did it wrong you get some, but not all errors in this file.
  • The specifications are included in the download file, its the help file. This file is send to screen when something is not understood by the program. But even then..., you need the manual...

Download
In the file you can find the above command file (all driveletters are set to C:), the helpfile as text file and a PMD icon: pmd-ecs.zip.

revision May 22, 2016