<?xml version="1.0" encoding="UTF-8"?>

<!--

   To run the example, set JBOSS_HOME and run ant (with no parameters)

   $Id: build.xml 3140 2007-09-26 08:44:19Z ataylor $

 -->

<project name="WebServicesExample" default="run">

   <property environment="ENV"/>

   <!-- These properties may be overriden by calling ants when this example is used in a smoke test -->
   <property file="../examples.properties"/>
   <property name="jboss.home" value="${ENV.JBOSS_HOME}"/>
   <property name="messaging.client.jar.path" value="${jboss.home}/client"/>
   <property name="messaging.client.jar.name" value="jboss-messaging-client.jar"/>
   <property name="jboss.configuration" value="all"/>
   <property name="example.queue.name" value="testQueue"/>

   <path id="common.compilation.classpath">
      <fileset file="${jboss.home}/client/jboss-j2ee.jar"/>
      <fileset file="${messaging.client.jar.path}/${messaging.client.jar.name}"/>
   </path>

   <property name="jboss.client" value="${jboss.home}/client"/>

   <path id="runtime.classpath">
      <path refid="common.compilation.classpath"/>
      <pathelement path="./etc"/>
      <pathelement path="../common/output/classes"/>
      <pathelement path="./output/classes"/>
      <pathelement location="${messaging.client.jar.path}/${messaging.client.jar.name}"/>

      <!-- all this stuff for WebServices -->
      <pathelement location="${jboss.home}/lib/endorsed/xercesImpl.jar"/>
      <pathelement location="${jboss.client}/activation.jar"/>
      <pathelement location="${jboss.client}/commons-logging.jar"/>
      <pathelement location="${jboss.client}/javassist.jar"/>
      <pathelement location="${jboss.client}/jbossall-client.jar"/>
      <pathelement location="${jboss.client}/jbossws-client.jar"/>
      <pathelement location="${jboss.client}/log4j.jar"/>
      <pathelement location="${jboss.client}/mail.jar"/>
      <pathelement location="${jboss.client}/jboss-xml-binding.jar"/>
      <pathelement location="${jboss.client}/jboss-jaxws.jar"/>
      <pathelement location="${jboss.client}/jboss-jaxrpc.jar"/>
      <pathelement location="${jboss.client}/jboss-saaj.jar"/>
      <pathelement location="${jboss.client}/wsdl4j.jar"/>
      <pathelement location="${jboss.client}/jaxb-api.jar"/>
   </path>

   <path id="client.classpath">
      <path refid="common.compilation.classpath"/>
      <pathelement path="./etc"/>
      <pathelement path="../common/output/classes"/>
      <pathelement path="./output/client-classes"/>

      <!-- all this stuff for WebServices -->
      <fileset file="${jboss.home}/server/${jboss.configuration}/lib/jboss-remoting.jar"/>
      <pathelement location="${jboss.client}/activation.jar"/>
      <pathelement location="${jboss.client}/commons-logging.jar"/>
      <pathelement location="${jboss.client}/javassist.jar"/>
      <pathelement location="${jboss.client}/jbossall-client.jar"/>
      <pathelement location="${jboss.client}/jbossws-client.jar"/>
      <pathelement location="${jboss.client}/log4j.jar"/>
      <pathelement location="${jboss.client}/mail.jar"/>
      <pathelement location="${jboss.client}/jboss-xml-binding.jar"/>
      <pathelement location="${jboss.client}/jboss-jaxws.jar"/>
      <pathelement location="${jboss.client}/jboss-jaxrpc.jar"/>
      <pathelement location="${jboss.client}/jboss-saaj.jar"/>
      <pathelement location="${jboss.client}/wsdl4j.jar"/>
      <pathelement location="${jboss.client}/jaxb-api.jar"/>
      <pathelement location="${jboss.home}/lib/endorsed/xercesImpl.jar"/>


      <pathelement location="${messaging.client.jar.path}/${messaging.client.jar.name}"/>
      <pathelement location="${jboss.home}/client/jbossall-client.jar"/>
      <pathelement location="${jboss.home}/server/${jboss.configuration}/lib/log4j.jar"/>
      <pathelement location="${jboss.home}/server/${jboss.configuration}/lib/javassist.jar"/>
      <pathelement location="${jboss.home}/server/${jboss.configuration}/deploy/jboss-aop-jdk50.deployer/jboss-aop-jdk50.jar"/>
      <pathelement location="${jboss.home}/server/${jboss.configuration}/deploy/jboss-aop-jdk50.deployer/trove.jar"/>


   </path>

   <target name="identify">
      <echo message="###########################################################################"/>
      <echo message="#              Running the WebServices example                            #"/>
      <echo message="###########################################################################"/>
      <echo message="The queue:      ${example.queue.name}"/>
      <echo message="The client jar: ${messaging.client.jar.path}/${messaging.client.jar.name}"/>
   </target>

   <target name="sanity-check" depends="identify">
      <available property="client.jar.present" file="${messaging.client.jar.path}/${messaging.client.jar.name}"/>
      <fail message="Could not find client jar ${messaging.client.jar.path}/${messaging.client.jar.name}"
            unless="client.jar.present"/>
   </target>

   <target name="init" depends="sanity-check">
      <mkdir dir="./output/classes/META-INF"/>
      <mkdir dir="./output/lib"/>
      <mkdir dir="../common/output/classes"/>
   </target>

   <target name="compile" depends="init">
      <javac destdir="../common/output/classes" debug="on" debuglevel="lines,vars,source">
         <src path="../common/src"/>
         <classpath refid="common.compilation.classpath"/>
      </javac>
      <javac destdir="./output/classes" debug="on" debuglevel="lines,vars,source">
         <src path="./src"/>
         <classpath refid="runtime.classpath"/>
      </javac>
   </target>

   <target name="run-wsdl-client" depends="compile">
      <taskdef name="wstools" classname="org.jboss.ws.tools.ant.wstools">
        <classpath refid="runtime.classpath"/>
      </taskdef>

      <mkdir dir="./output/client"/>

      <get src="http://127.0.0.1:8080/jms-web-service/JMSWebServiceExample?wsdl" dest="./output/service.wsdl" />

      <wstools config="./etc/client-config/client-config.xml"
               dest="./output/client"/>
   </target>


   <target name="war" depends="compile">
      <jar destfile="./output/lib/jms-web-service.war">
         <zipfileset dir="./output/classes" prefix="WEB-INF/classes"/>
         <zipfileset dir="./etc/WEB-INF" prefix="WEB-INF"/>
      </jar>
   </target>

   <target name="deploy" depends="war">
      <copy file="./output/lib/jms-web-service.war"
            todir="${jboss.home}/server/${jboss.configuration}/deploy"/>
      <antcall target="sleep"><param name="sleep.interval" value="10"/></antcall>
   </target>

   <target name="compile-client">
      <mkdir dir="./output/client-classes"/>
      <javac destdir="./output/client-classes" debug="on" debuglevel="lines,vars,source">
         <src path="./output/client"/>
         <src path="./src-client"/>
         <classpath refid="runtime.classpath"/>
      </javac>
   </target>


   <target name="run" depends="deploy, run-wsdl-client, compile-client">
      <antcall target="send-and-receive"/>
      <antcall target="undeploy"/>
   </target>

   <target name="send-and-receive">
      <!-- The client expects to find the name of the queue to connect to as value of the
           'example.queue.name' property, which *may* be defined by calling ants when this example
            is used in a smoke test -->
      <java classname="org.jboss.example.jms.webservices.client.Client"
            classpathref="client.classpath" fork="yes" failonerror="true">
         <sysproperty key="example.queue.name" value="${example.queue.name}"/>
         <!--
         <jvmarg line="-Xdebug -Xnoagent -Djava.compiler=NONE -Xrunjdwp:transport=dt_shmem,server=y,suspend=y,address=example"/>
          -->
      </java>
   </target>

   <target name="undeploy">
      <delete file="${jboss.home}/server/${jboss.configuration}/deploy/jms-web-service.war"
              quiet="true"/>
   </target>

   <target name="clean" depends="undeploy">
      <delete dir="./output" quiet="true"/>
      <delete dir="../common/output" quiet="true"/>
   </target>

   <target name="sleep">
      <echo message="Sleeping for ${sleep.interval} seconds ..."/>
      <sleep seconds="${sleep.interval}"/>
   </target>

</project>

