<!--
 ! ASM: a very small and fast Java bytecode manipulation framework
 ! Copyright (c) 2000,2002,2003 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="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">  
    <path id="test.classpath">
      <path refid="classpath"/>
      <pathelement location="${out.build}"/>
      <pathelement location="${out.test}"/>
      <pathelement path="${bcel.path}"/>
      <pathelement path="${serp.path}"/>  
      <pathelement path="${javassist.path}"/>
      <pathelement path="${janino.path}"/>
    </path>
  </target>
  
  <!-- ==================================== -->
  <!-- =========== COMPILATION ============ -->
  <!-- ==================================== -->

  <target name="compile.test.conform" depends="init" if="test.conform.exist">
    <mkdir dir="${out.test}"/>
    <javac srcdir="${test.conform}" destdir="${out.test}">
      <classpath refid="test.classpath"/>
      <include name="**/*.java"/>
    </javac>
  </target>

  <target name="compile.test.deviance" depends="init" if="test.deviance.exist">
    <mkdir dir="${out.test}"/>
    <javac srcdir="${test.deviance}" destdir="${out.test}">
      <classpath refid="test.classpath"/>
      <include name="**/*.java"/>
    </javac>
  </target>

  <target name="compile.test.thread" depends="init" if="test.thread.exist">
    <mkdir dir="${out.test}"/>
    <javac srcdir="${test.thread}" destdir="${out.test}">
      <classpath refid="test.classpath"/>
      <include name="**/*.java"/>
    </javac>
  </target>

  <target name="compile.test.stress" depends="init" if="test.stress.exist">
    <mkdir dir="${out.test}"/>
    <javac srcdir="${test.stress}" destdir="${out.test}">
      <classpath refid="test.classpath"/>
      <include name="**/*.java"/>
    </javac>
  </target>

  <target name="compile.test.perf" depends="init" if="test.perf.exist">
    <mkdir dir="${out.test}"/>
    <javac srcdir="${test.perf}" destdir="${out.test}">
      <classpath refid="test.classpath"/>
      <include name="**/*.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.group}" 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"/>
  
</project>
