<?xml version="1.0"?>

<!-- 
/*
** Module   : build.xml
** Abstract : ant build script for the harness project
**
** Copyright (c) 2004-2022, Golden Code Development Corporation.
**
** _#_ _I_ __Date__ _________________________________Description_________________________________
** 001 GES 20090108 First version based on prior works:
**                  - build and distribution dirs
**                  - clean task including all generated files
**                  - compile
**                  - jar
**                  - javadoc
** 002 ECF 20150920 Update for Java 8.
** 003 TJD 20220408 Update for Java 11.
*/
 -->
 
<!--
    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU Affero General Public License as
    published by the Free Software Foundation, either version 3 of the
    License, or (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU Affero General Public License for more details.

    You should have received a copy of the GNU Affero General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
 -->
 
<!--
    A "project" describes a set of targets that may be requested
    when Ant is executed.  The "default" attribute defines the
    target which is executed if no specific target is requested,
    and the "basedir" attribute defines the current working directory
    from which Ant executes the requested task.  This is normally
    set to the current working directory.
 -->

<project name="Harness Project" default="compile" basedir=".">


<!-- ===================== Property Definitions ========================= -->


<!--

  Each of the following properties are used in the build script.
  Values for these properties are set by the first place they are
  defined, from the following list:

  * Definitions on the "ant" command line (ant -Dfoo=bar compile).

  * Definitions from a "build.properties" file in the top level
    source directory of this application.

  * Definitions from a "build.properties" file in the developer's
    home directory.

  * Default definitions in this build.xml file.

  You will note below that property values can be composed based on the
  contents of previously defined properties.  This is a powerful technique
  that helps you minimize the number of changes required when your development
  environment is modified.  Note that property composition is allowed within
  "build.properties" files as well as in the "build.xml" script.

-->

  <property file="build.properties"/>
  <property file="${user.home}/build.properties"/>


<!-- ==================== File and Directory Names ====================== -->


<!--

  These properties generally define file and directory names (or paths) that
  affect where the build process stores its outputs.

-->

  <property name="build.home"    value="${basedir}/build"/>
  <property name="dist.home"     value="${basedir}/dist"/>
  <property name="src.home"      value="${basedir}/src"/>
  <property name="lib.home"      value="${basedir}/lib"/>
  <property name="src.gcd.home"  value="${basedir}/src/com/goldencode"/>
  <property name="manifest.dir"  value="${basedir}/manifest"/>

<!--  ==================== Compilation Control Options ================== -->

<!--

  These properties control option settings on the Javac compiler when it
  is invoked using the <javac> task.

  compile.debug        Should compilation include the debug option?

  compile.deprecation  Should compilation include the deprecation option?

  compile.optimize     Should compilation include the optimize option?

-->

  <property name="compile.debug"       value="true"/>
  <property name="compile.deprecation" value="true"/>
  <property name="compile.optimize"    value="true"/>


<!-- ==================== Compilation Classpath ========================= -->

<!--

  Rather than relying on the CLASSPATH environment variable, Ant includes
  features that makes it easy to dynamically construct the classpath you
  need for each compilation.  The example below constructs the compile
  classpath to include the servlet.jar file, as well as the other components
  that Tomcat makes available to web applications automatically, plus anything
  that you explicitly added.

-->

  <!-- Path used when compiling Java classes -->

  <path id="compile.classpath">

    <fileset dir="${lib.home}">
      <include name="*.jar"/>
    </fileset>

  </path>

<!-- ==================== All Target ==================================== -->

<!--

  The "all" target is a shortcut for running the "clean" target followed
  by the "compile" target, to force a complete recompile.

-->

  <target name="all" depends="clean,compile,jar,javadoc"
          description="Clean build directory, then compile"/>



<!-- ==================== Clean Target ================================== -->

<!--

  The "clean" target deletes any previous "build" directory,
  so that you can be ensured the application can be built from scratch.

-->

  <target
     name="clean"
     description="Delete old build directory">

     <delete
        failonerror="false"
        includeEmptyDirs="true">

        <fileset dir="${build.home}"/>
        <fileset dir="${dist.home}"/>

     </delete>
     
  </target>



<!-- ==================== Prepare Target ================================ -->

<!--

  The "prepare" target is used to create the "build" destination directory,
  and copy the static contents of your web application to it.  If you need
  to copy static files from external dependencies, you can customize the
  contents of this task.

  Normally, this task is executed indirectly when needed.

-->

  <target name="prepare">

    <!-- Create build directories as needed -->
    <mkdir dir="${build.home}" />
    <mkdir dir="${build.home}/lib" />
    <mkdir dir="${build.home}/classes" />
    <mkdir dir="${build.home}/classes/META-INF/services" />
    
    <!-- Create distribution directory as needed -->
    <mkdir dir="${dist.home}" />
    <mkdir dir="${dist.home}/docs/api" />

    <!-- Copy external jars -->
    <copy todir="${build.home}/lib">
      <fileset dir="${lib.home}" />
    </copy>

  </target>


<!-- ==================== Compile Target ================================ -->

<!--

  The "compile" target transforms source files (from your "src" directory)
  into object files in the appropriate location in the build directory.

-->

  <target name="compile"
          depends="prepare"
          description="Compile Java sources">

    <!-- Compile Java classes as necessary -->

    <javac srcdir="${src.home}"
           destdir="${build.home}/classes"
           memoryMaximumSize="256M"
           fork="true"
           debug="${compile.debug}"
           deprecation="${compile.deprecation}"
           optimize="${compile.optimize}">

        <classpath refid="compile.classpath"/>

    </javac>
    <copy todir="${build.home}/classes">
       <fileset dir="${src.home}" includes="**/*.properties"/>
    </copy>

  </target>

<!-- ==================== Jar Target ============================ -->  

  <target name="jar" depends="compile">

     <condition property="manifest.name" value="${manifest.dir}/harness_1.8.mf">
        <matches string="${java.version}" pattern="^1\.8"/>
     </condition>
     <condition property="manifest.name" value="${manifest.dir}/harness_1.8.mf">
        <matches string="${java.version}" pattern="^9\."/>
     </condition>
     <condition property="manifest.name" value="${manifest.dir}/harness_1.8.mf">
        <matches string="${java.version}" pattern="^1.\."/>
     </condition>
     <condition property="manifest.name" value="${manifest.dir}/harness_1.7.mf">
        <matches string="${java.version}" pattern="^1\.7"/>
     </condition>
     <condition property="manifest.name" value="${manifest.dir}/harness.mf">
        <not>
           <isset property="manifest.name"/>
        </not>
     </condition>
     <jar jarfile="${build.home}/lib/harness.jar"
          basedir="${build.home}/classes"
          includes="com/goldencode/**,**/*.properties"
          manifest="${manifest.name}"
     />

  </target>

<!-- ==================== Javadoc Target ========================== -->

<!--

  The "javadoc" target creates Javadoc API documentation for the Java
  classes included in your application.  Normally, this is only required
  when preparing a distribution release, but is available as a separate
  target in case the developer wants to create Javadocs independently.

-->

  <target name="javadoc"
          depends="compile"
          description="Create Javadoc API documentation">

    <javadoc sourcepath="${src.home}"
             destdir="${dist.home}/docs/api"
             maxmemory="256M"
             access="private"
             Footer="Copyright (c) 2008-2009, Golden Code Development
                     Corporation.&lt;br&gt;
                     ALL RIGHTS RESERVED. Use is subject to license terms."
             Windowtitle="Automated Terminal Testing Harness"
             locale="en_US"
             packagenames="*">

      <classpath refid="compile.classpath"/>

    </javadoc>

  </target>
    
</project>
