1、设置 user.properties
- # 项目名称
- project.name=WebService_Restful
- # 项目所在的路径
- project.dir=D:\\workspaces\\webservice\\Restful
- # 源文件所在的路径
- project.src.dir=${project.dir}\\src\\main\\java
2、build.xml
- <project name="checkstyle" default="checkstyle" basedir=".">
-
- <property file="user.properties" />
- <!-- - - - - - - - - - - - - - - - - -
- target: init
- - - - - - - - - - - - - - - - - - -->
- <target name="init">
- <tstamp />
-
- <property name="project.checkstyle.report.dir" value="${project.dir}/report" />
-
- <property name="project.check.result.name" value="${project.name}-checkstyle-result-${DSTAMP}.xml" />
-
- <property name="project.check.report.name" value="${project.name}-checkstyle-report-${DSTAMP}.html" />
-
- <property name="checkstyle.config" value="${basedir}/sunrising_checks.xml" />
-
- <property name="checkstyle.report.style" value="${basedir}/contrib/checkstyle-noframes.xsl" />
-
- <property name="checkstyle.result" value="${project.checkstyle.report.dir}/${project.check.result.name}" />
-
- <property name="checkstyle.report" value="${project.checkstyle.report.dir}/${project.check.report.name}" />
-
- <mkdir dir="${project.checkstyle.report.dir}" />
- </target>
- <taskdef resource="checkstyletask.properties" classpath="${basedir}/lib/checkstyle-all-5.0-beta01.jar" />
- <!-- - - - - - - - - - - - - - - - - -
- target: checkstyle
- - - - - - - - - - - - - - - - - - -->
- <target name="checkstyle" depends="init" description="Check java code and report ">
- <echo>"${checkstyle.config}"</echo>
- <checkstyle config="${checkstyle.config}" failOnViolation="false" failureProperty="checkstyle.failure">
- <formatter type="xml" tofile="${checkstyle.result}" />
- <fileset dir="${project.src.dir}" includes="**/*.java" />
- </checkstyle>
- <xslt in="${checkstyle.result}" out="${checkstyle.report}" style="${checkstyle.report.style}" />
- </target>
- <!-- - - - - - - - - - - - - - - - - -
- target: mailTarget
- - - - - - - - - - - - - - - - - - -->
- <target name="mailCheckStyleReport">
- <mail mailhost="mail.mydomain.cn" mailport="25" subject="Checkstyle violation(s) in project ${ant.project.name}" user="myname@mydomain.cn" password="mypass" files="myattchment">
- <from address="ci@mydomain.cn" />
- <replyto address="cimanager@mydomain.cn" />
- <to address="myname@mydomain.cn" />
- <message>TEST MAIL FROM CheckStyle</message>
- </mail>
- </target>
- </project>
3、注意
A)CheckStyle的jar位于当前basedir目录的lib中;
B)javax.activation.jar和mail.jar放到apache-ant-1.7.0\lib目录下,否则mailTarget不可用。
发表于 @
2008年11月10日 13:14:00 | | 编辑|
举报| 收藏