CheckStyle

From HaFrWiki
Revision as of 13:01, 14 November 2012 by Hjmf (talk | contribs) (Created page with "{{TOCright}} == Installation in Maven == To set CheckStyle in Maven or {{Maven 2]] add the following line of code to the settings of the project.xml, project.properties. ...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

Installation in Maven

To set CheckStyle in Maven or {{Maven 2]] add the following line of code to the settings of the project.xml, project.properties.

Project.xml

  <reports>
     ...
     <report>maven-checkstyle-plugin</report>
     ...
  </reports>

Project.properties

Add the name of the file containing the checkstyle settings:

# Checkstyle settings #
maven.checkstyle.excludes=**/*generated*/**
maven.checkstyle.properties=${basedir}/AAB_checks.xml

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:

<?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>

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

CheckStyle HTML-Size
Kb
HTML
Reduction %
HTML-Lines
K
Line
Reduction %
Description
All 3,881  0 90,142 0,00% Default checks
No LineLength 3,545  336 82,104 8.66% No com.puppycrawl.tools.checkstyle.checks.sizes.LineLengthCheck (AAB_1_checks.xml)
No indentation 1,563 1,982 37,411 51.07% No com.puppycrawl.tools.checkstyle.checks.indentation.IndentationCheck (AAB_1_checks.xml)
No whitespace Param Pad 1,561  2 37,378 0.05% No com.puppycrawl.tools.checkstyle.checks.whitespace.MethodParamPadCheck
tokens: CTOR_DEF, LITERAL_NEW, METHOD_CALL, METHOD_DEF, SUPER_CTOR_CALL
No whitespace After 1,537  24 36,795 0.62% No com.puppycrawl.tools.checkstyle.checks.whitespace.NoWhitespaceAfterCheck
tokens: ARRAY_INIT, BNOT, DEC, DOT, INC, LNOT, UNARY_MINUS, UNARY_PLUS
No whitespace Before 1,536  1 36.773 0.03% No com.puppycrawl.tools.checkstyle.checks.whitespace.WhitespaceAfterCheck
tokens: SEMI, POST_DEC, POST_INC
No whitespace After 1,058 478 25,286 12.32% No com.puppycrawl.tools.checkstyle.checks.whitespace.NoWhitespaceAfterCheck
tokens: COMMA, SEMI, TYPECAST
No whitespace Around 643 415 15,276 10.69% No com.puppycrawl.tools.checkstyle.checks.whitespace.WhitespaceAroundCheck
tokens: ASSIGN, BAND, BAND_ASSIGN, BOR, BOR_ASSIGN, BSR, BSR_ASSIGN, BXOR, BXOR_ASSIGN, COLON, DIV, DIV_ASSIGN, EQUAL, GE, GT, LAND, LCURLY, LE, LITERAL_ASSERT, LITERAL_CATCH, LITERAL_DO, LITERAL_ELSE, LITERAL_FINALLY, LITERAL_FOR, LITERAL_IF, LITERAL_RETURN, LITERAL_SYNCHRONIZED, LITERAL_TRY, LITERAL_WHILE, LOR, LT, MINUS, MINUS_ASSIGN, MOD, MOD_ASSIGN, NOT_EQUAL, PLUS, PLUS_ASSIGN, QUESTION, RCURLY, SL, SLIST, SL_ASSIGN, SR, SR_ASSIGN, STAR, STAR_ASSIGN