CheckStyle: Difference between revisions
mNo edit summary |
|||
Line 1: | Line 1: | ||
{{TOCright}} | {{TOCright}} | ||
Checkstyle is a tool for checking Code Standards Violations. It can be used different environments: | |||
* Standalone (not covered here) | |||
* [[#Installation_in_Ant|Ant]] | |||
* [[#Installation_in_Maven|Maven]] | |||
* IDE | |||
== Installation in Ant == | |||
To set CheckStyle in [[Ant]] add the following line of code to the build.xml. | |||
<syntaxhighlight lang="xml" line> | |||
<!-- The tools home-directories --> | |||
<property name = "checkstyle.home.dir" location = "." /> | |||
... | |||
<!-- Reference to the checkstyle plugin 6.8.1. --> | |||
<taskdef resource = "com/puppycrawl/tools/checkstyle/ant/checkstyle-ant-task.properties" classpath = "checkstyle-6.8.1-all.jar" /> | |||
... | |||
<!-- Checkstyle properties --> | |||
<property name="checkstyle.sourcepath" value="src" /> | |||
<property name="checkstyle.report.path" value="." /> | |||
<property name="checkstyle.report.style" value="checkstyle-simple.xsl" /> | |||
<property name="checkstyle.report.xml" value="checkstyle-report.xml" /> | |||
<property name="checkstyle.report.html" value="checkstyle-report.html" /> | |||
</syntaxhighlight> | |||
== Installation in Maven == | == Installation in Maven == | ||
To set CheckStyle in [[Maven]] or [[Maven 2]] add the following | To set CheckStyle in [[Maven]] or [[Maven 2]] add the following lines of code to the settings of the project.xml, project.properties. | ||
=== Project.xml === | === Project.xml === | ||
< | <syntaxhighlight lang="xml"> | ||
<reports> | <reports> | ||
... | ... | ||
Line 10: | Line 36: | ||
... | ... | ||
</reports> | </reports> | ||
</ | </syntaxhighlight> | ||
=== Project.properties === | === Project.properties === | ||
Add the name of the file containing the checkstyle settings: | Add the name of the file containing the checkstyle settings: | ||
< | <syntaxhighlight lang="bash"> | ||
# Checkstyle settings # | # Checkstyle settings # | ||
maven.checkstyle.excludes=**/*generated*/** | maven.checkstyle.excludes=**/*generated*/** | ||
maven.checkstyle.properties=${basedir}/AAB_checks.xml | maven.checkstyle.properties=${basedir}/AAB_checks.xml | ||
</ | </syntaxhighlight> | ||
== Configuration == | == Configuration == | ||
Line 27: | Line 55: | ||
The AAB uses its own CheckStyle convention (AAB_checks.xml), which is configured for each project separately. | The AAB uses its own CheckStyle convention (AAB_checks.xml), which is configured for each project separately. | ||
The format of the configuration file: | The format of the configuration file: | ||
< | <syntaxhighlight lang="xml"> | ||
<?xml version="1.0" encoding="UTF-8"?> | <?xml version="1.0" encoding="UTF-8"?> | ||
<!DOCTYPE module PUBLIC "-//Puppy Crawl//DTD Check Configuration 1.1//EN" "http://www.puppycrawl.com/dtds/configuration_1_1.dtd"> | <!DOCTYPE module PUBLIC "-//Puppy Crawl//DTD Check Configuration 1.1//EN" "http://www.puppycrawl.com/dtds/configuration_1_1.dtd"> | ||
Line 48: | Line 76: | ||
... | ... | ||
</module> | </module> | ||
</module></ | </module> | ||
</syntaxhighlight> | |||
== Problem == | == Problem == |
Revision as of 11:34, 15 August 2015
Checkstyle is a tool for checking Code Standards Violations. It can be used different environments:
Installation in Ant
To set CheckStyle in Ant add the following line of code to the build.xml. <syntaxhighlight lang="xml" line>
<property name = "checkstyle.home.dir" location = "." /> ... <taskdef resource = "com/puppycrawl/tools/checkstyle/ant/checkstyle-ant-task.properties" classpath = "checkstyle-6.8.1-all.jar" /> ... <property name="checkstyle.sourcepath" value="src" /> <property name="checkstyle.report.path" value="." /> <property name="checkstyle.report.style" value="checkstyle-simple.xsl" /> <property name="checkstyle.report.xml" value="checkstyle-report.xml" /> <property name="checkstyle.report.html" value="checkstyle-report.html" />
</syntaxhighlight>
Installation in Maven
To set CheckStyle in Maven or Maven 2 add the following lines of code to the settings of the project.xml, project.properties.
Project.xml
<syntaxhighlight lang="xml">
<reports> ... <report>maven-checkstyle-plugin</report> ... </reports>
</syntaxhighlight>
Project.properties
Add the name of the file containing the checkstyle settings: <syntaxhighlight lang="bash">
- Checkstyle settings #
maven.checkstyle.excludes=**/*generated*/** maven.checkstyle.properties=${basedir}/AAB_checks.xml </syntaxhighlight>
Configuration
The default CheckStyle is highly configurable. The installation come with sample configuration files:
- Apache Avalon (avalon_checks.xml)
- Sun coding conventions (sun_checks.xml)
- Apache Turbine Framework (turbine_checks.xml), this is the base of Frame
The AAB uses its own CheckStyle convention (AAB_checks.xml), which is configured for each project separately. The format of the configuration file: <syntaxhighlight lang="xml"> <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE module PUBLIC "-//Puppy Crawl//DTD Check Configuration 1.1//EN" "http://www.puppycrawl.com/dtds/configuration_1_1.dtd"> <module name="Checker">
<module name="TreeWalker"> <module name="com.puppycrawl.tools.checkstyle.checks.GenericIllegalRegexpCheck"> <property name="format" value="System.err"/> <property name="ignoreCase" value="false"/> <property name="ignoreComments" value="false"/> <property name="message" value="Do not use System.err"/> <property name="severity" value="warning"/> </module> ... <module name="com.puppycrawl.tools.checkstyle.checks.sizes.LineLengthCheck"> <property name="ignorePattern" value="^$"/> <property name="max" value="110"/> <property name="severity" value="warning"/> <property name="tabWidth" value="4"/> </module> ... </module>
</module> </syntaxhighlight>
Problem
The CheckStyle report becomes very long and difficult to handel. There are a few checks which delivers very much lines of report lines. A comparison of the size of checkstyle-report.html file for the different checkstyles
|