Files
Programs/Coverage/build.xml
T

86 lines
3.0 KiB
XML

<!-- Sample Ant build file for running RacingScore under JaCoCo -->
<!-- Jonathan Cook, 17 Sep 2015 -->
<project name="racingscore" default="jacocoreport" xmlns:jacoco="antlib:org.jacoco.ant">
<!-- property to allow ant to find jacoco: CHANGE THE PATH to point to yours -->
<property name="jacocodir" location="/home/jcook/tools/jacoco/lib" />
<property name="src" location="src/" />
<property name="build" location="bin/" />
<taskdef uri="antlib:org.jacoco.ant" resource="org/jacoco/ant/antlib.xml">
<classpath path="${jacocodir}/jacocoant.jar" />
</taskdef>
<!-- standard compile task, but turn debugging on for source viewing -->
<target name="compile" description="compile the source">
<mkdir dir="${build}"/>
<javac srcdir="${src}" destdir="${build}" includeantruntime="false" debug="true" />
</target>
<!-- tests if new jacoco run is needed by checking if the jacoco.exec file is
newer than the class files or this build file -->
<target name="checkRun">
<uptodate property="run.notneeded" targetfile="jacoco.exec">
<srcfiles dir="." includes="*.class build.xml" />
</uptodate>
</target>
<!-- run program under jacoco: this example has two runs, you'll need to perhaps
modify them, and then add more; this only runs if needed -->
<target name="jacocorun" depends="compile,checkRun" unless="run.notneeded">
<delete>
<!-- must delete coverage data file to start afresh (otherwise coverage accumulates) -->
<fileset dir="." includes="jacoco.exec" />
</delete>
<echo message="TEST RacingScore1: 8 9 6" />
<java classname="RacingScore1" fork="true">
<arg value="8" />
<arg value="9" />
<arg value="6" />
<jvmarg line="-javaagent:${jacocodir}/jacocoagent.jar" />
</java>
<echo message="TEST RacingScore2: 8 9 6" />
<java classname="RacingScore2" fork="true">
<arg value="8" />
<arg value="9" />
<arg value="6" />
<jvmarg line="-javaagent:${jacocodir}/jacocoagent.jar" />
</java>
</target>
<!-- tests if new jacoco report needs generated by checking if top report file
(index.html) is newer than the run data file (jacoco.exec) -->
<target name="checkReport">
<uptodate property="report.notneeded" targetfile="report/index.html" srcfile="jacoco.exec" />
</target>
<!-- generate a new jacoco report from a new data file; only runs if needed -->
<target name="jacocoreport" depends="jacocorun,checkReport" unless="report.notneeded">
<jacoco:report>
<executiondata>
<file file="jacoco.exec" />
</executiondata>
<structure name="racingscore">
<classfiles>
<fileset dir="." />
</classfiles>
<sourcefiles encoding="UTF-8">
<fileset dir="." />
</sourcefiles>
</structure>
<html destdir="report" />
</jacoco:report>
</target>
<!-- clean up by removing all generated files; do "ant clean" to start afresh -->
<target name="clean">
<delete>
<fileset dir="." includes="*.class jacoco.exec" />
</delete>
<delete dir="report" />
<delete dir="${build}"/>
</target>
</project>