<target name="run-emma" depends="-check.tests, -init-emma, -prepare-coverage, -run-junit, -report-coverage" if="has.tests" />
<target name="-check.tests">
<available property="has.tests" file="${workspace}/${project.name}/tests/src" type="dir" />
</target>
<target name="-init-emma" depends="-check.tests" if="has.tests">
<path id="emma.lib">
<pathelement location="lib/emma.jar" />
<pathelement location="lib/emma_ant.jar" />
</path>
<taskdef resource="emma_ant.properties" classpathref="emma.lib" />
<property name="instrumented.dir" value="${project.reports.dir}/instrumented" />
<property name="emma.coverage.dir" value="${project.reports.dir}/coverage" />
<mkdir dir="${emma.coverage.dir}" />
<property name="emma.metadata" value="${emma.coverage.dir}/metadata.emma" />
<property name="emma.dir" value="${emma.coverage.dir}/coverage.emma" />
</target>
<target name="-prepare-coverage" depends="-check.tests.sources" if="has.tests.sources">
<emma enabled="true">
<instr instrpath="${project.home}/classes" destdir="${instrumented.dir}" metadataFile="${emma.metadata}" merge="true" />
</emma>
</target>
<target name="-run-junit" depends="-check.tests" if="has.tests">
<property name="junit.dir" value="${project.reports.dir}/junit" />
<mkdir dir="${junit.dir}" />
<echo>Running junit for ${project.name}</echo>
<junit errorproperty="test.failed" failureproperty="test.failed" fork="true">
<classpath>
<pathelement location="${instrumented.dir}" />
<path refid="metrics.test.path" />
<pathelement location="${project.home}/migration" />
<path refid="emma.lib" />
</classpath>
<jvmarg value="-Demma.coverage.out.file=${emma.dir}" />
<jvmarg value="-Demma.coverage.out.merge=true" />
<formatter type="xml" />
<batchtest todir="${junit.dir}">
<fileset dir="${project.home}/tests/src" includes="**/*Test.java" />
</batchtest>
</junit>
<junitreport todir="${junit.dir}">
<fileset dir="${junit.dir}">
<include name="TEST-*.xml" />
</fileset>
<report format="frames" todir="${junit.dir}" />
</junitreport>
</target>
<target name="-report-coverage" depends="-check.tests.sources" if="has.tests.sources">
<emma enabled="true">
<report sourcePath="${project.home}/src">
<fileset dir="${emma.coverage.dir}" includes="*.emma" />
<xml outfile="${emma.coverage.dir}/coverage.xml" />
<html outfile="${emma.coverage.dir}/coverage.html" />
</report>
</emma>
</target>