<?xml version="1.0"?>
<project name="gettingstarted" default="default">
  <description>Compiles and runs example code</description>

  <!-- ===================================================================== -->
  <!-- Property declarations                                                 -->
  <!-- ===================================================================== -->

  <property name="proj.name"         value="${ant.project.name}"/>
  <property name="proj.version"      value="1.0"/>
  <property name="pkg.name"          value="example.${proj.name}"/>
  <property name="main.class"        value="${pkg.name}.Main"/>
  <property name="build.dir"         location="build"/>
  <property name="build.classes.dir" location="${build.dir}/classes"/>
  <property name="dist.dir"          location="dist"/>
  <property name="src.dir"           location="src"/>
  <property name="jar.filename"      value="${proj.name}-${proj.version}.jar"/>
  <property name="jar.file"          location="${dist.dir}/${jar.filename}"/>
  <property name="manifest.filename" value="${proj.name}.mf"/>
  <property name="manifest.file"     location="${build.dir}/${manifest.filename}"/>

  <!-- ===================================================================== -->
  <!-- Datatype declarations                                                 -->
  <!-- ===================================================================== -->

  <path id="compile.classpath">
    <pathelement location="${build.classes.dir}"/>
  </path>

  <path id="execute.classpath">
    <pathelement location="${build.classes.dir}"/>
  </path>

  <!-- ===================================================================== -->
  <!-- Top level targets                                                     -->
  <!-- ===================================================================== -->

  <target name="default"
          depends="execute"/>

  <target name="all"
          depends="execute, archive"/>

  <target name="compile"
          depends="init"
          description="Compiles the source code">
    <javac srcdir="${src.dir}"
           destdir="${build.classes.dir}"
           classpathref="compile.classpath"
           deprecation="true"
           debug="${build.debug}"
           debuglevel="${build.debuglevel}"/>
  </target>
  
  <target name="archive"
          depends="compile, manifest"
          description="Creates the JAR file">
    <jar destfile="${jar.file}"
         basedir="${build.classes.dir}"
         manifest="${manifest.file}"/>
  </target>
  
  <target name="clean"
          depends="init"
          description="Removes temporary directory contents">
    <delete dir="build"/>
    <delete dir="${dist.dir}"/>
  </target>

  <target name="execute"
          depends="compile"
          description="Runs the program">
    <property name="std.jvm.args"
              value="-Xfuture"/>
    <property name="mrj.jvm.args"
              value="-Xdock:name=${ant.project.name}"/>
    <property name="jvm.args"
              value="${std.jvm.args} ${mrj.jvm.args}"/>
    <java classname="${main.class}"
          classpathref="execute.classpath"
          fork="true">
        <jvmarg line="${jvm.args}"/>
        <arg value="a"/>
        <arg value="b"/>
        <arg file="."/>
    </java> 
  </target> 

  <!-- ===================================================================== -->
  <!-- Internal targets                                                      -->
  <!-- ===================================================================== -->

  <target name="init">
    <echo message="Building ${proj.name}  (version: ${proj.version})."/>
    <tstamp>
      <format property="timestamp.iso8601"
              pattern="yyyy-MM-dd'T'HH:mm:ss"/>
    </tstamp>
    <mkdir dir="${build.classes.dir}"/>
    <mkdir dir="${dist.dir}"/>
  </target>

  <target name="manifest"
          depends="init">
    <manifest file="${manifest.file}">
      <attribute name="Built-By"   value="${user.name}"/>
      <attribute name="Built-On"   value="${timestamp.iso8601}"/>
      <attribute name="Main-Class" value="${main.class}"/>
    </manifest>
  </target>

  <target name="debug">
    <echoproperties/>
  </target>

  <target name="help"
          depends="usage"/>

  <target name="usage">
    <echo message="  Execute 'ant -projecthelp' for build file help."/>
    <echo message="  Execute 'ant -help' for ANT help."/>
  </target>
</project>
<!--
                                                           <ant>
                                                            \_/
                                                           \(_)/
                                                           -(_)-
                                                           /(_)\
-->
