<?xml version="1.0"?>

<!--
  Expected properties:
    - catalina-ant.jar
    - catalina.username
    - catalina.password
    - tomcat.home
-->
<project name="Beehive/RunTomcatTasks" default="usage" basedir=".">

    <property name="catalina-ant.jar" location="${tomcat.home}/server/lib/catalina-ant.jar"/>

    <target name="deploy" description="Deploy a webapp to a running Tomcat server">
        <fail unless="context.path" message="Can't deploy webapp; the value ${context.path} was unspecified"/>
        <fail unless="webapp.dir" message="Can't deploy webapp; the value ${webapp.dir} was unspecified"/>

        <available property="webapp.available" file="${webapp.dir}" type="dir"/>
        <fail unless="webapp.available" message="The webapp at ${webapp.dir} does not exist."/>

        <property name="_url" value="file://${webapp.dir}"/>
        <echo>deploy webapp from ${_url} with context path ${context.path}</echo>

        <taskdef name="tomcatdeploy" classname="org.apache.catalina.ant.DeployTask" classpath="${catalina-ant.jar}"/>
        <tomcatdeploy path="/${context.path}" localWar="${_url}" username="${catalina.username}" password="${catalina.password}"/>
    </target>

    <target name="undeploy" description="Undeploy a webapp running on a Tomcat server">
        <fail unless="context.path" message="Can't undeploy webapp; the value ${context.path} was unspecified"/>

        <taskdef name="tomcatundeploy" classname="org.apache.catalina.ant.UndeployTask" classpath="${catalina-ant.jar}"/>
        <tomcatundeploy path="/${context.path}" username="${catalina.username}" password="${catalina.password}"/>
    </target>

    <target name="redeploy" description="Redeploy a webapp already running on a Tomcat server">
        <fail unless="context.path" message="Can't undeploy webapp; the value ${context.path} was unspecified"/>

        <taskdef name="tomcatreload" classname="org.apache.catalina.ant.ReloadTask" classpath="${catalina-ant.jar}"/>
        <tomcatreload path="/${context.path}" username="${catalina.username}" password="${catalina.password}"/>
    </target>

    <target name="start" description="Start a Tomcat instance.">

        <condition property="cmdline.options" value="">
            <not><isset property="cmdline.options"/></not>
        </condition>

        <condition property="java.options" value="">
            <not><isset property="java.options"/></not>
        </condition>

        <echo>startup.dir: ${tomcat.home}/bin</echo>
        <echo>cmdline.options: ${cmdline.options}</echo>
        <echo>java.options: ${java.options}</echo>

        <echo>Start Tomcat</echo>
        <exec os="Windows 2000,Windows 2003,Windows XP" dir="${tomcat.home}\bin" executable="cmd.exe">
            <env key="JAVA_OPTS" value="${java.options}"/>
            <arg line="/c startup.bat ${cmdline.options}"/>
        </exec>
        <exec os="Linux,SunOS,Solaris" dir="${tomcat.home}/bin" executable="sh">
            <env key="JAVA_OPTS" value="${java.options}"/>
            <arg line="startup.sh ${cmdline.options}"/>
       </exec>
    </target>

    <target name="stop" description="Stop the NetUI server">
        <echo>Stop Tomcat in: ${tomcat.home}</echo>
        <exec os="Windows 2000,Windows 2003,Windows XP" dir="${tomcat.home}\bin" executable="cmd.exe">
            <arg line=" /c shutdown"/>
        </exec>

        <exec os="Linux,SunOS,Solaris" dir="${tomcat.home}/bin" executable="sh">
            <arg line="shutdown.sh"/>
        </exec>
    </target>

</project>