checkstyle/src/xdocs/cmdline.xml.vm

219 lines
8.0 KiB
XML

<?xml version="1.0" encoding="UTF-8"?>
<document xmlns="http://maven.apache.org/XDOC/2.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/XDOC/2.0 http://maven.apache.org/xsd/xdoc-2.0.xsd">
<head>
<title>Command Line</title>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"/>
<script type="text/javascript" src="js/anchors.js"/>
<script type="text/javascript" src="js/google-analytics.js"/>
<link rel="icon" href="images/favicon.png" type="image/x-icon" />
<link rel="shortcut icon" href="images/favicon.ico" type="image/ico" />
</head>
<body>
<section name="Content">
<macro name="toc">
<param name="fromDepth" value="1"/>
<param name="toDepth" value="1"/>
</macro>
</section>
<section name="Description">
<p>
This document describes how to run Checkstyle using the command line
tool. The latest version of Checkstyle can be found at <a
href="http://checkstyle.sourceforge.net">http://checkstyle.sourceforge.net</a>.
This command line tool is included in the Checkstyle distribution.
</p>
</section>
<section name="Command line usage">
<p>
<source>
java -D&lt;property&gt;=&lt;value&gt; \
com.puppycrawl.tools.checkstyle.Main \
-c &lt;configurationFile&gt; \
[-f &lt;format&gt;] [-p &lt;propertiesFile&gt;] [-o &lt;file&gt;] \
file...
</source>
</p>
<p>
Checkstyle will process the specified files and by default report
errors to standard out in plain format. Checkstyle requires a <a
href="config.html">configuration XML file</a> that configures the
checks to apply. Command line options are:
</p>
<ul>
<li>
<code>-c configurationFile</code> - specifies the location of the
file that defines the configuration modules. The location can either
be a filesystem location, or a <a href="http://docs.oracle.com/javase/8/docs/technotes/guides/lang/resources.html#res_names">name</a> passed to the
ClassLoader.getResource() method.
</li>
<li>
<code>-f format</code> - specify the output
format. Options are <code> "plain"</code> for the <a
href="apidocs/com/puppycrawl/tools/checkstyle/DefaultLogger.html">DefaultLogger</a>
and <code>"xml"</code> for the <a
href="apidocs/com/puppycrawl/tools/checkstyle/XMLLogger.html">XMLLogger</a>.
Defaults to <code>"plain"</code>.
</li>
<li>
<code>-p propertiesFile</code> - specify a
properties file to use.
</li>
<li>
<code>-o file</code> - specify the file to output
to.
</li>
</ul>
<p>
Note that the <code>-n packageNamesFile</code>
option has been dropped for Checkstyle 5.0, because of
significant changes regarding package name file handling. See <a
href="config.html#Packages"/> for details.
</p>
<p>
Set the properties for <a href="config.html#Properties">expanded
property values</a> by either by assigning system properties using the
<code>-D&lt;property&gt;=&lt;value&gt;</code> arguments to java or
specifying a property file using the <code>-p</code> option. If a
property file is specified, the system properties are ignored.
</p>
</section>
<section name="Download and Run">
<p>
It is possible to run Checkstyle directly from the JAR file using
the <code>-jar</code> option. Download latest <a href="http://iweb.dl.sourceforge.net/project/checkstyle/checkstyle/${projectVersion}/checkstyle-${projectVersion}-all.jar">
checkstyle-${projectVersion}-all.jar</a>.
An example of run would be:
<source>
java -jar checkstyle-${projectVersion}-all.jar -c /sun_checks.xml MyClass.java
java -jar checkstyle-${projectVersion}-all.jar -c /google_checks.xml MyClass.java
</source>
It is recommended to use configuration files that are embeded in jar files, but latest configuration files are there:
<a href="https://raw.githubusercontent.com/checkstyle/checkstyle/master/src/main/resources/sun_checks.xml">sun_checks.xml</a>
<a href="https://raw.githubusercontent.com/checkstyle/checkstyle/master/src/main/resources/google_checks.xml">google_checks.xml</a>
</p>
<p>
To run Checkstyle UI viewer for AST tree directly from the JAR file using
the <code>-jar</code> option. Download latest <a href="http://iweb.dl.sourceforge.net/project/checkstyle/checkstyle/${projectVersion}/checkstyle-${projectVersion}-all.jar">
checkstyle-${projectVersion}-all.jar</a>.
An example of run would be (path to java file is optional):
<source>
java -cp checkstyle-${projectVersion}-all.jar com.puppycrawl.tools.checkstyle.gui.Main MyClass.java
</source>
</p>
</section>
<section name="Run after compilation">
<p>
Download and compile:
<source>
git clone https://github.com/checkstyle/checkstyle.git
cd checkstyle
mvn clean compile
</source>
Run validation with arguments:
<source>
mvn exec:java -Dexec.mainClass="com.puppycrawl.tools.checkstyle.Main" \
-Dexec.args="-c /sun_checks.xml src/main/java "
</source>
Run UI application for file :
<source>
mvn exec:java -Dexec.mainClass="com.puppycrawl.tools.checkstyle.gui.Main" \
-Dexec.args="src/main/java/com/puppycrawl/tools/checkstyle/Checker.java"
</source>
Build all jars, and launch CLI from new build:
<source>
mvn clean package -Passembly
java -jar target/checkstyle-X.X-SNAPSHOT-all.jar -c /sun_checks.xml MyClass.java
</source>
</p>
</section>
<section name="Usage by Classpath update">
<p>
The easiest way is to include
<a href="http://iweb.dl.sourceforge.net/project/checkstyle/checkstyle/${projectVersion}/checkstyle-${projectVersion}-all.jar">checkstyle-${projectVersion}-all.jar</a> in the
<a href="http://docs.oracle.com/javase/8/docs/technotes/tools/windows/classpath.html#sthref10">classpath</a>. Alternatively, you must include the
<code>compile</code> third party dependencies listed in
<a href="dependencies.html">Project Dependencies</a> in the
classpath.
<br/>
<br/>
<b>
Run checkstyle with configuration file at
<code>docs/sun_checks.xml</code> on a filesystem
</b>
</p>
<source>
java com.puppycrawl.tools.checkstyle.Main -c docs/sun_checks.xml \
Check.java
</source>
<p>
<b>
Run checkstyle with configuration file
<code>docs/sun_checks.xml</code> on all Java files in a directory
</b>
</p>
<source>
java com.puppycrawl.tools.checkstyle.Main -c docs/sun_checks.xml \
src/
</source>
<p>
<b>
Run checkstyle with configuration file
<code>docs/sun_checks.xml</code> on a file and provide a system
property
</b>
</p>
<source>
java -Dcheckstyle.cache.file=target/cachefile \
com.puppycrawl.tools.checkstyle.Main -c docs/sun_checks.xml \
Check.java
</source>
<p>
<b>
Run checkstyle with configuration file
<code>docs/sun_checks.xml</code> on a file and use properties in a
file
</b>
</p>
<source>
java com.puppycrawl.tools.checkstyle.Main -c docs/sun_checks.xml \
-p myCheckstyle.properties Check.java
</source>
<p>
<b>
Run checkstyle with configuration file
<code>docs/sun_checks.xml</code> on a file and output to a file in
XML format
</b>
</p>
<source>
java com.puppycrawl.tools.checkstyle.Main -c docs/sun_checks.xml \
-f xml -o build/checkstyle_errors.xml Check.java
</source>
</section>
</body>
</document>