<?xml version="1.0" encoding="UTF-8"?>
<project name="quality-multi-bundle" xmlns:ivy="antlib:org.apache.ivy.ant">

	<import file="common.xml"/>

<!-- Main targets -->
	<target name="test" depends="jar, test.pre, test.do, test.post"
			description="Executes all tests resulting from a compilation of the test tree returning test success metrics."/>

	<target name="clover" depends="clover.pre, clover.do, clover.post"
			description="Executes all tests resulting from a compilation of the test tree returning test coverage metrics."/>

	<target name="findbugs" depends="findbugs.pre, findbugs.do"
			description="Checks all code from the source tree for bugs."/>

<!-- Other targets -->
	<target name="test.pre">
		<delete quiet="true" dir="${test-results.output.dir}"/>
		<mkdir dir="${test-results.output.dir}/xml"/>
	</target>

	<target name="test.do">
		<all-bundles target="test.do">
			<property name="test-results.output.dir" value="${test-results.output.dir}"/>
		</all-bundles>
	</target>

	<target name="test.post">
		<mkdir dir="${test-results.output.dir}/html"/>
		<junitreport>
			<fileset dir="${test-results.output.dir}/xml"/>
			<report format="frames" todir="${test-results.output.dir}/html"/>
		</junitreport>
		<delete file="TESTS-TestSuites.xml"/>
	</target>

	<target name="clover.init" depends="ivy.init">
		<ivy:cachepath resolveId="clover.classpath" pathid="clover.classpath" organisation="com.atlassian.clover"
				module="com.springsource.com.cenqua.clover" revision="${com.springsource.com.cenqua.clover.version}"
				conf="runtime" type="jar" inline="true" log="download-only"/>
		<taskdef resource="cloverlib.xml" classpathref="clover.classpath"/>
	</target>

	<target name="clover.pre" depends="clover.init">
		<delete dir="${clover.output.dir}" quiet="true"/>
		<mkdir dir="${clover.output.dir}"/>
	</target>

	<target name="clover.do">
		<clover-setup initstring="${clover.db.file}"/>
		<all-bundles target="clover.do">
			<property name="clover.output.dir" value="${clover.output.dir}"/>
			<property name="clover.db.file" value="${clover.db.file}"/>
			<property name="test-results.output.dir" value="${test-results.output.dir}"/>
		</all-bundles>
	</target>

	<target name="clover.post" depends="clover.init">
		<clover-report initstring="${clover.db.file}">
			<current outfile="${clover.output.dir}/clover.xml" span="30m">
				<format type="xml"/>
				<testsources dir="..">
					<include name="**/src/test/java/**/*.java"/>
					<include name="**/src/test/java/*.java"/>
				</testsources>
			</current>
		</clover-report>
		<clover-report initstring="${clover.db.file}">
			<current outfile="${clover.output.dir}/html" span="30m">
				<format type="html"/>
				<testsources dir="..">
					<include name="**/src/test/java/**/*.java"/>
					<include name="**/src/test/java/*.java"/>
				</testsources>
			</current>
		</clover-report>
		<clover-report initstring="${clover.db.file}">
			<current outfile="${clover.output.dir}/clover.pdf" summary="true" span="30m">
				<format type="pdf"/>
				<testsources dir="..">
					<include name="**/src/test/java/**/*.java"/>
					<include name="**/src/test/java/*.java"/>
				</testsources>
			</current>
		</clover-report>
		<clover-check initstring="${clover.db.file}" target="${clover.coverage}" haltOnFailure="${clover.enforce}"
				span="30m">
			<testsources dir="..">
				<include name="**/src/test/java/**/*.java"/>
				<include name="**/src/test/java/*.java"/>
			</testsources>
		</clover-check>
	</target>

	<target name="findbugs.pre">
		<delete dir="${findbugs.output.dir}" quiet="true"/>
		<mkdir dir="${findbugs.output.dir}"/>
	</target>

	<target name="findbugs.do">
		<all-bundles target="findbugs.do">
			<property name="findbugs.output.dir" value="${findbugs.output.dir}"/>
		</all-bundles>
	</target>

</project>