网上找了好些个关于CheckStyle的文章都是抄抄抄一大通,却没有一个build.xml着实可运行,
在这里我也是参考着一编,改改成能成功运行并能生成正确报告,发送 Email 的build.xml文件1<?xml version="1.0" encoding="gb2312"?> 2 3<!-- ANT make file checkstype --> 4 5<!-- See <a href="http://jakarta.apache.org/ant" data-mce-href="http://jakarta.apache.org/ant">http://jakarta.apache.org/ant</a> for info about ANT --> 6<!-- 网上下来的CheckStyle解压在d:/javalib/CheckStyle/checkstyle-4.1中 --> 7<project name="checkstyle" default="checkstyle" basedir="d:/javalib/CheckStyle/checkstyle-4.1"> 8 9 <!-- CheckStyle配置,这里你替换成你实际的环境 --> 10 <property name="project.docs.dir" value="${basedir}/contrib"/> 11 12 <!-- 源代码的目录是e:/eclipseworkspace/talupdate/src --> 13 <property name="project.src.dir" value="e:/eclipseworkspace/talupdate/src"/> 14 15 <!-- 建立了build目录在其中生成报告 --> 16 <property name="project.checkstyleReport.dir" value="${basedir}/build"/> 17 <property name="checkstyle.jar" value="${basedir}/checkstyle-all-4.1.jar"/> 18 19 <!-- 使用SUN的代码规范,可替换成公司自己的规范 --> 20 <property name="checkstyle.config" value="${basedir}/sun_checks.xml"/> 21 <property name="checkstyle.report.style" value="${project.docs.dir}/checkstyle-noframes.xsl"/> 22 <property name="checkstyle.result" value="${project.checkstyleReport.dir}/checkstyle_result.xml"/> 23 <property name="checkstyle.report" value="${project.checkstyleReport.dir}/checkstyle_report.html"/> 24 25 <!-- 定义发送邮件列表 --> 26 <property name="mail.list" value="(User1)user1@xxx.com,(User2)user2@xxx.com"/> 27 28 <target name="init"> 29 <tstamp/> 30 </target> 31 32 <!--CheckStyle脚步--> 33 <taskdef resource="checkstyletask.properties" classpath="${checkstyle.jar}"/> 34 35 <target name="checkstyle" depends="init" description="对java源代码进行检查并产生检查报告. "> 36 <checkstyle config="${checkstyle.config}" failOnViolation="false" failureProperty="checkstyle.failure"> 37 <formatter type="xml" tofile="${checkstyle.result}"/> 38 <fileset dir="${project.src.dir}" includes="**/*.java"/> 39 </checkstyle> 40 41 <!-- 生成报告,其格式取决于${checkstyle.report.style} --> 42 <style in="${checkstyle.result}" out="${checkstyle.report}" style="${checkstyle.report.style}"/> 43 </target> 44 45 <!-- 当有不规范的情况发生时将检查结果发送到 --> 46 <target name="checkstyle-nightly" depends="checkstyle" if="checkstyle.failure" 47 description="Sends email if checkstyle detected code conventions violations."> 48 49 <!-- 如果邮件服务器需要验证,则加上 user 和 password 属性 --> 50 <mail from="(Admin)admin@xxx.com" tolist="${mail.list}" mailhost="mail.xxx.com" 51 subject=" checkstyle result from project reports" files="${checkstyle.report}"/> 52 </target> 53</project>
<继续补充内容>