checkstyle ANT Task

Description

This task runs checkstyle over specified Java files. The task has been tested using ANT 1.2. The latest version of checkstyle can be found at http://www.puppycrawl.com/checkstyle. This task is included in the checkstyle distribution.

Installation

The easiest way is to include checkstyle-all-1.0.jar in the classpath. This contains all the classes required to run checkstyle. Alternatively, you must include the following in the classpath:

  1. checkstyle-1.0.jar
  2. ANTLR 2.7.1 classes. antlr.jar is included in the distribution.
  3. Jakarta Regexp 1.2 classes. jakarta-regexp-1.2.jar is included in the distribution.

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

  <taskdef name="checkstyle"
           classname="com.puppycrawl.tools.checkstyle.CheckStyleTask"/>

Parameters

Attribute Description Required
file File to run checkstyle on. One of either file or at least one nested fileset element
allowtabs Indicates whether to allow tabs. Defaults to "no". No
allowprotected Indicates whether to allow protected data. Defaults to "no". No
allownoauthor Indicates whether to allow no @author tag to be defined for class and interface Javadoc comments. Defaults to "no". No
maxlinelen Specifies the maximum line length. Default value is defined here. No
memberpattern Specifies the regular expression to match against member variables. Default value is defined here. No
parampattern Specifies the regular expression to match against parameters. Default value is defined here. No
constpattern Specifies the regular expression to match against static/final variables. Default value is defined here. No
staticpattern Specifies the regular expression to match against static variables. Default value is defined here. No
typepattern Specifies the regular expression to match against type names. Default value is defined here. No
headerfile Specifies the file containing the header lines. Default is to not check. No
headerignoreline Specifies the line in the header to ignore when comparing. Default it to not ignore any line. No

Examples

Run checkstyle on a single file

  <checkstyle file="Check.java"/>

Run checkstyle on a set of Java files in directory

  <checkstyle>
    <fileset dir="src/checkstyle" includes="**/*.java"/>
  </checkstyle>

Run checkstyle on a set of Java files and allow tabs

  <checkstyle allowtabs="yes">
    <fileset dir="src/checkstyle" includes="**/*.java"/>
  </checkstyle>

Run checkstyle on a set of Java files and disable pattern matching

  <checkstyle allowtabs="yes">
              parampattern="."
              constpattern="."
              staticpattern="."
              memberpattern="."
    <fileset dir="src/checkstyle" includes="**/*.java"/>
  </checkstyle>

Copyright © 2001 Oliver Burn. All rights Reserved.
$Id: anttask.html,v 1.5 2001/02/15 00:24:19 oburn Exp $