Code Analysis Tools – Sample Ant Script

November 17, 2009

When you develop reusable components quality is very important. The higher a reusable asset’s usage, the higher the need for robustness. Unlike monolithic code, defects with reusable assets can rapidly impact several business processes and applications. All the more reason for the criticality of automated testing. In addition to testing, code analysis tools can detect defects, warn regarding unsafe/potentially buggy code, and also recommend various source code style/formatting improvements. All of these contribute to higher quality. I have used findbugs, pmd, and checkstyle in this space and they are very useful to analyze source code. You can also include these in your continuous integration suite.

Many readers have requested that I post sample code and scripts – so here is a sample apache ant build script that you can use with your code. Just be sure to modify the properties file to point to appropriate folders. The script will produce html reports for pmd and checkstyle as well as a find bugs output file (for viewing it with the findbugs client).

Code Analysis Script

Pre-requisites prior to running this script:

Set JAVA_HOME to your JDK 1.5 or above folder

Install apache ant 1.6+, findbugs, pmd, and checkstyle in your environment

Make sure the findbugs, pmd, and checkstyle jar files are in ant’s CLASSPATH.

Let me know if you have issues with using this script. Enjoy!

 

Like this post? Subscribe to RSS feed or get blog updates via email.

tweet this add to del.icio.us post to facebook


%d bloggers like this: