163 lines
6.7 KiB
HTML
163 lines
6.7 KiB
HTML
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
|
|
|
|
<html>
|
|
<head>
|
|
<title>Checkstyle ANT Task - Version @CHECKSTYLE_VERSION@</title>
|
|
<link rel="stylesheet" type="text/css" href="mystyle.css">
|
|
</head>
|
|
|
|
<body>
|
|
<h1><a name="checkstyle">Checkstyle ANT Task - Version @CHECKSTYLE_VERSION@</a></h1>
|
|
<h3>Description</h3>
|
|
|
|
<p>This task runs Checkstyle over specified Java files. The task has been tested using ANT 1.4.1. The latest version of checkstyle can be found at <a href="http://checkstyle.sourceforge.net/">http://checkstyle.sourceforge.net/</a>.
|
|
This task is included in the checkstyle distribution.</p>
|
|
|
|
<h3>Installation</h3>
|
|
<p>The easiest way is to include <span class="default">checkstyle-all-@CHECKSTYLE_VERSION@.jar</span> in the classpath. This contains all the classes required to run Checkstyle. Alternatively, you must include the following in the classpath:</p>
|
|
<ol>
|
|
<li><span class="default">checkstyle-@CHECKSTYLE_VERSION@.jar</span></li>
|
|
<li>ANTLR 2.7.1 classes. <span class="default">antlr.jar</span> is included in the distribution.</li>
|
|
<li>Jakarta Regexp 1.2 classes. <span class="default">jakarta-regexp-1.2.jar</span> is included in the distribution.</li>
|
|
</ol>
|
|
|
|
<p>To use the task in a build file, you will need the following <code>taskdef</code> declaration:</p>
|
|
<pre>
|
|
<taskdef name="checkstyle"
|
|
classname="com.puppycrawl.tools.checkstyle.CheckStyleTask"/>
|
|
</pre>
|
|
<p>Alternatively, since checkstyle version 2.2 you can use <code>taskdef</code>'s resource attribute:</p>
|
|
<pre>
|
|
<taskdef resource="checkstyletask.properties"/>
|
|
</pre>
|
|
|
|
|
|
<h3>Parameters</h3>
|
|
<table border="1" cellpadding="2" cellspacing="0" summary="parameters">
|
|
<tr class="header">
|
|
<td valign="top"><b>Attribute</b></td>
|
|
<td valign="top"><b>Description</b></td>
|
|
<td valign="top"><b>Required</b></td>
|
|
</tr>
|
|
<tr>
|
|
<td valign="top">file</td>
|
|
<td valign="top">File to run checkstyle on.</td>
|
|
<td align="center" valign="top">One of either <i>file</i> or at least one nested <i>fileset</i> element</td>
|
|
</tr>
|
|
<tr>
|
|
<td valign="top">properties</td>
|
|
<td valign="top">Specifies a properties file that contains the configuration options. This is useful for sharing checkstyle configurations across ant build files. The property names to use in the file are the same as on the <a href="cmdline.html">command line</a>. Other parameters to the ANT task override the settings in the properties file.</td>
|
|
<td align="center" valign="top">No</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td valign="top">failOnViolation</td>
|
|
<td valign="top">Specifies whether the build will continue even if there are violations. Defaults to <span class="default">"true"</span>.</td>
|
|
<td align="center" valign="top">No</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td valign="top">failureProperty</td>
|
|
<td valign="top">The name of a property to set in the event of a violation.</td>
|
|
<td align="center" valign="top">No</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td valign="top">classpath</td>
|
|
<td valign="top">The classpath to use when looking up classes. Defaults to the current classpath.</td>
|
|
<td align="center" valign="top">No</td>
|
|
</tr>
|
|
|
|
</table>
|
|
|
|
|
|
<h3>Nested Elements</h3>
|
|
|
|
<p>This task supports the nested elements <a href="http://jakarta.apache.org/ant/manual/CoreTypes/fileset.html"><fileset></a>, <span class="default"><classpath></span> and <span class="default"><formatter></span>. The parameters for the <span class="default"><formatter></span> element are:</p>
|
|
|
|
<table border="1" cellpadding="2" cellspacing="0" summary="nested elements">
|
|
<tr class="header">
|
|
<td valign="top"><b>Attribute</b></td>
|
|
<td valign="top"><b>Description</b></td>
|
|
<td valign="top"><b>Required</b></td>
|
|
</tr>
|
|
<tr>
|
|
<td valign="top">type</td>
|
|
<td valign="top">
|
|
<p>The type of output to generate. The valid values are:</p>
|
|
<ul>
|
|
<li><span class="default">plain</span> - specifies the <a href="api/com/puppycrawl/tools/checkstyle/DefaultLogger.html">DefaultLogger</a></li>
|
|
<li><span class="default">xml</span> - specifies the <a href="api/com/puppycrawl/tools/checkstyle/XMLLogger.html">XMLLogger</a></li>
|
|
</ul>
|
|
<p>Defaults to <span class="default">"plain"</span>.</p>
|
|
</td>
|
|
<td align="center" valign="top">No</td>
|
|
</tr>
|
|
<tr>
|
|
<td valign="top">toFile</td>
|
|
<td valign="top">The file to write output to. Defaults to standard output. Note, there is no way to explicitly specify standard output.
|
|
</td>
|
|
<td align="center" valign="top">No</td>
|
|
</tr>
|
|
</table>
|
|
|
|
|
|
<h3>Examples</h3>
|
|
<p><b>Run checkstyle on a single file</b></p>
|
|
<pre>
|
|
<checkstyle file="Check.java"/>
|
|
</pre>
|
|
|
|
<p><b>Run checkstyle on a set of Java files in directory</b></p>
|
|
<pre>
|
|
<checkstyle>
|
|
<fileset dir="src/checkstyle" includes="**/*.java"/>
|
|
</checkstyle>
|
|
</pre>
|
|
|
|
<p><b>Run checkstyle on a set of files and output messages to standard output in plain format, and a file in XML format</b></p>
|
|
<pre>
|
|
<checkstyle>
|
|
<fileset dir="src/checkstyle" includes="**/*.java"/>
|
|
<formatter type="plain"/>
|
|
<formatter type="xml" toFile="build/checkstyle_errors.xml"/>
|
|
</checkstyle>
|
|
</pre>
|
|
|
|
<p><b>Run checkstyle in an automated build and send an email report if style violations are detected</b></p>
|
|
<pre>
|
|
<target name="checkstyle"
|
|
description="Generates a report of code convention violations.">
|
|
|
|
<checkstyle failureProperty="checkstyle.failure"
|
|
failOnViolation="false">
|
|
<formatter type="xml" tofile="checkstyle_report.xml"/>
|
|
<fileset dir="src" includes="**/*.java"/>
|
|
</checkstyle>
|
|
|
|
<style in="checkstyle_report.xml" out="checkstyle_report.html" style="checkstyle.xsl"/>
|
|
|
|
</target>
|
|
|
|
<!-- run this target as part of automated build -->
|
|
<target name="checkstyle-nightly"
|
|
depends="checkstyle"
|
|
if="checkstyle.failure"
|
|
description="Sends email if checkstyle detected code conventions violations.">
|
|
|
|
<!-- use your own server and email addresses below. See Ant documentation for details -->
|
|
|
|
<mail from="qa@some.domain"
|
|
tolist="someone@some.domain,someoneelse@some.domain"
|
|
mailhost="mailbox.some.domain"
|
|
subject="Checkstyle violation(s) in project ${ant.project.name}"
|
|
files="checkstyle_report.html"/>
|
|
|
|
</target>
|
|
</pre>
|
|
|
|
<hr>
|
|
<p align="center">Copyright © 2001 Oliver Burn. All rights Reserved.</p>
|
|
</body>
|
|
</html>
|