java 代码规范检查之check-style
这是目前公司java 代码规范所涉及到的几部分 ,结合ant做个演示
一.配置checkstlye
<?xml version="1.0"? encoding="GBK"?>
<project name="Depoly" default="checkstyle" basedir=".">
??? <property file="oa.properties" />
<target name="checkstyle">
???
???
??? <taskdef name="checkstyle" classname="com.puppycrawl.tools.checkstyle.CheckStyleTask">
??? ??? <classpath>
??? ??? ??? ??? <fileset dir="${CheckStyleHome}" includes="checkstyle-5.6-all.jar" />
??? ??? ??? ??? <fileset dir="${CheckStyleHome}" includes="*.jar" />
??? ??? ??? </classpath>
??? </taskdef>
??? ??? ?<checkstyle config="./oa_checks.xml">
??? ??? ??? <fileset dir="${src}" includes=" **/*.java" />
??? ??? ??? <formatter type="xml" toFile="./1.xml"/>
??? ??? </checkstyle>??
??? </target>
</project>
二:oa_checks.xm 配置
?? <!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="TreeWalker">
??? <!-- Checks Javadoc comments for class and interface definitions -->
???? ??? <module name="JavadocType">
???? ??? ??? <!-- check for an @author tag -->
? ??? ???? <property name="authorFormat" value="\S"/>
? ??? ???? ? <!-- check for an @version tag -->
? ??? ???? <property name="versionFormat" value="\S"/>
??? ??? </module>
??? ??? <module name="ClassTypeParameterName" >
??? ??? ??? <!-- class type parameters -->
??? ??? ??? ?<property name="format" value="^[A-Z]$"/>
??? ??? </module>??? ???
??? ??? <!-- Checks for unused import statements
??? ??? <module name="UnusedImports"/>
? -->
??? ??? <!-- Check that finds import statements that use the * notation. -->
??? ??? <module name="AvoidStarImport" />?
??? ??? <!-- check ConstantName -->
??? ??? ?<module name="ConstantName" >
??? ??? ???? ??? <property name="format" value="^[A-Z][A-Z0-9]*(_[A-Z0-9]+)*$" />
??? ??? ???? </module>
??? ??? ???? <!-- Checks the Javadoc of a method -->
??? ??? ???? <module name="JavadocMethod" >
??? ??? ???? ??? <property name="allowMissingThrowsTags" value="true" />
??? ??? ???? ??? <property name="allowMissingParamTags"? value="true" />
??? ??? ???? ??? <property name="allowMissingReturnTag" value="true" />
??? ??? ???? ??? </module>
??? ??? ????
??? ??? ???? <!-- method less than 200 -->
??? ??? ???? <module name="MethodLength">
?? ??? ??? ??? <property name="tokens" value="METHOD_DEF"/>
?? ??? ??? ??? ??? ??? <property name="max" value="200"/>
??? ??? ??? ??? </module>
??? </module>
???
</module>
?