Checkstyle~A static code analysis tool


Really big projects require the input of hundreds of programmers, often geographically dispersed and with great differences in skill level.

Code reviews are essential to code quality, but no team wants to review tens of thousands of lines of code, or should have to.

In many cases, a QA team is assigned to review this code manually, based on coding standards used as guidelines for development.

Code Conventions for Java Programming Language

Code Conventions for Java Programming Language

How to overcome the challenges associated with code reviews by automating them?

Programmer's Thinking Cap (Source: Google)

Programmer’s Thinking Cap (Source: Google)

Manually reviewing millions of lines of code is a tedious job, though; ultimately as exhausting as it must be exhaustive.

Java™ Application Development on Linux® – Free 599 Page eBook

Enterprise Java Virtualization:

Understanding the TCO Implications

InfoWorld’s Java IDE Comparison Strategy Guide:

Java Essential Training

Apache Jakarta Commons: Reusable Java™ Components

Enabling Rapid ROI: With Java™ – Based Business Intelligence Applications:

Smart teams don’t do code reviews manually: instead they rely on source code analyzers like Checkstyle, PMD, and JTest.

Checkstyle is a development tool to help programmers write Java code that adheres to a coding standard. It automates the process of checking Java code to spare humans of this boring (but important) 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.

A good example of a report that can be produced using Checkstyle and Maven can be seen here.

Another Example is:

Checkstyle Log Analyzer Violation Chart (Source: Google)

Checkstyle Log Analyzer Violation Chart (Source: Google)

Usage:

Checkstyle is built in a JAR file which can run inside a Java VM or as an Apache Ant task. It can also integrate into an IDE or other tools.

n  Checkstyle is highly configurable and can be made to support almost any coding standard.

n  Checkstyle configuration

A Checkstyle configuration specifies which modules to plug in and apply to Java source files. Modules are structured in a tree whose root is the Checker module. The next level of modules contains:

* FileSetChecks – modules that take a set of input files and fire error messages.

* Filters – modules that filter audit events, including error messages, for acceptance.

* AuditListeners – modules that report accepted events.

For more details Click Here.

n  It can be used as:

u  An Ant task.

To use the task in a build file, you will need the following taskdef declaration:

<taskdef resource="checkstyletask.properties" classpath="/path/to/checkstyle-X.jar"/>

u  A command line tool.

The command line usage is:

java -D=   com.puppycrawl.tools.checkstyle.Main  -c  [-f] [-p] [-o]  [-r

] file...Checkstyle will process the specified files and by default report errors to standard out in plain format. Checkstyle requires a configuration XML file that configures the checks to apply. Command line options are:

  • -f format - specify the output format. Options are "plain" for the DefaultLogger and "xml" for the XMLLogger. Defaults to "plain".
  • -p propertiesFile - specify a properties file to use.
  • -o file - specify the file to output to.
  • -r dir - specify the directory to traverse for Java source files.

n  Checkstyle is often used as an Eclipse plugin, and also as part of a project build to create a report of coding-standard violations.

n  It can be downloaded at:

http://checkstyle.sourceforge.net/

Features:

The things that Checkstyle can check for are:

v  Javadoc Comments

v  Naming Conventions

v  Headers

v  Imports

v  Size Violations

v  Whitespace

v  Modifiers

v  Blocks

v  Coding Problems

v  Class Design

Duplicate Code

v  Metrics Checks

  • BooleanExpressionComplexity
  • ClassDataAbstractionCoupling
  • ClassFanOutComplexity
  • CyclomaticComplexity
  • NPathComplexity

v  Miscellaneous Checks

v  Optional Checks

Single Sign-On for Java and Web Applications

Bulletproof Java Code: A Practical Strategy for Developing Functional, Reliable, and Secure Java Code

Transforming a Generic Java IDE to Your Application Specific IDE:

The Java Virtual Appliance—No OS Required

BEA WebLogic® Operations Control: Application Virtualization for Enterprise Java

Enabling Rapid ROI: With Java™ - Based Business Intelligence Applications:

Reference:


http://checkstyle.sourceforge.net/


http://en.wikipedia.org/wiki/Checkstyle


http://eclipse-cs.sourceforge.net/


http://checkstyle.sourceforge.net/cmdline.html


http://checkstyle.sourceforge.net/anttask.html


http://www.javaworld.com/javaworld/jw-11-2008/jw-11-checkstyle1.html

About these ads

5 comments on “Checkstyle~A static code analysis tool

  1. Pingback: Maven~Software Tool for Project Management and Builds Automation | Researcher's Blog (Informative)

  2. Pingback: How to install Ant? | Researcher's Blog (Informative)

  3. Pingback: Introduction to ANT | Researcher's Blog (Informative)

  4. Pingback: Built-in Tasks in Ant | Researcher's Blog (Informative)

  5. Pingback: ANT Overview, Structure & Basics (Build File) | Researcher's Blog (Informative)

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s