<project name="Clover_Tutorial" default="clover.report" basedir=".">

    <!--
        How to call this build file:

        ant -f build_quick.xml install.clover
        ant -f build_quick.xml

        The first one installs Clover in Ant. The latter one calls default 'clover.report' target.
    -->

    <!--
        Install clover.jar into Ant's classpath. This must be done only once, we recommend installing
        it manually or via separate 'ant' command call. Without this JAR present in the Ant's classpath,
        the <javac> task will not be able to find CloverCompilerAdapter class, which is being set by
        the <clover-setup> task. Do not confuse Ant's classpath with <javac> task's build path - these
        are two different things.
    -->
    <target name="install.clover">
        <copy todir="${user.home}/.ant/lib">
            <fileset dir="../lib" includes="clover-*.jar"/>
            <mapper type="glob" from="clover-*.jar" to="clover.jar"/>
        </copy>
    </target>


    <property name="build.classes" location="build/classes"/>
    <property name="build.testclasses" location="build/testclasses"/>
    <property name="build.testresults" location="build/testresults"/>

    <property name="junit.jar" location="lib/junit-4.12.jar"/>
    <property name="hamcrest.jar" location="lib/hamcrest-core-1.3.jar"/>
    <!-- Ensure you have copied clover.jar to this location by calling install.clover target -->
    <property name="clover.jar" location="${user.home}/.ant/lib/clover.jar"/>

    <path id="build.classpath">
        <pathelement path="${clover.jar}"/>
        <pathelement location="${build.classes}"/>
    </path>

    <path id="testbuild.classpath">
        <path refid="build.classpath"/>
        <pathelement location="${junit.jar}"/>
        <pathelement location="${hamcrest.jar}"/>
        <pathelement location="${build.testclasses}"/>
    </path>

    <property name="clover.db" location="build/clover/db/clover.db"/>

    <!-- Import Clover's tasks -->
    <taskdef resource="cloverlib.xml"/>

    <target name="with.clover">
	    <clover-setup initstring="${clover.db}"/>
    </target>

    <target name="compile" depends="with.clover">
        <mkdir dir="${build.classes}"/>
        <javac srcdir="src/main/java" destdir="${build.classes}" classpathref="build.classpath" includeantruntime="false"/>

        <mkdir dir="${build.testclasses}"/>
        <javac srcdir="src/test/java" destdir="${build.testclasses}" classpathref="testbuild.classpath" includeantruntime="false"/>
    </target>

    <target name="test" depends="compile">
        <mkdir dir="${build.testresults}"/>
        <junit fork="yes" printsummary="true" showoutput="true">
            <classpath refid="testbuild.classpath"/>
            <formatter type="xml"/>
            <batchtest fork="yes" todir="${build.testresults}">
                <fileset dir="${build.testclasses}" includes="**/*Test.*"/>
            </batchtest>
        </junit>
    </target>

    <target name="clover.report" depends="test">
	    <clover-html-report outdir="build/clover_html" title="Clover Demo" initstring="${clover.db}"/>
    </target>

    <target name="clean">
        <delete dir="build"/>
    </target>

</project>
