<?xml version="1.0"?>
<project name="[APP_DESC]" default="main">
  <!-- 
    Sample Ant build.xml for building an application and deploying
    the installation package to a website (via scp or ftp).
    Simply replace appropriate values for each [PLACE HOLDER] below.
  -->
  <property name="root_dir" location="[ROOT_DIR]"/>
  <property name="project" location="${root_dir}/[PROJECT_DIR]"/>
  <property name="lib" location="${root_dir}/dev/lib"/>
  <property name="jar_batch" location="${lib}/mk_[APP_NAME].bat"/>
  <property name="obfuscate" location="${root_dir}/dev/obfuscate"/>
  <property name="obfuscate_batch" location="${obfuscate}/obfuscate_[APP_NAME].bat"/>
  <property name="doc" location="${root_dir}/dev/doc"/>
  <property name="doc_batch" location="${doc}/mk_[APP_NAME]_api.bat"/>
  <property name="html" location="${root_dir}/[HTML_DIR]"/>
  <property name="install" location="[INSTALL_DIR]"/>
  <property name="output" location="${root_dir}/product/[APP_NAME]/releases"/>
  <property name="application" value="[APP_DESC]"/>
  <property name="version" value="1.0.0"/>
  <property name="release_zip" value="[APP_NAME]_-${version}.zip"/>
  <property name="server" value="[SERVER]"/>
  <property name="deploy" value="/home/webadmin/${server}/html/download"/>
  
  <target name="main" depends="init, build, jar, obfuscate, test, doc, install, release"/>
  
  <target name="init">
    <buildnumber/>
    <tstamp/>

    <echo>Building ${application} - ${release_zip}.</echo>
    <echo>    Build Date: ${TODAY}.</echo>
    <echo>    Build Number: ${build.number}.</echo>
    <input
      message="Continue with building release?"
      validargs="y,n"
      addproperty="do.continue">
    </input>
    <condition property="do.abort">
      <equals arg1="n" arg2="${do.continue}"/>
    </condition>
    <fail if="do.abort">Build aborted.</fail>
  </target>

  <target name="build" depends="init">
    <!-- Invoke ant on the build.xml file for the NetBeans project. -->
    <ant target="jar" inheritall="false" antfile="${project}/build.xml"/>
  </target>

  <target name="jar" depends="build">
    <!-- Execute the batch script to combine all jar files into a single jar file. -->
    <exec dir="${lib}" executable="${jar_batch}" failonerror="true"/>
  </target>
  
  <target name="obfuscate">
    <!-- Execute the batch script to obfuscate the jar file. -->
    <exec dir="${obfuscate}" executable="${obfuscate_batch}" failonerror="true"/>
  </target>
  
  <target name="test">
    <echo>Testing the obfuscated ${application}...</echo>
  </target>
  
  <target name="doc">
    <!-- Execute the batch script to generate the javadoc. -->
    <!-- Note: the generated HTML will be placed in the ${html}/api directory. -->
    <exec dir="${doc}" executable="${doc_batch}" failonerror="true"/>
  </target>
  
  <target name="install">
    <!-- Copy the obfuscated jar file to the installation directory. -->
    <copy file="${obfuscate}/root_dir_sqlclient.jar" todir="${install}"/>
    
    <!-- Copy the javadoc to the installation directory. -->
    <copy todir="${install}/doc/api">
      <fileset dir="${html}/api"/>
    </copy>
    
    <!-- Copy selected web site contents to the installation directory. -->
    <copy todir="${install}/doc">
      <fileset dir="${html}">
        <exclude name="demo/"/>
        <exclude name="tutorials/"/>
        <exclude name="demo.html"/>
        <exclude name="tutorial.html"/>
      </fileset>
    </copy>
  </target>
  
  <target name="release">
    <!-- Zip up the release package and copy to the ${output} directory. -->
    <zip destfile="${output}/${release_zip}" basedir="${install}"/>
  </target>

  <target name="get_user" unless="user">
    <input message="Please enter user:" addproperty="user"/>
  </target>

  <target name="get_password" unless="password">
    <input message="Please enter password:" addproperty="password"/>
  </target>

  <target name="deploy" depends="init, release, get_user, get_password">
    <!-- Use SSH to deploy the release to the server. -->
    <scp file="${output}/${release_zip}" todir="${user}:${password}@${server}:${deploy}" trust="yes"/>

    <!-- Use FTP to deploy the release to the server (faster but not as secure as SSH). -->
    <!--
    <ftp action="put" server="${server}" binary="true" verbose="true"
         userid="${user}" password="${password}" remotedir="${deploy}">
      <fileset dir="${output}">
        <include name="${release_zip}"/>
      </fileset>
    </ftp>
    -->
  </target>
</project>