<?xml version="1.0"?>

<project 
  xmlns:ant="jelly:ant"
  xmlns:doc="doc"
  xmlns:j="jelly:core">
  
  <goal name="maven-junit-report-plugin:register">
    <j:if test="${unitTestSourcesPresent == 'true'}">
      <doc:registerReport 
        name="Unit Tests"
        pluginName="maven-junit-report-plugin"
        description="Report on the results of the unit tests."
        link="junit-report"/>
    </j:if>
  </goal>
  
  <goal name="maven-junit-report-plugin:deregister">
    <j:if test="${unitTestSourcesPresent == 'true'}">
      <doc:deregisterReport name="Unit Tests"/>
    </j:if>
  </goal>

  <!-- ================================================================== -->
  <!-- C R E A T E  J U N I T  X M L  R E P O R T                         -->
  <!-- ================================================================== -->

  <goal
    name="maven-junit-report-plugin:report"
    description="Generate a report from the test results">

    <j:if test="${unitTestSourcesPresent == 'true'}">

      <!-- Make sure that the report is generated whether the tests pass or
           not -->
      <j:set var="ignoreTestFailureOld" value="${maven.test.failure.ignore}"/>
      <j:set var="maven.test.failure.ignore" scope="parent" value="true"/>
      <attainGoal name="test:test"/>
      <j:set var="maven.test.failure.ignore" scope="parent" 
        value="${ignoreTestFailureOld}"/>

      <j:set var="testReportsDirectory"
        value="${pom.getPluginContext('maven-test-plugin').getVariable('maven.test.reportsDirectory')}"/>

      <ant:mkdir dir="${testReportsDirectory}"/>

      <!-- Consolidate the reports into a single -->
      <ant:junitreport todir="${maven.build.dir}">
        <ant:fileset dir="${testReportsDirectory}">
          <ant:include name="TEST-*.xml"/>
        </ant:fileset>
      </ant:junitreport>

      <doc:jsl
        input="${maven.build.dir}/TESTS-TestSuites.xml"
        output="junit-report.xml"
        stylesheet="${plugin.resources}/junit.jsl"
        outputMode="xml"
        prettyPrint="true"
      />

    </j:if>
    
  </goal>

</project>
