Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save artsok/f3301fc949ce953136638209b92c7f6d to your computer and use it in GitHub Desktop.
Save artsok/f3301fc949ce953136638209b92c7f6d to your computer and use it in GitHub Desktop.
Understanding AST
AST Tree
RooT
-sibling
|-child
|-sibling
|-sibling
-Sibling
-sibling
-Sibling
command to display AST Tree:
java -classpath C:\checkstyle-5.6-all.jar com.puppycrawl.tools.checkstyle.gui.Main
command to run check for a sinlge class
java -classpath C:\checkstyle-5.6-all.jar com.puppycrawl.tools.checkstyle.Main -c checkstyle_test.xml SampleClass.java
command to run check using maven
mvn clean install -DgenerateReports=false checkstyle:checkstyle checkstyle:check
JUnit Testing CheckStyle
similar test provided at
http://opensourcejavaphp.net/java/checkstyle/com/puppycrawl/tools/checkstyle/BaseCheckTestSupport.java.html
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
<version>2.9.1</version>
<configuration>
<configLocation>C:\checkstyle_test.xml</configLocation>
<!--
<configLocation>
http://localhost:9080/sonar/profiles/export?format=checkstyle&amp;language=java&amp;name=test.checkstyle
</configLocation>
-->
</configuration>
<executions>
<execution>
<id>checkstyle</id>
<phase>prepare-package</phase>
<goals>
<goal>checkstyle</goal>
</goals>
</execution>
<execution>
<id>checkstyle-check</id>
<phase>verify</phase>
<goals>
<goal>check</goal>
</goals>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>my.checkstyle</groupId>
<artifactId>my-checkstyle</artifactId>
<version>1.0.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.eclipse.equinox</groupId>
<artifactId>app</artifactId>
<version>1.0.0-v20070606</version>
</dependency>
</dependencies>
</plugin>
Checkstyle_test.xml
=====================
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE module PUBLIC "-//Puppy Crawl//DTD Check Configuration 1.2//EN" "http://www.puppycrawl.com/dtds/configuration_1_2.dtd">
<module name="Checker">
<module name="RegexpMultiline">
<property name="format" value="(?i)script"/>
<property name="fileExtensions" value="jsp,xml,html,js" />
<property name="severity" value="warning" />
</module>
</module>
plugin for pom.xml
===========================
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
<version>2.9.1</version>
<configuration>
<configLocation>C:\checkstyle_test.xml</configLocation>
<!--
<configLocation>
http://localhost:9080/sonar/profiles/export?format=checkstyle&amp;language=java&amp;name=cde.checkstyle
</configLocation>
-->
<sourceDirectory>${project.build.directory}</sourceDirectory>
<includes>**\/*.jsp, **\/*.java, **\/*.xml</includes>
</configuration>
<executions>
<execution>
<id>checkstyle</id>
<phase>prepare-package</phase>
<goals>
<goal>checkstyle</goal>
</goals>
</execution>
<execution>
<id>checkstyle-check</id>
<phase>verify</phase>
<goals>
<goal>check</goal>
</goals>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>my.checkstyle</groupId>
<artifactId>my-checkstyle</artifactId>
<version>1.0.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.eclipse.equinox</groupId>
<artifactId>app</artifactId>
<version>1.0.0-v20070606</version>
</dependency>
</dependencies>
</plugin>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment