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

    <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 -->
    <property name="clover.jar" location="${user.home}/.ant/lib/clover.jar"/>

    <path id="build.classpath">
        <pathelement location="${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>

    <taskdef resource="cloverlib.xml"/>

    <property name="clover.ordering" value="failfast"/>   <!-- @ordering: optional; values "failfast", "orginal" or "random"; default: "failfast"; -->
    <property name="clover.optimize" value="true"/>      <!-- Enable/Disable optimization -->
    <property name="clover.minimize" value="true"/>      <!-- Exclude tests, or run all?  -->
    <property name="clover.fullrunevery" value="10"/>    <!-- Determine how many builds between full builds. -->
    <property name="clover.snapshot.file" value=".clover/clover.snapshot"/>


    <target name="compile">
        <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}">
                <clover-optimized-testset snapshotfile="${clover.snapshot.file}"
                                          fullrunevery="${clover.fullrunevery}"
                                          enabled="${clover.optimize}"
                                          minimize="${clover.minimize}"
                                          ordering="${clover.ordering}">
                    <fileset dir="${build.testclasses}" includes="**/*Test.*"/>
                </clover-optimized-testset>
            </batchtest>
        </junit>
    </target>

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

    <target name="with.clover">
        <clover-setup/>
    </target>

    <target name="clover.snapshot">
        <clover-snapshot file="${clover.snapshot.file}"/>
    </target>

    <target name="clover.report">
        <clover-html-report outdir="build/clover_html" title="Tutorial"/>
    </target>

    <target name="clover.all" depends="with.clover, test, clover.snapshot, clover.report" 
            description="Runs a build with Clover and generates a Clover HTML report">
    </target>

</project>
