<?xml version="1.0"?> 
<project name="Tomcat-test" default="main" basedir=".">

  <!-- Compilation properties -->

  <property name="build.compiler" value="classic"/>
  <property name="optimize" value="false" />
  <property name="debug" value="on" />

  <!-- Directories -->
  <property name="ws" value="../../.." /> 
  <property name="work.dir" value="${ws}/jakarta-tomcat" /> 
  <property name="install.dir" value="${ws}" /> 

  <property name="tomcat.build" value="${ws}/jakarta-tomcat/build/tomcat"/>
  <property name="tomcat.dist" value="${ws}/jakarta-tomcat/dist/tomcat"/>
  <property name="wdst.webapp" value="${tomcat.build}/webapps/servlet-tests"/>

  <property name="watchdog.src" value="${ws}/jakarta-watchdog"/>
  <property name="watchdog.build" value="${watchdog.src}/../build/watchdog"/>

  <!-- ==================== Initialization - guessing config ========== -->
  <target name="init">
    <available file="${watchdog.src}/build.xml" 
	       property="watchdog.available" />
    <echo message="Testing ${watchdog.src}/build.xml ${watchdog.available}" />
  </target>

  <!-- ==================== Copy static files ==================== -->

  <target name="prepare" depends="init">
  </target>

  <!-- ==================== Build the internal test app ================== -->
  <target name="sanity-test" depends="init">
    <mkdir dir="${tomcat.build}/webapps/test"/>
    <!-- the golden files will be part of the webapp - no 
         need to have a separate directory or polute lib -->

    <mkdir dir="${tomcat.build}/webapps/test/Golden"/>
    <copy todir="${tomcat.build}/webapps/test/Golden">
            <fileset dir="src/tests/share/tests/jsp/Golden"/>
    </copy>

    <copy 
	  todir="${tomcat.build}/webapps/test">
            <fileset dir="src/tests/webpages"/>
    </copy>

    <javac 
	   srcdir="src/tests/webpages/WEB-INF/classes" 
	   optimize="${optimize}" 
	   destdir="${tomcat.build}/webapps/test/WEB-INF/classes" 
	   classpath="${tomcat.build}/classes;${servlet22.jar}" />

    <!-- build the test driver -->
    <javac 
	   srcdir="src/tests/share/gtest" 
	   optimize="${optimize}" 
	   destdir="${tomcat.build}/webapps/test/WEB-INF/classes" 
	   classpath="${tomcat.build}/classes" />
  </target>

  <target name="test.war" depends="sanity-test" >
    <jar 
	 jarfile="${tomcat.dist}/webapps/test.war" 
	 basedir="${tomcat.build}/webapps/test" includes="**"/> 
  </target>

  <target name="watchdog" if="watchdog.available" depends="init"> 
    <echo message="Building watchdog from ${watchdog.src} " />
    <!-- special arangements to allow running watchdog from web -->
    
    <mkdir dir="${tomcat.build}/webapps/servlet-tests"/>
    <mkdir dir="${tomcat.build}/webapps/jsp-tests"/>

    <copy todir="${tomcat.build}/webapps/jsp-tests" >
      <fileset dir="${watchdog.src}/src/server/jsp-tests" />
    </copy>
    <delete file="${tomcat.build}/webapps/jsp-tests/WEB-INF/lib/moo.jar" />
    <copy todir="${tomcat.build}/webapps/jsp-tests/Golden" >
    <fileset dir="${watchdog.src}/src/clients/org/apache/jcheck/jsp/client" />
    </copy>

    <copy todir="${tomcat.build}/webapps/servlet-tests" >
      <fileset dir="${watchdog.src}/src/server/servlet-tests" />
    </copy>
    <mkdir dir="${wdst.webapp}/WEB-INF/classes/org/apache/jcheck/props"/>
    <copy todir="${wdst.webapp}//WEB-INF/classes/org/apache/jcheck/props" >
      <fileset dir="${watchdog.src}/src/clients/org/apache/jcheck/props" />
    </copy>
    <mkdir dir="${wdst.webapp}/WEB-INF/classes/org/apache/jcheck/servlet"/>
    <copy todir="${wdst.webapp}//WEB-INF/classes/org/apache/jcheck/servlet" >
      <fileset dir="${watchdog.src}/src/clients/org/apache/jcheck/servlet" />
    </copy>

    <copy file="${watchdog.src}/src/conf/jsp-gtest.xml"
        todir="${tomcat.build}/webapps/jsp-tests/WEB-INF"/>
    <copy file="${watchdog.src}/src/conf/servlet-moo.xml"
        todir="${wdst.webapp}//WEB-INF"/>

    <javac 
	   srcdir="${tomcat.build}/webapps/jsp-tests/WEB-INF/classes" 
	   optimize="${optimize}" 
	   destdir="${tomcat.build}/webapps/jsp-tests/WEB-INF/classes" 
	   classpath="${tomcat.build}/classes;${servlet22.jar}"
	   />

    <!-- Watchdog requires a special client application -->
    <javac 
	   srcdir="${watchdog.src}/../jakarta-tools/moo/src/share"
	   optimize="${optimize}" 
	   destdir="${tomcat.build}/webapps/servlet-tests/WEB-INF/classes" 
	   classpath="${tomcat.build}/classes;${servlet22.jar}"
	   />

    <javac 
	   srcdir="${tomcat.build}/webapps/servlet-tests/WEB-INF/classes" 
	   optimize="${optimize}" 
	   destdir="${tomcat.build}/webapps/servlet-tests/WEB-INF/classes" 
	   classpath="${tomcat.build}/classes;${servlet22.jar}"
	   />

    <replace file="${tomcat.build}/webapps/jsp-tests/WEB-INF/jsp-gtest.xml" 
	     token="org.apache.tomcat.task.GTest" 
	     value="org.apache.tomcat.util.test.GTest" />

  </target>

  <!-- ==================== Admin & agreagate ==================== -->
   
  <target name="clean-classes" depends="init">
    <delete dir="${tomcat.build}/classes/org"/>
  </target>

  <target name="clean" depends="init">
    <delete dir="${tomcat.build}"/>
  </target>
  
  <target name="all" depends=""/>
  <target name="main" depends="sanity-test"/>
    
</project>
