首页 > 代码库 > checkstyle+ant生成checkstyle报告

checkstyle+ant生成checkstyle报告

<?xml version="1.0" encoding="UTF-8" ?>
<project name="tibim" default="xml2html"
	xmlns:cs="antlib:com.puppycrawl.tools.checkstyle.ant" basedir=".">
	<description>
		checkstyle tibim project!
	</description>
	<property name="extrlib"
		location="D:\jenkins\svn\web\TiBIM\webapps\web\WEB-INF\lib" />
	<property name="checkstyleFile" value="http://www.mamicode.com/checkstyle" />
	<property name="project.src" location="./src" />
	<target name="clean" description="clean up">
		<delete dir="${checkstyleFile}" />
	</target>
	<path id="compile.classpath">
		<fileset dir="${extrlib}">
			<include name="**/*.jar" />
		</fileset>
	</path>
	<target name="init" depends="clean">
		<!-- Create the classes directory structure used by compile -->
		<mkdir dir="${checkstyleFile}" />
	</target>
	<target name="checkstyle" depends="init"
		description="Generates a report of code convention violations.">
		<taskdef
			resource="com/puppycrawl/tools/checkstyle/ant/checkstyle-ant-task.properties"
			classpath="${extrlib}/checkstyle-8.0-all.jar" />
		<checkstyle config="${extrlib}/code_rules.xml"
			failureProperty="checkstyle.failure" failOnViolation="false">
			<formatter type="xml" tofile="${checkstyleFile}/checkstyle_report.xml" />
			<fileset dir="${project.src}" includes="**/*.java" />
		</checkstyle>
	</target>
	<target name="xml2html" depends="checkstyle">
		<xslt in="${checkstyleFile}/checkstyle_report.xml" out="${checkstyleFile}/checkstyle.html"
			style="${extrlib}/checkstyle-frames.xsl">
			<param name="output.dir" expression="${checkstyleFile}" />
		</xslt>
	</target>
</project>

  其中checkstyle-8.0-all.jar是checkstyle依赖的jar包,可以在https://sourceforge.net/projects/checkstyle/files/checkstyle/处下载使用

  code_rules.xml是公司内部的checkstyle规范文档,可以在http://checkstyle.sourceforge.net/处下载sun公司或者google的代码规范

  checkstyle-frames.xsl是生成checkstyle测试报告的样式表,可以在github上,https://github.com/checkstyle/contribution下面xsl文件下找到

欢迎转载,转载请注明出处:http://www.cnblogs.com/hustar0102/p/5885115.html

checkstyle+ant生成checkstyle报告