<?xml version="1.0" encoding="UTF-8" standalone="no"?>

<project
	name="checkstyle"
	xmlns:cs="antlib:com.puppycrawl.tools.checkstyle">
	<!-- Checkstyle properties -->
	<property
		name="checkstyle.lib.dir"
		location="${ant.lib.dir}/checkstyle" />
	<property
		name="checkstyle.cfg.dir"
		location="${ant.cfg.dir}/checkstyle" />
	<property
		name="checkstyle.policy"
		location="${checkstyle.cfg.dir}/checkstyle-policy.xml" />
	<property
		name="checkstyle.xsl"
		location="${checkstyle.cfg.dir}/checkstyle-noframes-sorted.xsl" />
	<property
		name="checkstyle.build.dir"
		location="${build.dir}/checkstyle" />
	<property
		name="checkstyle.report.xml"
		location="${checkstyle.build.dir}/checkstyle.xml" />
	<property
		name="checkstyle.report.html"
		location="${checkstyle.build.dir}/checkstyle.html" />

	<!-- Checkstyle tasks -->
	<target
		name="checkstyle-init"
		depends="classpaths">
		<delete
			dir="${checkstyle.build.dir}" />

		<path
			id="checkstyle.classpath">
			<fileset
				dir="${checkstyle.lib.dir}">
				<include
					name="*.jar" />
			</fileset>
			<path
				refid="junit.classpath" />
			<path
				refid="compile.classpath" />
		</path>

		<taskdef
			uri="antlib:com.puppycrawl.tools.checkstyle"
			resource="com/puppycrawl/tools/checkstyle/antlib.xml"
			classpathref="checkstyle.classpath"
			onerror="failall" />
	</target>

	<target
		name="checkstyle-run"
		depends="checkstyle-init">
		<mkdir
			dir="${checkstyle.build.dir}" />
		<cs:checkstyle
			failOnViolation="false"
			failureProperty="checkstyle.failed"
			config="${checkstyle.policy}"
			classpathref="checkstyle.classpath">
			<formatter
				type="plain" />
			<formatter
				type="xml"
				toFile="${checkstyle.report.xml}" />
			<fileset
				dir="${src.dir}"
				includes="**/*.java" />
			<fileset
				dir="${testsrc.dir}"
				includes="**/*.java" />
		</cs:checkstyle>
	</target>

	<target
		name="checkstyle-report"
		depends="checkstyle-run"
		if="checkstyle.failed">
		<xslt
			style="${checkstyle.xsl}"
			in="${checkstyle.report.xml}"
			out="${checkstyle.report.html}" />
		<fail>
			Checkstyle reported style failures. See
			${checkstyle.report.html}
		</fail>
	</target>

	<target
		name="checkstyle"
		depends="checkstyle-report"
		description="Check that the source code adheres to the coding standard" />
</project>

