<?xml version="1.0"?>

<project name="Apache Sandesha" default="usage" basedir=".">
    <description>
   Build File for Samples in Apache Sandesha

   This file is intended for ANT, a Java based build tool.
   ANT is available from http://jakarta.apache.org/ant/index.html

Prerequisites:
   J2SDK 1.4          from http://java.sun.com/
   jakarta-ant        from http://jakarta.apache.org/ant/
   commons-logging    from http://jakarta.apache.org/commons/logging.html
   log4j              from http://jakarta.apache.org/log4j

Optional components:
   junit              from http://www.junit.org/

Build Instructions:
   To build, run

     ant "target"

   on the directory where this file is located with the target you want.

    </description>

    <target name="usage">
        <echo message="                                                                            "/>
        <echo message="----------------------------------------------------------------------------"/>
        <echo message=" Available Targets Are                                                      "/>
        <echo message="   ping_sync       -->AsyncPing Sample                                      "/>
        <echo message="   ping_async      -->SyncPing  Sample                                      "/>
        <echo message="   echo_sync_ack   -->EchoStirng Sample                                     "/>
        <echo message="   echo_async_ack  -->EchoStirng Sample                                     "/>
        <echo message="   clean           --> cleans up all generated files and                    "/>
        <echo message="   usage           --> provides help on using the build tool  (default)     "/>
        <echo message="----------------------------------------------------------------------------"/>
        <echo message="                                                                            "/>
    </target>

    <target name="check.jar">
        <available property="sandesha.jar.found1" file="../Sandesha-1.0.jar"/>
        <available property="target.directory.found" file="../target/Sandesha-1.0.jar"/>
    </target>

    <target name="set.jar.at.root" depends="check.jar" unless="sandesha.jar.found1">
        <echo message="Cannot find the Sandesha-1.0.jar."/>
        <fail message="If you are using the source distribution, please build the source using maven before running the samples."/>
    </target>

    <target name="check.target.dir" depends="check.jar" unless="target.directory.found">
        <mkdir dir="../target"/>
        <antcall target="set.jar.at.root"/>
    </target>


    <target name="init" depends="check.target.dir">
        <property name="dir.libs" value="../lib"/>
        <property name="dir.root" value="../"/>
        <property name="dir.target" value="../target"/>
        <property name="jar.name" value="Sandesha-1.0.jar"/>

        <mkdir dir="classes"/>

        <path id="classpath.libraries" description="3rd party libs">
            <fileset dir="${dir.libs}">
                <include name="**/*.jar"/>
            </fileset>
            <fileset dir="${dir.root}">
                <include name="${jar.name}"/>
            </fileset>
            <fileset dir="${dir.target}">
                <include name="${jar.name}"/>
            </fileset>
            <pathelement location="classes"/>

        </path>

        <javac srcdir="." destdir="classes" debug="on">
            <classpath refid="classpath.libraries"/>
        </javac>

    </target>



    <!--===========================//Interop Section//============================================-->
    <!--
       //Targets in this section is used to test the basic interops. Here Sandesha client and the
       //Sandesha server are tested with each other. TCP Monitors will be started automatically to
       //view the message flow.
    -->


    <target name="run_tcp1" depends="init">
        <java classname="org.apache.axis.utils.tcpmon" fork="true" spawn="true">
            <arg value="8070"/>
            <arg value="localhost"/>
            <arg value="8080"/>
            <classpath refid="classpath.libraries"/>
        </java>
    </target>
    <target name="run_tcp2" depends="init">
        <java classname="org.apache.axis.utils.tcpmon" fork="true" spawn="true">
            <arg value="9070"/>
            <arg value="localhost"/>
            <arg value="9090"/>
            <classpath refid="classpath.libraries"/>

        </java>
    </target>


    <!-- =================================================================== -->
    <!-- Launches the functional test HTTP server -->
    <!-- =================================================================== -->
    <target name="run_server" depends="init">
        <echo message="Starting test http server."/>
        <java classname="org.apache.axis.transport.http.SimpleAxisServer" spawn="true" fork="yes">
            <arg line="-p 8080"/>  <!-- arbitrary port -->
            <classpath refid="classpath.libraries"/>
        </java>
    </target>


    <target name="run_interop_async_ping" depends="run_tcp1,run_tcp2,run_server">
        <java classname="org.apache.sandesha.samples.AsyncPingClient">
            <classpath refid="classpath.libraries"/>
        </java>
    </target>

    <target name="run_interop_sync_ping" depends="run_tcp1,run_server">
        <java classname="org.apache.sandesha.samples.SyncPingClient">
            <classpath refid="classpath.libraries"/>
        </java>
    </target>

    <target name="run_interop_echo_string_async_ack" depends="run_tcp1,run_tcp2,run_server">
        <java classname="org.apache.sandesha.samples.EchoClientAsyncAck">
            <classpath refid="classpath.libraries"/>
        </java>
    </target>

    <target name="run_interop_echo_string_sync_ack" depends="run_tcp1,run_tcp2,run_server">
        <java classname="org.apache.sandesha.samples.EchoClientSyncAck">
            <classpath refid="classpath.libraries"/>
        </java>
    </target>

    <target name="shutdown_server" depends="init">
        <echo message="ShutDown the server "/>
        <java classname="org.apache.axis.client.AdminClient" fork="yes" spawn="true">
            <classpath refid="classpath.libraries"/>
            <arg line="quit -p 8080"/>
        </java>
    </target>

    <target name="ping_sync" depends="run_interop_sync_ping,shutdown_server"> </target>
    <target name="ping_async" depends="run_interop_async_ping,shutdown_server"> </target>
    <target name="echo_sync_ack" depends="run_interop_echo_string_sync_ack,shutdown_server"> </target>
    <target name="echo_async_ack" depends="run_interop_echo_string_async_ack,shutdown_server"> </target>

    <!--=============================//End of Interop Testing//====================================-->


</project>