<!--
 ! ASM: a very small and fast Java bytecode manipulation framework
 ! Copyright (c) 2000-2005 INRIA, France Telecom
 ! All rights reserved.
 !
 ! Redistribution and use in source and binary forms, with or without
 ! modification, are permitted provided that the following conditions
 ! are met:
 ! 1. Redistributions of source code must retain the above copyright
 !    notice, this list of conditions and the following disclaimer.
 ! 2. Redistributions in binary form must reproduce the above copyright
 !    notice, this list of conditions and the following disclaimer in the
 !    documentation and/or other materials provided with the distribution.
 ! 3. Neither the name of the copyright holders nor the names of its
 !    contributors may be used to endorse or promote products derived from
 !    this software without specific prior written permission.
 !
 ! THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
 ! AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 ! IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 ! ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
 ! LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
 ! CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
 ! SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 ! INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
 ! CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 ! ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
 ! THE POSSIBILITY OF SUCH DAMAGE.
-->

<project name="test" default="test">

  <!-- ==================================== -->
  <!-- ======== PROPERTY DEFINITION ======= -->
  <!-- ==================================== -->

  <property name="test.conform"   value="${test}/conform"/>
  <property name="test.deviance"  value="${test}/deviance"/>
  <property name="test.thread"    value="${test}/thread"/>
  <property name="test.stress"    value="${test}/stress"/>
  <property name="test.perf"      value="${test}/perf"/>

  <target name="properties">
    <condition property="asm.test" value="${java.home}/lib/rt.jar,test/conform/cases">
      <not><isset property="asm.test"/></not>
    </condition>
    
    <condition property="asm.test.class" value="">
      <not><isset property="asm.test.class"/></not>
    </condition>

    <condition property="java5">
      <available classname="java.lang.annotation.Annotation"/> 
    </condition>
      
    <condition property="test.conform.exist">
      <available file="${test.conform}"/>
    </condition>

    <condition property="test.deviance.exist">
      <available file="${test.deviance}"/>
    </condition>

    <condition property="test.thread.exist">
      <available file="${test.thread}"/>
    </condition>

    <condition property="test.stress.exist">
      <available file="${test.stress}"/>
    </condition>

    <condition property="test.perf.exist">
      <available file="${test.perf}"/>
    </condition>
    
    <condition property="test.all">
      <and>
        <not><isset property="test.type"/></not>
        <not><isset property="test.group"/></not>
        <not><isset property="test.name"/></not>
      </and>
    </condition>

    <condition property="test.paths.configured">
      <and>
        <isset property="bcel.path"/>
        <isset property="serp.path"/>
        <isset property="javassist.path"/>
        <isset property="janino.path"/>
      </and>
    </condition>
  </target>

  <!-- ================================== -->
  <!-- ========  INITIALIZATION   ======= -->
  <!-- ================================== -->
  
  <target name="check" unless="test.paths.configured">
    <echo message="The 'build.properties' file must be configured"/>
    <fail/>
  </target>
  
  <target name="init" depends="properties,check">  
    <mkdir dir="${out.test}"/>
    <mkdir dir="${out.test}/reports"/>
    <path id="test.classpath">
      <pathelement location="${classes}"/>
      <pathelement location="${out.test}"/>
      <pathelement path="${bcel.path}"/>
      <pathelement path="${serp.path}"/>  
      <pathelement path="${javassist.path}"/>
      <pathelement path="${janino.path}"/>
      <path refid="cobertura.classpath"/>
    </path>
  </target>
  
  <!-- ==================================== -->
  <!-- =========== COMPILATION ============ -->
  <!-- ==================================== -->

  <target name="compile.test.conform" depends="init" if="test.conform.exist">
    <javac srcdir="${test.conform}" destdir="${out.test}" 
        debug="on" debuglevel="lines,vars,source">
      <classpath refid="test.classpath"/>
      <include name="**/*.java"/>
      <exclude name="annotations/**/*.java" unless="java5"/>
      <exclude name="**/AnnotationTest.java" unless="java5"/>
    </javac>
    <copy todir="${out.test}">
  	  <fileset dir="${test.conform}">
        <include name="**/*.txt"/>
        <include name="**/*.data"/>
      </fileset>
    </copy>
  </target>

  <target name="compile.test.deviance" depends="init" if="test.deviance.exist">
    <javac srcdir="${test.deviance}" destdir="${out.test}" debug="on" source="1.3" target="1.2">
      <classpath refid="test.classpath"/>
      <include name="**/*.java"/>
    </javac>
  </target>

  <target name="compile.test.thread" depends="init" if="test.thread.exist">
    <javac srcdir="${test.thread}" destdir="${out.test}" debug="on" source="1.3" target="1.2">
      <classpath refid="test.classpath"/>
      <include name="**/*.java"/>
    </javac>
  </target>

  <target name="compile.test.stress" depends="init" if="test.stress.exist">
    <javac srcdir="${test.stress}" destdir="${out.test}" debug="on" source="1.3" target="1.2">
      <classpath refid="test.classpath"/>
      <include name="**/*.java"/>
    </javac>
  </target>

  <target name="compile.test.perf" depends="init" if="test.perf.exist">
    <javac srcdir="${test.perf}" destdir="${out.test}" debug="on" source="1.3" target="1.2">
      <classpath refid="test.classpath"/>
      <include name="**/*.java"/>
      <exclude name="**/xml/*.java"/>
    </javac>
  </target>

  <target name="compile" depends="compile.test.conform,compile.test.deviance,compile.test.thread,compile.test.stress,compile.test.perf"/>

  <!-- ============================= -->
  <!-- =========== TEST ============ -->
  <!-- ============================= -->

  <target name="testAll" depends="compile" if="test.all">
    <multipleAnt dir="${test.conform}" inheritRefs="true"/>
    <!--multipleAnt dir="${test.deviance}" inheritRefs="true"/>
    <multipleAnt dir="${test.thread}" inheritRefs="true"/>
    <multipleAnt dir="${test.stress}" inheritRefs="true"/-->
    <multipleAnt dir="${test.perf}" inheritRefs="true"/>
  </target>

  <target name="testType" depends="compile" if="test.type">
    <multipleAnt dir="${test}/${test.type}" inheritRefs="true"/>
  </target>

  <target name="testGroup" depends="compile" if="test.group">
    <ant antfile="test/${test.group}.xml" inheritRefs="true"/>
  </target>

  <target name="testName" depends="compile" if="test.name">
    <multipleAnt dir="${test.conform}" target="${test.name}" inheritRefs="true"/>
    <!--multipleAnt dir="${test.deviance}" target="${test.name}" inheritRefs="true"/>
    <multipleAnt dir="${test.thread}" target="${test.name}" inheritRefs="true"/>
    <multipleAnt dir="${test.stress}" target="${test.name}" inheritRefs="true"/-->
    <multipleAnt dir="${test.perf}" target="${test.name}" inheritRefs="true"/>
  </target>

  <target name="test" depends="testAll,testType,testGroup,testName">
    <!--junitreport todir="${out.test}/reports">
      <fileset dir="${out.test}/reports">
        <include name="TEST-*.xml"/>
      </fileset>
      <report todir="${out.test}/reports"/>
    </junitreport-->
  </target>
  
</project>