<?xml version="1.0"?>
<!-- 
/*
 * Copyright 2001-2004 The Apache Software Foundation.
 * 
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *      http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
 -->


<project 
  xmlns:ant="jelly:ant"
  xmlns:doc="doc"
  xmlns:j="jelly:core"
  xmlns:maven="jelly:maven">
  
  <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" 
    prereqs="junit-report:report"/>

  <goal name="junit-report: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}"/>

      <maven:pluginVar var="testReportsDirectory" plugin='maven-test-plugin' property='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>
