Wednesday, August 27, 2008

CheckStyle integration with OpenNMS

What is CheckStyle:

Checkstyle is a development tool to help programmers to write Java code that adheres to a coding standard. It automates the process of checking Java code to spare humans of this boring task. This makes it ideal for projects that want to enforce a coding standard.

Checkstyle is highly configurable and can be made to support almost any coding standard. An example configuration file is supplied supporting the Sun Code Conventions. As well, other sample configuration files are supplied for other well known conventions.

A good example of a report that can be produced using CheckStyle and Maven

I prefer to use geosoft java coding conventions always. You can download CheckStyle from here.

Procedure to integrate CheckStyle with OpenNMS Maven:

I believe us all familiar to use Maven. So I am just directly going for CheckStyle integration.

While compiling OpenNMS code I used CheckStyle to generate Static code Analyze report.


To generate the Checkstyle report as part of the Project Reports, add the Checkstyle plugin in the section of openNMS root pom.xml.



I used geosoft check file so I changed the above configuration as per my need




Then, execute the site plugin to generate the report. Use the following command in command line.

mvn site

We can also generate the Checkstyle report by explicitly executing the checkstyle:checkstyle goal from the command line. It is not required to specify the Checkstyle plugin in your pom.xml unless you want to use a specific configuration. . Use the following command in command line.

mvn checkstyle:checkstyle

To specifically configure the Checkstyle plugin, we need to add it in the section of your pom.xml as shown in the sample below.

Note: The generated report will be saved under target\site folder of each project folder. example : opennms-model\target\site

Some of the images might missing in this post. Please see my wordpress blog also.
http://experiencesharing.wordpress.com/

Reference Links:

http://maven.apache.org/plugins/maven-checkstyle-plugin/checkstyle-mojo.html#outputDirectory

http://maven.apache.org/plugins/maven-checkstyle-plugin/usage.html

http://maven.apache.org/plugins/maven-checkstyle-plugin/

No comments: