Tuesday, December 11, 2012

PMD

PMD is a static code analyzer for Java. It allows a developer team to maintain its software  consistently with their prescribed coding guidelines by automatically checking the guidelines against the software.

PMD is flexible since one can easily add new rules simply by writing XPath expressions over Java AST(abstract syntax tree), or more seriously by writing Java codes to detect more complicated inconsistency.

A quick start is possible:

  - Download from http://pmd.sourceforge.net
  - Unzip it, creating a directory named
  - Add the binary directory to your executable path such as PATH.
  - Create a test java file:
      public class Test
     {
        void foo()
        {
            int x = 42;
        }
      }
  - Run PMD on Windows by
 
       C:\> pmd.bat -d Test.java -f text -R rulesets/java/unusedcode.xml
   
     to see the analysis result:

       Test.java:5   Avoid unused local variables such as 'x'.

  - That's it!

You can find much more and more information in the PMD web site, http://pmd.sourceforge.net.

Also, WIKI is always our friend. http://en.wikipedia.org/wiki/PMD_(software).