Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CheckStyle checks not been ignored

I have set up my checkstyle checks in my pom.xml as follows

<reporting>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-checkstyle-plugin</artifactId>
                <version>2.10</version>
                <configuration>
                    <suppressionsLocation>
                        checkstyle-suppressions.xml
                    </suppressionsLocation>
                    <suppressionsFileExpression>
                        checkstyle-suppressions.xml
                    </suppressionsFileExpression>
                </configuration>
            </plugin>
        </plugins>
    </reporting>

my checkstyle-supressions.xml file contains the following

<?xml version="1.0"?>

<!DOCTYPE suppressions PUBLIC
     "-//Puppy Crawl//DTD Suppressions 1.0//EN"
     "http://www.puppycrawl.com/dtds/suppressions_1_0.dtd">

<suppressions>
  <suppress checks="JavadocStyleCheck"
             files="**/*.java"
             />
  <suppress checks="JavadocTypeCheck"
             files="**/*.java"
             />
  <suppress checks="JavadocVariableCheck"
             files="**/*.java"
             />
  <suppress checks="FileTabCharacterCheck"
             files="**/*.java"
             />
</suppressions>

I want that when i run mvn site, the check style plugin does not report any JavaDoc comments or errors relating to tab characters. But this does not work. How can i achieve this ?

Kind Regards

like image 994
user1730789 Avatar asked Mar 22 '13 15:03

user1730789


1 Answers

The CheckStyle:SuppressionFilter told us as

A suppressions XML document contains a set of suppress elements, where each suppress element can have the following attributes:

  1. files - a regular expression matched against the file name associated with an audit event. It is mandatory.
  2. checks - a regular expression matched against the name of the check associated with an audit event. Optional if id is specified.
  3. id - a string matched against the id of the check associated with an audit event. Optional if checks is specified.
  4. lines - a comma-separated list of values, where each value is an integer or a range of integers denoted by integer-integer. It is optional.
  5. columns - a comma-separated list of values, where each value is an integer or a range of integers denoted by integer-integer. It is optional.

Since the files is a regular expression, you can test the configure online at Regular Expression Test Page for Java.

If the files is **/*.java, when apply the regular expression with com.test.My.java the result is failure as Dangling meta character '*' near index 0 **/*.java ^

Then the solution is setting the files as .*\.java , when apply the regular expression with com.test.My.java the result is matches(): yes, lookingAt(): yes, find(): yes and group(0): com.test.My.java.

The plugin configuration should be the following:-

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-checkstyle-plugin</artifactId>
    <version>2.10</version>
    <configuration>
      <suppressionsLocation>checkstyle-suppressions.xml</suppressionsLocation>
      <suppressionsFileExpression>checkstyle.suppressions.file</suppressionsFileExpression>
    </configuration>
</plugin>

The checkstyle:checkstyle told us as

  1. suppressionsLocation: Specifies the location of the suppressions XML file to use. This parameter is resolved as resource, URL, then file. If successfully resolved, the contents of the suppressions XML is copied into the ${project.build.directory}/checkstyle-supressions.xml file before being passed to Checkstyle for loading.

  2. suppressionsFileExpression The key to be used in the properties for the suppressions file. Default value is: checkstyle.suppressions.file.

Please refer to Maven Checkstyle Plugin: Using a Suppressions Filter for further information.

I hope this may help.

like image 112
Charlee Chitsuk Avatar answered Sep 22 '22 15:09

Charlee Chitsuk