
    <!-- Global properties -->
    <property name="cactus.conf.tomcat3x" value="${cactus.conf.dir}/tomcat3x"/>
    <property name="cactus.target.tomcat3x" value="${cactus.target.dir}/tomcat3x"/>

    <!--
       ========================================================================
         Run Tomcat 3.x tests
       ========================================================================
    -->
    <target name="cactus.run.tomcat3x" 
        depends="cactus.init,cactus.setup.tomcat3x,cactus.war,cactus.deploy.tomcat3x"
        if="cactus.home.tomcat3x" description="Run tests on Tomcat 3.x">

        <!-- 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 -->

        <antcall target="cactus.runservertests.tomcat3x" inheritRefs="true"/>

    </target>

    <target name="cactus.runservertests.tomcat3x" depends="cactus.runservertests.task.tomcat3x, cactus.runservertests.target.tomcat3x"/>

    <target name="cactus.runservertests.task.tomcat3x" if ="cactus.test.task">

        <taskdef name="cactus.testTask" classname="${cactus.test.task}"/>
        <runservertests
            testURL="http://localhost:${cactus.port}/${cactus.context}/ServletRedirector?Cactus_Service=RUN_TEST"
            startTarget="cactus.start.tomcat3x"
            stopTarget="cactus.stop.tomcat3x">
          <test>
          	<cactus.testTask/>
          </test>
        </runservertests>

    </target>

    <target name="cactus.runservertests.target.tomcat3x" unless="cactus.test.task">

        <runservertests
            testURL="http://localhost:${cactus.port}/${cactus.context}/ServletRedirector?Cactus_Service=RUN_TEST"
            startTarget="cactus.start.tomcat3x"
            stopTarget="cactus.stop.tomcat3x"
            testTarget="cactus.test"/>

    </target>

    <!--
       ========================================================================
         Start Tomcat 3.x
       ========================================================================
    -->
    <target name="cactus.start.tomcat3x" description="Start Tomcat 3.x"
        depends="cactus.check.tomcat3x" if="cactus.home.tomcat3x">

        <java jvm="${cactus.jvm}" classname="org.apache.tomcat.startup.Main" 
            fork="yes">

            <sysproperty key="tomcat.home" file="${cactus.target.tomcat3x}"/>
            <sysproperty key="tomcat.install" file="${cactus.home.tomcat3x}"/>

            <classpath>
                <fileset dir="${cactus.home.tomcat3x}/lib">
                    <include name="tomcat.jar"/>
                </fileset>
            </classpath>

            <arg value="start"/>

        </java>

    </target>

    <!--
       ========================================================================
         Stop Tomcat 3.3
       ========================================================================
    -->
    <target name="cactus.stop.tomcat3x" description="Stop Tomcat 3.x"
        depends="cactus.check.tomcat3x" if="cactus.home.tomcat3x">

        <java jvm="${cactus.jvm}" classname="org.apache.tomcat.startup.Main" 
            fork="yes">

            <sysproperty key="tomcat.home" file="${cactus.target.tomcat3x}"/>
            <sysproperty key="tomcat.install" file="${cactus.home.tomcat3x}"/>

            <classpath>
                <fileset dir="${cactus.home.tomcat3x}/lib">
                    <include name="tomcat.jar"/>
                </fileset>
            </classpath>

            <arg value="stop"/>

        </java>

    </target>

    <!--
       ========================================================================
         Display a warning message if the needed servlet engine home property
         is not set
       ========================================================================
    -->
    <target name="cactus.check.tomcat3x" unless="cactus.home.tomcat3x">

        <echo></echo>
        <echo>******************************************************</echo>
        <echo>WARNING : The 'cactus.home.tomcat3x' property has not</echo>
        <echo>been set. No test will be run on that servlet engine.</echo>
        <echo>******************************************************</echo>
        <echo></echo>

    </target>

    <!--
       ========================================================================
         Deploy the cactified webapp
       ========================================================================
    -->
    <target name="cactus.deploy.tomcat3x" if="cactus.home.tomcat3x"
        description="Deploy the webapp on Tomcat 3.x">

        <!-- Copy the webapp -->
        <copy todir="${cactus.target.tomcat3x}/webapps/${cactus.context}">
            <fileset dir="${cactus.target.dir}/${cactus.context}"/>
        </copy>

    </target>

    <!--
       ========================================================================
         Set up a valid Tomcat 3.x directory structure in the
         cactus.target.tomcat3x directory.
       ========================================================================
    -->
    <target name="cactus.setup.tomcat3x"
        depends="cactus.init, cactus.check.tomcat3x" if="cactus.home.tomcat3x"
        description="Set up a Tomcat 3.x directory structure">

        <!-- Delete everything -->
        <delete dir="${cactus.target.tomcat3x}/webapps"/>

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

        <copy todir="${cactus.target.tomcat3x}/conf" filtering="on">
            <fileset dir="${cactus.conf.tomcat3x}"/>
        </copy>

    </target>
