<?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="EJB3MDBExample" 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}"/>
      <fileset file="${jboss.home}/client/jboss-ejb3x.jar"/>
   </path>

   <path id="example.compilation.classpath">
      <path refid="common.compilation.classpath"/>
      <pathelement path="../common/output/classes"/>
   </path>

   <path id="execution.classpath">
      <pathelement path="./etc"/>
      <pathelement path="../common/output/classes"/>
      <pathelement path="./output/classes"/>
      <fileset file="${messaging.client.jar.path}/${messaging.client.jar.name}"/>
      <fileset file="${jboss.home}/server/${jboss.configuration}/lib/jboss-remoting.jar"/>
      <fileset file="${jboss.home}/client/jbossall-client.jar"/>
      <fileset file="${jboss.home}/server/${jboss.configuration}/lib/log4j.jar"/>
      <fileset file="${jboss.home}/server/${jboss.configuration}/lib/javassist.jar"/>
      <fileset file="${jboss.home}/server/${jboss.configuration}/deploy/jboss-aop-jdk50.deployer/jboss-aop-jdk50.jar"/>
      <fileset file="${jboss.home}/server/${jboss.configuration}/deploy/jboss-aop-jdk50.deployer/trove.jar"/>
   </path>

   <target name="identify">
      <echo message="###########################################################################"/>
      <echo message="#                     Running the EJB3 MDB 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"/>
      <available property="ejb3.support.installed" file="${jboss.home}/server/${jboss.configuration}/deploy/ejb3.deployer"/>
      <fail message="EJB3 does not seem to be installed in ${jboss.home}/server/${jboss.configuration}! Install it and try again."
            unless="ejb3.support.installed"/>
   </target>

   <target name="init" depends="sanity-check">
      <mkdir dir="./output/classes/META-INF"/>
      <mkdir dir="./output/lib/META-INF"/>
      <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="example.compilation.classpath"/>
      </javac>
   </target>

   <target name="jar" depends="compile">
      <copy todir="./output/classes/META-INF" filtering="true">
         <fileset dir="./etc/META-INF" includes="*"/>
         <filterset>
            <filter token="QUEUE_NAME" value="${example.queue.name}"/>
         </filterset>
      </copy>
      <jar destfile="./output/lib/mdb-example.ejb3"
           basedir="./output/classes"
           includes="META-INF/**,org/jboss/example/**/EJB3MDBExample.class"/>
   </target>

   <target name="deploy" depends="jar">
      <copy file="./output/lib/mdb-example.ejb3"
            todir="${jboss.home}/server/${jboss.configuration}/deploy"/>
      <antcall target="sleep"><param name="sleep.interval" value="5"/></antcall>
   </target>

   <target name="run" depends="deploy">
      <antcall target="send"/>
      <antcall target="undeploy"/>
   </target>

   <target name="send">
      <!-- MDBExample 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.ejb3mdb.Sender"
         classpathref="execution.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/mdb-example.ejb3" 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>

