<!-- 
/*
 * 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.
 */
 -->
    <!--
       ========================================================================
         Run Tomcat 3.3 tests
       ========================================================================
    -->
    <target name="test.tomcat.33" depends="prepare.test.tomcat.33"
        if="maven.appserver.home" description="Run tests on Tomcat 3.3">

        <!-- Start the servlet engine, wait for it to be started, run the
             unit tests, stop the servlet engine, wait for it to be stopped.
             The servlet engine is stopped if the tests fail for any reason -->

        <runservertests testURL="http://localhost:${test.port}/test"
            startTarget="start.tomcat.33"
            stopTarget="stop.tomcat.33"
            testTarget="test"/>

    </target>

    <!--
       ========================================================================
         Start Tomcat 3.3
       ========================================================================
    -->
    <target name="start.tomcat.33">

        <java classname="org.apache.tomcat.startup.Main" fork="yes">
            <jvmarg value="-Dtomcat.home=${target.tomcat33.full.dir}"/>
            <jvmarg value="-Dtomcat.install=${maven.appserver.home}"/>
            <arg value="start"/>
            <classpath>
                <fileset dir="${maven.appserver.home}/lib">
                    <include name="tomcat.jar"/>
                </fileset>
            </classpath>
        </java>

    </target>

    <!--
       ========================================================================
         Stop Tomcat 3.3
       ========================================================================
    -->
    <target name="stop.tomcat.33">

        <java classname="org.apache.tomcat.startup.Main" fork="yes">
            <jvmarg value="-Dtomcat.home=${target.tomcat33.full.dir}"/>
            <jvmarg value="-Dtomcat.install=${maven.appserver.home}"/>
            <arg value="stop"/>
            <classpath>
                <fileset dir="${maven.appserver.home}/lib">
                    <include name="tomcat.jar"/>
                </fileset>
            </classpath>
        </java>

    </target>

    <!--
       ========================================================================
         Display a warning message if the needed servlet engine home property
         is not set
       ========================================================================
    -->
    <target name="check.test.tomcat.33" unless="maven.appserver.home">

        <echo message=""/>
        <echo message="******************************************************"/>
        <echo message="WARNING : The 'maven.appserver.home' property has not been "/>
        <echo message="set. No test will be run on that servlet engine."/>
        <echo message="******************************************************"/>
        <echo message=""/>

    </target>

    <!--
       ========================================================================
         Prepare directories and variables for running the tests
       ========================================================================
    -->
    <target name="prepare.test.tomcat.33"
        depends="check.test.tomcat.33,testwar" if="maven.appserver.home">

        <echo message="maven.appserver.home = ${maven.appserver.home}"/>

        <property name="maven.appserver.dir"
            value="${target.test.dir}/tomcat33"/>
        <property name="conf.tomcat33.dir" value="${conf.test.dir}/tomcat33"/>
        <property name="target.tomcat33.full.dir"
            value="${basedir}/${maven.appserver.dir}"/>
        <filter token="maven.appserver.dir" value="${maven.appserver.dir}"/>

        <!-- Delete everything -->
        <delete dir="${maven.appserver.dir}/webapps"/>

        <!-- Create work and conf directories and copy configuration files -->
        <mkdir dir="${maven.appserver.dir}/conf"/>
        <mkdir dir="${maven.appserver.dir}/work"/>
        <mkdir dir="${maven.appserver.dir}/webapps"/>

        <copy todir="${maven.appserver.dir}/conf" filtering="on">
            <fileset dir="${conf.tomcat33.dir}"/>
        </copy>

        <!-- Copy the war file -->
        <copy file="${target.test.dir}/test.war"
            tofile="${maven.appserver.dir}/webapps/test.war"/>

    </target>
