Overview

This project provides Checkstyle rules to be used in smartics projects.

Integration with Maven

Please use the maven-checkstyle-plugin to use the rules from within Maven.

The following snippet shows how the rules can be integrated into the project (you may want to use the pluginManagement instead of the plugins section).

<build>
  <plugins>
    <plugin>
      <groupId>org.apache.maven.plugins</groupId>
      <artifactId>maven-checkstyle-plugin</artifactId>
      <version>maven-checkstyle-plugin.version</version>
      <dependencies>
        <dependency>
          <groupId>de.smartics.config</groupId>
          <artifactId>config-smartics-checkstyle</artifactId>
          <version>1.6.3</version>
        </dependency>
      </dependencies>
    </plugin>
    ...
  </plugins>
</build>

...

  <reportPlugins>
    <plugin>
      <groupId>org.apache.maven.plugins</groupId>
      <artifactId>maven-checkstyle-plugin</artifactId>
      <version>2.7</version>
      <configuration>
        <configLocation>checkstyle.xml</configLocation>
        <suppressionsLocation>checkstyle-smartics-suppressions.xml</suppressionsLocation>
        <propertyExpansion>suppressions.file=${project.build.directory}/checkstyle-suppressions.xml</propertyExpansion>
      </configuration>
    </plugin>
    ...
  </reportPlugins>

The suppressionsLocation would be sufficient for the Maven configuration without the propertyExpansion property. But eclipse requires the filter to be specified within the checkstyle.xml with the reference to the the checkstyle-suppressions.xml. Since this file is copied to the target folder by the checkstyle plugin, we override the suppressions.file property to pass the correct value to the filter.

Since configuration information is passed from the report to the build plugin, but other information not (or not necessarily), to sync the version information you may want to specify it as a property and reference to it from the version element.

<version>${maven-checkstyle-plugin.version}</version>
...
  <properties>
    <maven-checkstyle-plugin.version>2.7</maven-checkstyle-plugin.version>
  </properties>

Integration with eclipse

Please use the maven-eclipse-plugin to use the rules from within your eclipse IDE. Enclose the fileset-config in a CDATA section (not shown in the snippet below for technical reasons).

<plugin>
  <groupId>org.apache.maven.plugins</groupId>
  <artifactId>maven-eclipse-plugin</artifactId>
  <version>2.8</version>
  <configuration>
    <additionalConfig>
      <file>
        <name>.checkstyle</name>
        <content>
          <fileset-config file-format-version="1.2.0" simple-config="true">
        <fileset name="All" enabled="true" check-config-name="smartics" local="false">
          <file-match-pattern match-pattern="." include-pattern="true" />
          <file-match-pattern match-pattern="^src[/\\]test[/\\]resources[/\\].*\.java$"
                              include-pattern="false" />
        </fileset>
        <filter name="SuppressionFilter" enabled="true"/>
      </fileset-config>
        </content>
      </file>
    </additionalConfig>
    <additionalBuildcommands>
      <buildCommand>
        <name>com.atlassw.tools.eclipse.checkstyle.CheckstyleBuilder</name>
      </buildCommand>
    </additionalBuildcommands>
    <additionalProjectnatures>
      <projectnature>com.atlassw.tools.eclipse.checkstyle.CheckstyleNature</projectnature>
    </additionalProjectnatures>
  </configuration>
</plugin>

In our projects we do not want Java source files in the test resources folder to be checked and therefore exclude them.

Please note that the checkstyle configuration has to be registered in eclipse by the name smartics manually. Also add a property suppressions.file to refer to the suppressions file (either in the target folder or to a local copy of this file).

Formatter for eclipse

The smartics formatter for Java sources is included in the artifact of this project. It can be downloaded as part of the build process with the maven-dependency-plugin or manually from the artifact repository.

Validation

For validation issues the referenced DTDs are copied from the checkstyle distribution to the dtd folder of this distribution. Users may add these DTDs manually to their installation.