<?xml version="1.0" encoding="UTF-8"?>
<project name="DMDirc-tests" default="default" basedir=".">
    <description>Test-related tasks for DMDirc.</description>

    <target name="-init-clover" depends="-init-dependencies">
        <taskdef resource="cloverlib.xml" classpathref="test-classpath"/>
        <taskdef resource="cloverjunitlib.xml" classpathref="test-classpath"/>
        <property name="clover.license.path" location="etc/clover.license"/>
        <property name="clover.init.string" location=".clover/clover.db"/>

        <condition property="clover.installed">
            <and>
                <available classname="com.cenqua.clover.CloverInstr"/>
                <available file="etc/clover.license"/>
            </and>
        </condition>

        <property name="plugins.build.target" value="compile-for-tests"/>
    </target>

    <target name="with.clover" depends="-init-clover,clean" if="clover.installed"
            description="Set up Clover to instrument tests.">
        <clover-clean/>
        <clover-env/>
        <clover-setup initstring="${clover.init.string}">
            <fileset dir="src/com/" includes="**/*.java" />
            <fileset dir="modules/parser/src/" includes="**/*.java" />
            <fileset dir="modules/util/src/" includes="**/*.java" />
            <fileset dir="modules/plugins/src/" includes="**/*.java" />
            <fileset dir="test/">
                <include name="**/*.java" />
                <exclude name="**/harness/**/*.java" />
            </fileset>
            <fileset dir="modules/parser/test/">
                <include name="**/*.java" />
                <exclude name="**/harness/**/*.java" />
            </fileset>
            <fileset dir="modules/util/test/">
                <include name="**/*.java" />
                <exclude name="**/harness/**/*.java" />
            </fileset>
            <fileset dir="modules/plugins/test/">
                <include name="**/*.java" />
                <exclude name="**/harness/**/*.java" />
            </fileset>
            <methodContext name="private_ctor" regexp="(.* )?private +[a-zA-Z0-9_$]+ *\( *\).*"/>
        </clover-setup>
    </target>

    <target name="clover.snapshot" depends="with.clover" if="clover.installed">
        <clover-snapshot/>
    </target>

    <target name="clover.xml" if="clover.installed" depends="-init-clover"
            description="Generate a Clover XML report.">
        <mkdir dir="reports/clover" />
        <clover-report>
            <current outfile="reports/clover/clover.xml">
                <format type="xml" filter="private_ctor"/>
            </current>
        </clover-report>
    </target>

    <target name="clover.html" if="clover.installed" depends="-init-clover"
            description="Generate a Clover HTML report.">
        <mkdir dir="reports/clover" />
        <mkdir dir="reports/clover/history" />
        <clover-historypoint historydir="reports/clover/history" />
        <clover-report>
            <current outfile="reports/clover">
                <format type="html" filter="private_ctor"/>
             </current>
             <historical outfile="reports/clover" historydir="reports/clover/history" />
        </clover-report>
    </target>

    <property name="test.reports" value="./junitreports" />

    <target name="-do-test-reports">
        <mkdir dir="${test.reports}" />
        <junitreport todir="${test.reports}">
            <fileset dir="${build.test.results.dir}">
                <include name="TEST-*.xml" />
            </fileset>
            <report todir="${test.reports}" />
        </junitreport>
    </target>

    <target name="test-html" depends="with.clover,compile-test,test,clover.html,clover.snapshot"
            description="Run tests and generate a Clover HTML report."/>
    <target name="test-xml" depends="with.clover,compile-test,test,clover.xml,clover.snapshot"
            description="Run tests and generate a Clover XML report."/>
    <target name="test-both" depends="test-html,test-xml"
            description="Run tests and generate Clover XML and HTML reports."/>

    <target name="teamcity-clover-report">
        <xslt in="reports/clover/clover.xml" style="checkstyle/clover.xsl" out="teamcity-info.xml" />
    </target>

</project>
