Friday, March 26, 2010

Cleaner CDK Code #3: run the PMD tests

PMD is a tool to run some tests against your source code. The check for code style, common problems, and places where code could be improved. The CDK has been using it for years now, such as here for CDK 1.3.x.

Running the PMD tests from the command line
When you are writing patches for the CDK, you can run the PMD tests via an Ant file, for example via the command line:
$ ant -f pmd.xml
However, when working on a single file, you will likely appreciated running the tests against a single module. This can be done with (for the data module):
$ ant -f pmd.xml -Dpmd.test=custom -Dmodule=data test-module
The custom.xml defines the tests we normally run.

The pmd.xml does not create HTML pages, like Nightly does. Instead, an XML file is currently created. The xpath utility can be used to filter out the information we are interested in. For example, if we want to reports just about DefaultChemObjectBuilder, we issue:
$ xpath -e "//violation[@class='DefaultChemObjectBuilder']" \\

No comments:

Post a Comment