<?xml version="1.0"?>

<!-- Build script for the chapter 12 examples -->
<project name="Chapter 12 build" default="build-all">
   <property name="chapter.dir" value="${build.dir}/ws" />

    <path id="client.path">
        <pathelement location="${src.resources}" />
       <!-- <pathelement location="${lib.dir}/log4j.jar" />-->

        <fileset dir="${jboss.dist}/client">
            <include name="**/*.jar" />
            <!--<exclude name="log4j.jar" />-->
        </fileset>

        <pathelement location="${jboss.dist}/server/default/lib/cglib.jar" />
        <pathelement location="${lib.dir}/asm.jar" />
        <pathelement location="${build.classes.dir}" />
    </path>

   <target name="prepare">
       <mkdir dir="${chapter.dir}" />
       <mkdir dir="${build.src.dir}/wsdl" />
   </target>

   <target name="config">
   </target>
   
   <target name="compile-src" depends="config">
   </target>

   <target name="build-all">
       <antcall target="chap12-jars" />
   </target>

   <target name="wstools-ejb">
       <taskdef name="wstools" classname="org.jboss.ws.tools.ant.wstools"> 
           <classpath refid="client.path" />
       </taskdef> 

       <mkdir dir="${chapter.dir}/ejb" />
       
       <wstools dest="${chapter.dir}/ejb" 
                config="${src.dir}/org/jboss/ws/wstools-ejb-config.xml"/> 
   </target>

   <target name="wstools-servlet">
       <taskdef name="wstools" classname="org.jboss.ws.tools.ant.wstools"> 
           <classpath refid="client.path" />
       </taskdef> 

       <mkdir dir="${chapter.dir}/servlet" />

       <wstools dest="${chapter.dir}/servlet"
                config="${src.dir}/org/jboss/ws/wstools-servlet-config.xml"/> 
   </target>

   <target name="chap12-jars" depends="prepare,wstools-ejb">
       <jar destfile="${chapter.dir}/hello-ejb.jar"
            basedir="${build.classes.dir}">
           <metainf dir="${src.dir}/org/jboss/ws/ejbmeta">
               <include name="ejb-jar.xml" />
           </metainf>

           <metainf dir="${chapter.dir}/ejb">
               <include name="jaxrpc-mapping.xml" /> 
               <include name="webservices.xml" />
               <include name="wsdl/HelloService.wsdl" />
           </metainf>

           <include name="org/jboss/ws/hello/**" />
       </jar>
   </target>

   <target name="chap12-war" depends="prepare,wstools-servlet">
       <property name="meta" value="${src.dir}/org/jboss/ws/servletmeta" />

       <war destfile="${chapter.dir}/hello-servlet.war" webxml="${meta}/web.xml">
           <webinf dir="${chapter.dir}/servlet">
               <include name="jaxrpc-mapping.xml" /> 
               <include name="webservices.xml" />
               <include name="wsdl/HelloService.wsdl" />
           </webinf>

           <classes dir="${build.classes.dir}">
               <include name="org/jboss/ws/hello/*.class" />
           </classes>
       </war>
   </target>

   <target name="ch12-ex.jar" depends="prepare">
       <jar destfile="${chapter.dir}/ch12-ex.jar"
            basedir="${build.classes.dir}">

           <metainf dir="${src.dir}/org/jboss/ws/example">
               <include name="ejb-jar.xml" />
               <include name="jboss.xml" />
               <include name="mapping.xml" />
           </metainf>

           <metainf dir="${src.dir}/org/jboss/ws/hello/">
               <include name="wsdl/HelloService.wsdl" />
           </metainf>

           <include name="org/jboss/ws/example/*.class" />
           <include name="org/jboss/ws/hello/Hello.class" />
       </jar>
   </target>



   <target name="run-example1" depends="chap12-war">
       <copy file="${chapter.dir}/hello-servlet.war"
             todir="${jboss.dist}/server/default/deploy"/>

       <echo message="Waiting for 5 seconds for deploy..." />
       <sleep seconds="5"/>
       

       <java dir="${build.classes.dir}" fork="yes" failOnError="true"
             className="org.jboss.ws.client.HelloClient">
          
           <jvmarg value="-Djava.endorsed.dirs=${jboss.dist}/lib/endorsed" />
           <arg value="http://localhost:8080/hello-servlet/Hello?wsdl" />
           <arg value="JBoss user" />
           <classpath>
               <pathelement location="${build.dir}/classes"/>
               <path refid="client.path" />
           </classpath>
       </java>      
   </target>
   
   <target name="run-example1b" depends="chap12-war">
       <copy file="${chapter.dir}/hello-servlet.war"
             todir="${jboss.dist}/server/default/deploy"/>

       <echo message="Waiting for 5 seconds for deploy..." />
       <sleep seconds="5"/>
       

       <java dir="${build.classes.dir}" fork="yes" failOnError="true"
             className="org.jboss.ws.client.HelloClientDII">
           
           <jvmarg value="-Djava.endorsed.dirs=${jboss.dist}/lib/endorsed" />
           <arg value="http://localhost:8080/hello-servlet/Hello?wsdl" />
           <arg value="JBoss DII user" />
           <classpath>
               <pathelement location="${build.dir}/classes"/>
               <path refid="client.path" />
           </classpath>
       </java>      
   </target>



   <target name="run-example2" depends="chap12-jars">
       <copy file="${chapter.dir}/hello-ejb.jar"
             todir="${jboss.dist}/server/default/deploy"/>
       
       <echo message="Waiting for 5 seconds for deploy..." />
       <sleep seconds="5"/>
       
       <java dir="${build.classes.dir}" fork="yes" failOnError="true"
             className="org.jboss.ws.client.HelloClient">
           <jvmarg value="-Djava.endorsed.dirs=${jboss.dist}/lib/endorsed" />
           
           <arg value="http://localhost:8080/HelloBeanService/HelloBean?wsdl" />
           <arg value="JBoss user" />
           <classpath>
               <pathelement location="${build.dir}/classes"/>
               <path refid="client.path" />
           </classpath>
       </java>      
   </target>

   <target name="run-example2b" depends="chap12-jars">
       <copy file="${chapter.dir}/hello-ejb.jar"
             todir="${jboss.dist}/server/default/deploy"/>
       
       <echo message="Waiting for 5 seconds for deploy..." />
       <sleep seconds="5"/>
       
       <java dir="${build.classes.dir}" fork="yes" failOnError="true"
             className="org.jboss.ws.client.HelloClientDII">
           
           <jvmarg value="-Djava.endorsed.dirs=${jboss.dist}/lib/endorsed" />
           <arg value="http://localhost:8080/HelloBeanService/HelloBean?wsdl" />
           <arg value="JBoss DII user" />
           <classpath>
               <pathelement location="${build.dir}/classes"/>
               <path refid="client.path" />
           </classpath>
       </java>      
   </target>



                             

   <target name="run-example3" depends="chap12-war,ch12-ex.jar">
       <copy file="${chapter.dir}/hello-servlet.war"
             todir="${jboss.dist}/server/default/deploy"/>

       <echo message="Waiting for 5 seconds for deploy..." />
       <sleep seconds="5"/>

       <copy file="${chapter.dir}/ch12-ex.jar"
             todir="${jboss.dist}/server/default/deploy"/>

       <echo message="Waiting for 5 seconds for deploy..." />
       <sleep seconds="5"/>
       

      <java dir="${build.classes.dir}" fork="yes" failOnError="true"
            className="org.jboss.ws.client.ExampleClient">
          
          <classpath>
              <pathelement location="${build.dir}/classes"/>
              <path refid="client.path" />
          </classpath>
      </java>      

   </target>

</project>
