<!--
    Example of build file for Ant
    Copyright 2003 DeNova, Inc.
    All rights reserved worldwide.
    
    The following build assumes that you have a JExpress Professional (.jex) project to build your installers. 
    
    Search this file for the word WARNING and adapt each of the values to your system. 
     
    If your installer include custom classes and you use a JExpress subproject to find all the
    custom classes for the installer, then adapt the build-custom.xml file.
-->

<project name="Installer" default="build" basedir=".">

    <description>
        Installer build file
    </description>

    <property environment="env"/>

    <!-- release information -->
    
    <property name="version" value="1.0"/>
    
    <!-- directories -->
    
    <!-- WARNING: Adapt to your local system -->
    <!-- installation directory for JExpress Professional -->
    <property name="jexpress.dir" value="/usr/local/bin/JExpressProfessional"/>
    
    <!-- WARNING: Adapt to your local system -->
    <!-- program name for your Java compiler -->
    <property name="compiler.name" value="jikes"/>
    
    <!-- WARNING: Adapt to your local system -->
    <!-- JExpress project that builds your installer -->
    <property name="installer.project.name" value="Hello.jex"/>
    
    <!-- WARNING: Adapt to your local system -->
    <!-- distribution directory for your app's installer -->
    <!-- IMPORTANT: this directory must match the "build" directory in ${installer.project.name} -->
    <property name="dist.dir" value="${user.dir}/distribution/MyApp"/>
    
    
    <!-- properties related to JExpressProfessional -->    
    <property name="jexpress.installer.dir" value="${jexpress.dir}/JExpressInstaller"/>
    <property name="purejava.installer.dir" value="platforms/PureJava/Standalone"/>
    <property name="jexpress.errors.log" value="errors.log"/>
         
           
    <!-- targets -->

    <!-- builds all custom class files and the installer -->
    <target name="build" 
        depends="init,installer.build"
        description="Build Installer"/>
        
    <!-- cleans class files, compiles, and builds a new installer -->
    <target name="cleanbuild" 
        depends="init,clean,build"
        description="Remove buildable files and then build"/>
        
    <!-- runs an already created installer -->
    <target name="run"

        depends="init"
        description="Run the Pure Java installer">
        
        <exec dir="${dist.dir}/${purejava.installer.dir}" executable="java">

            <arg value="-cp"/>
            <arg path="${dist.dir}/${purejava.installer.dir}/install.jar"/>

            <arg value="load"/>
        </exec>        
    </target>

    
    <!-- the following targets are unlikely to be invoked from the command line -->
    
    <target name="init" 
        description="Initialization">
        
        <tstamp/>
        <buildnumber/>
        
        <property name="build.compiler" value="${compiler.name}"/>

        <!-- make sure JExpress Professional is available -->
        <condition property="jexpress.not.configured">
            <not>
                <available file="${jexpress.dir}"/>
            </not>
        </condition>
        <antcall target="jexpress.required" />
    </target>
    
    <target name="installer.build" 
        depends="init"
        description="Build installer">
        
        <!-- remove the error.log -->
        <delete failonerror="false" quiet="true" file="${jexpress.dir}/error.log"/>
        
        <!-- build the installer -->
        <exec dir="${jexpress.dir}" resultproperty="installer.result" executable="java">

            <arg value="-cp"/>
            <arg path="${jexpress.dir}"/>

            <arg value="com.denova.JExpress.Build.JExpressDeveloper"/>
            <arg value="${src.dir}/${installer.project.name}"/>
            <arg value="-version"/>
            <arg value="${version}"/>
        </exec>
        
        <!-- show the errors log, if it exists -->
        <condition property="installers.errors.log.found">
             <available file="${jexpress.dir}/${jexpress.errors.log}"/>
        </condition>
        <antcall target="show.installer.errors" />
        
        <!-- fail if a serious error was detected during the build -->
        <condition property="installer.error">
            <not>
                <equals arg1="${installer.result}" arg2="0" />
            </not>
        </condition>
        <fail if="installer.error" message="Critical error building installer. See errors.log above."/>        
    </target>
    
    <target name="show.installer.errors"
        if="installers.errors.log.found"
        description="Display the errors log for the installer">
        
        <antcall target="show.results.log"/>        
   </target>
        
    <target name="show.results.log"
        description="Display the results log from a JExpress build">
        
        <exec dir="${jexpress.dir}" executable="cat">

            <arg value="${jexpress.errors.log}"/>
        </exec>
    </target>
        
    <target name="clean" 
        depends="init,installer.clean,dist.clean"
        description="Remove buildable files"/>
        
    <target name="installer.clean" 
        description="Remove installer's class files">
        
        <delete quiet="true">
            <fileset dir="${src.dir}">
                <include name="**/*.class"/>
            </fileset>
        </delete>
    </target>
    
    <target name="dist.clean"
        description="Remove distribution files">
        
        <!-- delete this entire subdirectory tree -->
        <delete quiet="true" dir="${dist.dir}"/>
    </target>
        
    <target name="jexpress.required" 
        if="jexpress.not.configured"
        description="JExpress Professional required">

        <fail message="Change the jexpress.dir property to match your installation directory for JExpress Professional."/>
        
    </target>
    
    <!-- This target is intentionally empty.
         Simply running another target, even empty, cancels the current one. --> 
    <target name="cancel" 
        description="Cancel current Ant process"/>
        
</project>

