<?xml version="1.0" encoding="ISO-8859-1"?>
<project default="buildall" xmlns:j="jelly:core" xmlns:u="jelly:util" xmlns:ant="jelly:ant" >

  <goal name="buildall">
      <attainGoal name="test:utest"/>
      <attainGoal name="jar"/>
      <attainGoal name="site"/>
  </goal>


  <postGoal name="xdoc:register-reports">

<!--    <attainGoal name="maven-checkstyle-plugin:deregister"/>-->
<!--    <attainGoal name="maven-changelog-plugin:deregister"/>-->

<!--    <attainGoal name="maven-jxr-plugin:deregister"/>-->
<!--    <attainGoal name="maven-linkcheck-plugin:deregister"/>-->

    <!--
    <attainGoal name="maven-jdepend-plugin:deregister"/>
    <attainGoal name="maven-statcvs-plugin:deregister"/>
    <attainGoal name="maven-javadoc-plugin:deregister"/>
    <attainGoal name="maven-developer-activity-plugin:deregister"/>
    <attainGoal name="maven-changes-plugin:deregister"/>
    <attainGoal name="maven-file-activity-plugin:deregister"/>
    <attainGoal name="maven-license-plugin:deregister"/>
    <attainGoal name="maven-junit-report-plugin:deregister"/>
    -->
    <!--
    -->
    <attainGoal name="maven-statcvs-plugin:register"/>
    <attainGoal name="maven-jcoverage-plugin:register"/>


  </postGoal>




   <goal name="test:test">
     <!--attainGoal name="test:utest" /-->
   </goal>

   <goal name="test:utest"
        description="Test the application"
        prereqs="test:compile">

<!-- from test:compile! -->
    <j:set var="maven.test.searchdir" value="${maven.test.dest}"/>
    <j:if test="${context.getVariable('maven.test.search.classdir') == null}">
	  <j:set var="maven.test.searchdir" value="${pom.build.unitTestSourceDirectory}"/>
    </j:if>
<!-- from test:compile! -->

    <j:if test="${unitTestSourcesPresent == 'true' and context.getVariable('maven.test.skip') != 'true'}">

      <taskdef
        name="junit"
        classname="org.apache.tools.ant.taskdefs.optional.junit.JUnitTask"

      >
      </taskdef>

      <junit printSummary="${maven.junit.printSummary}"
             failureProperty="maven.test.failure"
             fork="${maven.junit.fork}">
        <j:if test="${context.getVariable('maven.junit.jvm') != null}">
          <setProperty name="jvm" value="${maven.junit.jvm}" />
        </j:if>
        <j:if test="${!context.getVariable('maven.junit.fork').toString().trim().equalsIgnoreCase('no')}">
          <setProperty name="dir" value="${maven.junit.dir}" />
        </j:if>
        <sysproperty key="basedir" value="${basedir}"/>
        <u:tokenize var="listOfProperties" delim=" ">${maven.junit.sysproperties}</u:tokenize>
        <j:forEach var="someProperty" items="${listOfProperties}">
          <sysproperty key="${someProperty}" value="${context.getVariable(someProperty)}"/>
        </j:forEach>
        <u:tokenize var="listOfEnv" delim=" ">${maven.junit.envvars}</u:tokenize>
        <j:forEach var="someEnv" items="${listOfEnv}">
          <env key="${someEnv}" value="${context.getVariable(someEnv)}"/>
        </j:forEach>
        <u:tokenize var="listOfJvmArgs" delim=" ">${maven.junit.jvmargs}</u:tokenize>
        <j:forEach var="somejvmarg" items="${listOfJvmArgs}">
          <jvmarg value="${somejvmarg}"/>
        </j:forEach>
        <formatter type="xml"/>
        <!--formatter type="${maven.junit.format}" usefile="${maven.junit.usefile}"/-->

      <formatter classname="junitour.UnitourSummaryResultFormatter" usefile="${maven.junit.usefile}" />
      <formatter classname="junitour.UnitourResultFormatter" extension=".xml" />

        <classpath>
          <pathelement location="${maven.test.dest}"/>
          <pathelement location="${maven.build.dest}"/>
          <path refid="maven.dependency.classpath"/>
          <pathelement path="${plugin.getDependencyPath('junit')}"/>
          <pathelement path="${plugin.getDependencyPath('junitour')}"/>
          <j:if test="${!context.getVariable('maven.junit.fork').toString().trim().equalsIgnoreCase('no')}">
            <pathelement path="${plugin.getDependencyPath('xml-apis')}"/>
            <pathelement path="${plugin.getDependencyPath('xerces')}"/>
          </j:if>
        </classpath>

        <batchtest todir="${maven.test.reportsDirectory}">
          <fileset dir="${maven.test.searchdir}">
            <j:forEach var="pat" items="${pom.build.unitTest.includes}">
              <include name="${pat}"/>
            </j:forEach>
            <j:forEach var="pat" items="${pom.build.unitTest.excludes}">
              <exclude name="${pat}"/>
            </j:forEach>
              <!-- KEEP ALL ABSTRACT TESTS FROM BEING RUN! -->
              <exclude name="**/*AbstractTestCase.java"/>
          </fileset>
        </batchtest>
      </junit>

      <j:if test="${maven.test.failure}">
        <j:if test="${context.getVariable('maven.test.failure.ignore') != 'true'}">
          <fail message="There were test failures."/>
        </j:if>
      </j:if>

    </j:if>

    <j:if test="${!unitTestSourcesPresent}">
      <echo>No tests to run.</echo>
    </j:if>

  </goal>

   <goal name="test:uutest" description="Test the application"
       prereqs="test:compile">
     <echo message="Great, you're using Unitour Unit Testing, Now checking enivronment variables:..." />
     <echo message="junit - location=${pom.getDependencyPath('junit')}" />
     <echo message="maven-test-plugin#maven.test.dest - location=${pom.getPluginContext('maven-test-plugin').getVariable('maven.test.dest')}" />
     <echo message="pom#maven.test.dest - location=${pom.getVariable('maven.test.dest')}" />
     <echo message="maven.test.dest - location=${maven.test.dest}" />
     <echo message="maven.build.dest - location=${maven.build.dest}" />
     <echo message="maven.dependency.classpath - location=${maven.dependency.classpath}" />


   <j:if test="${unitTestSourcesPresent == 'true' and context.getVariable('maven.test.skip') != 'true'}">

     <ant:path id="unit.classpath">
       <ant:path refid="maven.dependency.classpath"/>
       <ant:pathelement location="${maven.test.dest}"/>
       <ant:pathelement location="${maven.build.dest}"/>
       <ant:pathelement path="${pom.getDependencyPath('junit')}"/>
       <ant:pathelement path="${pom.getDependencyPath('junitour')}"/>
     </ant:path>


     <ant:taskdef
       name="junit"
       classname="org.apache.tools.ant.taskdefs.optional.junit.JUnitTask"
       classpathref="unit.classpath"/>

     <ant:junit printSummary="false"
            failureProperty="maven.test.failure"
            fork="${maven.junit.fork}"
            dir="${maven.junit.dir}">

       <sysproperty key="basedir" value="${basedir}"/>
       <u:tokenize var="listOfProperties" delim=" ">${maven.junit.sysproperties}</u:tokenize>
       <j:forEach var="someProperty" items="${listOfProperties}">
         <sysproperty key="${someProperty}" value="${context.getVariable(someProperty)}"/>
       </j:forEach>
       <u:tokenize var="listOfJvmArgs" delim=" ">${maven.junit.jvmargs}</u:tokenize>
       <j:forEach var="somejvmarg" items="${listOfJvmArgs}">
         <jvmarg value="${somejvmarg}"/>
       </j:forEach>
      <!--j:if test="${maven.junit.printSummary== 'true'}">
         <formatter usefile="false" classname="junitour.UnitourSummaryResultFormatter" />
      </j:if-->

      <ant:formatter classname="junitour.UnitourSummaryResultFormatter" usefile="${maven.junit.usefile}" />
      <ant:formatter classname="junitour.UnitourResultFormatter" extension=".xml" />

       <ant:classpath>
         <pathelement location="${pom.getPluginContext('maven-test-plugin').getVariable('maven.test.dest')}"/>
         <pathelement location="${pom.getPluginContext('maven-test-plugin').getVariable('maven.test.dest')}"/>
         <pathelement location="${maven.build.dest}"/>
         <ant:path refid="maven.dependency.classpath"/>
         <ant:path refid="unit.classpath"/>
       </ant:classpath>

       <ant:batchtest todir="${pom.getPluginContext('maven-test-plugin').getVariable('maven.test.reportsDirectory')}">
         <ant:fileset dir="${pom.build.unitTestSourceDirectory}">
<!--         <ant:fileset dir="src/java/test">-->
           <j:forEach var="pat" items="${pom.build.unitTest.includes}">
             <include name="${pat}"/>
           </j:forEach>
           <j:forEach var="pat" items="${pom.build.unitTest.excludes}">
             <exclude name="${pat}"/>
           </j:forEach>
             <!-- KEEP ALL ABSTRACT TESTS FROM BEING RUN! -->
             <exclude name="**/*AbstractTestCase.java"/>
         </ant:fileset>
       </ant:batchtest>
     </ant:junit>

     <j:if test="${maven.test.failure}">
       <j:set var="ignore__" value="${maven.test.failure.ignore}X"/>
       <j:if test="${ignore__ == 'X'}">
         <fail message="There were test failures."/>
       </j:if>
     </j:if>

   </j:if>

   <j:if test="${!unitTestSourcesPresent}">
     <echo>No tests to run.</echo>
   </j:if>

 </goal>



</project>
