<!-- targets.xml: Referenced by the build.xml files, this file
     contains targets common to all of the jaxrpc examples.  -->

  <taskdef name="deploy" classname="org.apache.catalina.ant.DeployTask" />
  <taskdef name="undeploy" classname="org.apache.catalina.ant.UndeployTask" />
  <taskdef name="list" classname="org.apache.catalina.ant.ListTask" />
  <taskdef name="start" classname="org.apache.catalina.ant.StartTask" />
  <taskdef name="stop" classname="org.apache.catalina.ant.StopTask" />

  <target name="deploy" 
     description="Deploys a Web application">
      <deploy url="${url}" username="${username}" password="${password}" 
        path="/${context-path}" war="file:${war-path}"   
      />
  </target>

  <target name="undeploy" 
     description="Undeploys a Web application">
      <undeploy url="${url}" username="${username}" password="${password}" 
        path="/${context-path}"     
      />
  </target>

  <target name="redeploy" 
      description="Undeploys and deploys a Web aplication">
      <antcall target="undeploy" />
      <antcall target="deploy" />
  </target>

  <target name="list" 
     description="Lists Web applications">
     <echo message="Listing the applications...."/>
     <list
        url="${url}" 
        username="${username}" 
        password="${password}" 
      />
  </target>

  <target name="start" 
     description="Starts a Web application">
     <echo message="Starting the application...."/>
     <start
        url="${url}" 
        username="${username}" 
        password="${password}" 
        path="/${context-path}" 
      />
  </target>

  <target name="stop" 
     description="Stops a Web application">
     <echo message="Stopping the application...."/>
     <stop
        url="${url}" 
        username="${username}" 
        password="${password}" 
        path="/${context-path}" 
      />
  </target>

  <target name="set-ws-scripts" 
     description="Sets the value of the wscompile and wsdeploy properties for this build file" >
     <condition property="script-suffix" value="bat">
        <os family="windows"/>
     </condition>
     <condition property="script-suffix" value="sh">
        <not>
           <os family="windows"/>
        </not>
     </condition>
     <property name="wscompile" value="${jwsdp.home}/bin/wscompile.${script-suffix}"/>
     <property name="wsdeploy" value="${jwsdp.home}/bin/wsdeploy.${script-suffix}"/>
  </target>

  <target name="prepare" 
     description="Creates the build and dist directories" >
     <echo message="Creating the required directories...." />
     <mkdir dir="${build}/client/${example}" />
     <mkdir dir="${build}/server/${example}" />
     <mkdir dir="${build}/shared/${example}" />
     <mkdir dir="${build}/wsdeploy-generated" />
     <mkdir dir="dist" />
     <mkdir dir="${build}/WEB-INF/classes/${example}" />
  </target>

  <target name="compile-server" depends="prepare"
      description="Compiles the server-side source code">
      <echo message="Compiling the server-side source code...."/>
      <javac
         srcdir="."
         destdir="${build}/shared"
         includes="*.java"
         excludes="*Client.java"
      />
  </target>

  <target name="setup-web-inf"
     description="Copies files to build/WEB-INF">
     <echo message="Setting up ${build}/WEB-INF...."/>
     <delete dir="${build}/WEB-INF" />
     <copy todir="${build}/WEB-INF/classes/${example}">
         <fileset dir="${build}/shared/${example}" />
         <fileset dir="${build}/server/${example}" />
     </copy>
     <copy file="web.xml" todir="${build}/WEB-INF" />
     <copy file="jaxrpc-ri.xml" todir="${build}/WEB-INF" />
  </target>

  <target name="package" 
      description="Packages the WAR file">
      <echo message="Packaging the WAR...."/>
      <delete file="dist/${portable-war}" />
      <jar jarfile="dist/${portable-war}" >
        <fileset dir="${build}" includes="WEB-INF/**" />
      </jar>
  </target>

  <target name="process-war" depends="set-ws-scripts"
      description="Runs wsdeploy to generate the ties and create a deployable WAR file">
      <echo message="Running wsdeploy...."/>
      <delete file="dist/${deployable-war}" />
   <exec executable="${wsdeploy}">
      <arg line="-tmpdir"/>
      <arg line="${build}/wsdeploy-generated"/>
      <arg line="-o"/>
      <arg line="dist/${deployable-war}"/>
      <arg line="dist/${portable-war}"/>
      <arg line="-verbose"/>
    </exec>
  </target>

  <target name="generate-stubs" depends="set-ws-scripts,prepare"
      description="Runs wscompile to generate the client stub classes">
      <echo message="Running wscompile...."/>
    <exec executable="${wscompile}">
       <arg line="-gen:client"/>
       <arg line="-d ${build}/client"/>
       <arg line="-classpath ${build}/shared"/>
       <arg line="config.xml"/>
    </exec>
  </target>

  <target name="compile-client" depends="prepare" 
      description="Compiles the client-side source code"  >
      <echo message="Compiling the client source code...."/>
      <javac
         srcdir="."
         destdir="${build}/client"
         classpath="${jwsdp-jars}:build/shared:build/client"
         includes="*Client.java"
      />
  </target>

  <target name="jar-client" 
      description="Builds the JAR file that contains the client">
      <echo message="Building the client JAR  file...."/>
      <delete file="dist/${client-jar}" />
      <jar jarfile="dist/${client-jar}" >
        <fileset dir="${build}/client" />
        <fileset dir="${build}/shared" > 
             <exclude name="**/*Impl*" />
         </fileset>
      </jar>
  </target>

  <target name="build-static" depends="clean-client,generate-stubs,
     compile-client,jar-client"
     description="Executes the targets needed to build a stub client.">
  </target>

  <target name="build-dynamic" depends="clean-client,compile-client,jar-client"
     description="Executes the targets needed to build a dynamic client.">
  </target>

  <target name="build-service" depends="clean,clean-wars,compile-server,
     setup-web-inf,package,process-war"
     description="Executes the targets needed to build the service.">
  </target>

  <target name="run" 
     description="Runs the example client">
     <echo message="Running the ${client-class} program...." />
      <java 
            fork="on" 
            classpath="dist/${client-jar}:${jwsdp-jars}" 
            classname="${client-class}" >
      </java>
  </target>

  <target name="clean" 
     description="Removes the build directory">
    <delete dir="${build}" />
  </target>

  <target name="clean-client" 
     description="Removes the client classes and JAR">
    <delete>
      <fileset dir="${build}/client/${example}" includes="*.class"/>
    </delete>

    <delete file="dist/${client-jar}" />
  </target>

  <target name="clean-wars" 
     description="Deletes the WAR files in the dist directory">
    <delete file="dist/${portable-war}" />
    <delete file="dist/${deployable-war}" />
  </target>

  <target name="debug" depends="set-ws-scripts"
     description="Displays values of some of the properties of this build file">
     <echo message="**Debug**" />
     <echo message="  ${user.home}" />
     <echo message="  ${username}" />
     <echo message="  ${password}" />
     <echo message="  ${url}" />
     <echo message="  ${wsdeploy}" />
     <echo message="  ${context-path}" />
     <echo message="  ${war-path}" />
  </target>

