<?xml version="1.0"?>

<project default="compile" name="Sample use of ant for a small Java project">

<description>
  This is a sample use of ant for a small Java project.
</description>

<!-- This was done by Laurie Hendren - note you can use xml comments too. -->

<!-- properties for project directories -->
<property name="srcDir" location="src"/>
<property name="classesDir" location="classes"/>
<property name="docDir" location="doc"/>
<property name="libDir" location="lib"/>
<property name="jarBaseName" value="money"/>

<!-- properties for .jar files - set one of the following -->
<property name="toolsHome" location="/home/user/hendren/303/"/> 
<!-- 
<property name="toolsHome" location="c:\"/>
-->
<property name="junitJar" location="${toolsHome}/junit3.8.1/junit.jar"/>
<property name="jalopyDir" location="${toolsHome}/jalopy"/> 
<property name="yGuardJar" location="${toolsHome}/yguard-1.3.2/lib/yguard.jar"/>

<!-- ========== set up non-standard taskdefs ========== -->

<!-- Jalopy -->
<taskdef name="jalopy"
         classname="de.hunsicker.jalopy.plugin.ant.AntPlugin">
  <classpath>
    <fileset dir="${jalopyDir}/lib">
      <include name="*.jar" />
    </fileset>
  </classpath>
</taskdef>

<!-- yGuard -->
<taskdef name="yGuard"
         classname="com.yworks.yguard.ObfuscatorTask"
         classpath="${yGuardJar}"/>

<!-- =========== Init Target ==================== -->
<target name="init" description="Create necessary directories">
  <tstamp/> <!-- set the timestamps -->
  <mkdir dir="${classesDir}"/>
  <mkdir dir="${docDir}"/>
  <mkdir dir="${libDir}"/>
</target>   

<!--  ========== Compile Target ================= -->
<target name="compile" depends="init" description="Compile .java files">
<javac srcdir="${srcDir}" destdir="${classesDir}">
<classpath>
  <pathelement location="${junitJar}"/>
</classpath>
</javac>
</target>

<!--  ========== Build Target ==================  -->
<target name="build" depends="javadoc,junit" description="Create .jar">
<jar destfile="${libDir}/${jarBaseName}-${DSTAMP}.jar" basedir="${classesDir}">
  <manifest>
    <attribute name="Built-By" value="${user.name}"/>
    <attribute name="Main-Class" value="money.MoneyTest"/>
  </manifest>
</jar>
<jar destfile="${libDir}/${jarBaseName}-src-${DSTAMP}.jar" basedir="${srcDir}"/>
<jar destfile="${libDir}/${jarBaseName}-doc-${DSTAMP}.jar" basedir="${docDir}"/>
</target>

<!-- =========== JUnit Test ==================== -->
<target name="junit" depends="compile" description="Run Junit Tests">
  <junit haltonfailure="no" printsummary="yes" showoutput="yes">
  <classpath>
    <pathelement location="${classesDir}"/>
    <pathelement location="${junitJar}"/>
  </classpath>
  <test name="money.MoneyTest"/>
  <batchtest fork="yes">
    <fileset dir="${srcDir}">
      <include name="**/*Test*.java"/>
      <exclude name="**/AllTests.java"/>
    </fileset>
  </batchtest>
  </junit>
</target>

<!-- ========== Run Target ===================== -->
<target name="run" depends="build" description="Run the application">
<java fork="yes" classname="money.MoneyTest">
  <classpath>
    <pathelement location="${libDir}/${jarBaseName}-${DSTAMP}.jar"/>
    <pathelement location="${junitJar}"/>
  </classpath>
</java>
</target>


<!-- ========== Run Obfuscated Target ============ -->
<target name="runobf" depends="obfuscate" description="Run obfuscated jar">
<java fork="yes" classname="money.MoneyTest">
  <classpath>
    <pathelement location="${libDir}/${jarBaseName}-obf-${DSTAMP}.jar"/>
    <pathelement location="${junitJar}"/>
  </classpath>
</java>
</target>

<!-- ========== Javadoc Target ================== -->
<target name="javadoc" depends="compile" description="Create the javadoc">
<javadoc sourcepath="${srcDir}" 
         destdir="${docDir}"
         packagenames="money"
/>
</target>

<!-- ========== Javadoc Target ================== -->
<target name="javadoc-nocompile" depends="init" 
        description="Create the javadoc for an app that does not yet compile">
<javadoc sourcepath="${srcDir}" 
         destdir="${docDir}"
         packagenames="money"
/>
</target>

<!-- ========== Jalopy Target =================== -->
<target name="format" depends="compile" description="Formats source code">
<jalopy 
   fileformat="unix"
   convention="laurie.xml">
   <fileset dir="${srcDir}">
     <include name="**/*.java" />
   </fileset>
</jalopy>
</target>

<!-- yGuard Obfuscate Target ===================== -->
<target name="obfuscate" depends="build" 
      description="Produces obfuscated class files">
<yGuard
  mainclass="money.MoneyTest"
  logfile="yGuard.log"
  replaceclassnamestrings="true"
  conservemanifest="true"
  >
  <property name="error-checking" value="pedantic"/>
  <inoutpair in="${libDir}/${jarBaseName}-${DSTAMP}.jar" 
             out="${libDir}/${jarBaseName}-obf-${DSTAMP}.jar"/>
  <expose>
     <class name="money.MoneyTest" methods="private" />
  </expose>
</yGuard>
</target>

<!-- =========== Clean Target =================== -->
<target name="clean" description="Remove all .class files">
  <delete dir="${classesDir}"/>
  <delete dir="${libDir}"/>
  <delete dir="${docDir}"/>
  <delete file="yGuard.log"/>
</target>

</project>

