<?xml version="1.0" encoding="ISO-8859-1"?>
<!--
 ***********************************************************************
 * File:  build.xml
 *
 * Description:
 *
 *   ANT build script for the IzPack Test Application.  References
 *   the 'build.properties' file located in the same directory.
 *
 * Notes:
 *
 *   o  ANT build.xml properties are set to their first definition in
 *      the following sources (properties are immutable, so once they
 *      are set they can't be changed):
 *
 *      (1) Command line properties (e.g. ant -Dcatalina.home=xyz compile)
 *      (2) A referenced build.properties file.
 *      (3) Property assignment statements within build.xml.
 *
 * Author: rdg, 2/14/2007
 ***********************************************************************
 -->

<project
    name="Deploy IzPack Test Project"
    default="build-and-install"
    basedir=".">

    <!-- ============= -->
    <!--  Properties   -->
    <!-- ============= -->

    <property file="build.properties" />

    <property name="javac" location="${jdk.bin}/javac" />
    <property name="javadoc" location="${jdk.bin}/javadoc" />

    <!--
    <condition property="compile.debug" value="true">
        <not><isset/></not>
    </condition>
    -->

    <!-- ======== -->
    <!--  Tasks   -->
    <!-- ======== -->

    <!-- Ant task for the IzPack installer. -->

    <taskdef name="izpack" classpath="${izpack.compiler.jar}"
        classname="com.izforge.izpack.ant.IzPackTask" />

    <!-- =========================== -->
    <!--  Class path for build       -->
    <!-- =========================== -->

    <path id="classpath">
        <!--
        <fileset dir="${app.lib.dir}">
            <include name="*.jar" />
        </fileset>
        -->
        <fileset dir="${app.class.dir}">
            <include name="*.class" />
        </fileset>
        <fileset dir="${jdk.lib}">
            <include name="*.jar" />
        </fileset>
    </path>

    <!-- ==================================== -->
    <!--  Build and install the application   -->
    <!-- ==================================== -->

    <target name="build-and-install" depends="build,install"
        description="Build and install the application.">
        <echo message="Build and install the ${app.name} application"/>
    </target>

    <!-- =========================== -->
    <!--  Build the application      -->
    <!-- =========================== -->

    <target name="build" depends="clean,build-jar,build-izpack"
        description="Build the application.">
        <echo message="Build the ${app.name} application" />
    </target>

    <!-- =========================== -->
    <!--  Clean output directories  -->
    <!-- =========================== -->

    <target name="clean"
        description="Delete build output files.">
        <echo message="Delete build output files."/>

        <delete dir="${app.class.dir}" quiet="true" verbose="false" />
        <mkdir dir="${app.class.dir}" />
        <mkdir dir="${app.class.res.dir}" />
        <delete dir="${app.bin.dir}" quiet="true" verbose="false" />
        <mkdir dir="${app.bin.dir}" />
        <delete dir="${app.dep.dir}" quiet="true" verbose="false" />

    </target>

    <!-- =========================== -->
    <!--  Build application Jar file -->
    <!-- =========================== -->

    <target name="build-jar" depends="compile"
        description="Build the application Jar file.">
        <echo message="Build application Jar file ${app.jar.file}."/>

        <jar destfile="${app.jar.file}"
             basedir="${app.class.dir}"
             manifest="${app.manifest.file}"
             update="false" >
        </jar>

    </target>

    <!-- ========= -->
    <!--  Compile  -->
    <!-- ========= -->

    <target name="compile"
        description="Compile the application.">
        <echo message="Compile java source from ${app.src.dir} to ${app.class.dir}."/>

        <depend srcdir="${app.src.dir}"
            destdir="${app.class.dir}" cache="${app.dep.dir}" />
        <javac
            executable="${javac}"
            failonerror="true"
            verbose="false"
            listfiles="true"
            srcdir="${app.src.dir}"
            destdir="${app.class.dir}"
            debug="${compile.debug}"
            deprecation="${compile.deprecation}"
            optimize="${compile.optimize}" >
            <classpath refid="classpath" />
        </javac>

        <!-- Copy the /src/resources folder as /classes/resources  -->
        <echo message="Copy resource bundle(s) from ${app.res.dir} to ${app.class.res.dir}."/>
        <copy todir="${app.class.res.dir}">
            <fileset dir="${app.res.dir}">
                <include name="MyResources.properties" />
            </fileset>
        </copy>

    </target>

    <!-- ================================== -->
    <!--  Build the IzPack installation kit -->
    <!-- ================================== -->

    <target name="build-izpack"
        description="Build the IzPack installation kit." >
        <echo message="Build IzPack installation kit '${izpack.install.jar}'." />

        <!-- Note: If it's a web app, you may want to change
             installerType to "web" and add the <webdir>
             attribute in the applicable install.xml file. -->

        <izpack
            input="${izpack.install.xml}"
            output="${izpack.install.jar}"
            basedir="${app.build.dir}"
            inheritAll="true" >
        </izpack>

        <echo message="Done building the IzPack kit." />

    </target>

    <!-- ================================= -->
    <!--  Launch the application installer -->
    <!-- ================================= -->

    <target name="install"
        description="Launch the IzPack installer.">
        <echo message="Launch the IzPack installer. "/>
        <java
            jar="${izpack.install.jar}"
            fork="true">
        </java>
    </target>

    <!-- ===================== -->
    <!--  Run the application  -->
    <!-- ===================== -->

    <target name="run"
        description="Run the application.">
        <echo message="Run the application. "/>
        <java
            jar="${app.jar.file}"
            fork="true">
            <arg value="arg1Value" />
            <arg value="arg2Value" />
            <arg value="arg3Value" />
        </java>
    </target>

</project>

