<project default="menu">

  <!-- build.xml for FormattedTitles project for H03,
  Univ. of Delaware, CISC370, 07J, P. Conrad, 06/18/2007 -->

  <property name="projectName" value="Formats" />
  <property environment="env"/> <!-- load the environment variables -->

  <!-- Load the properties file for this host. -->
       
  <property file="${env.HOSTNAME}.properties" /> 

  <!-- create a destination for the java doc -->



  <property name="javadocDest" 
            value="${webRoot}/${projectName}/javadoc" />

  <property name="javadocURL" 
            value="${webAddress}/${projectName}/javadoc" />

  <property name="distDest" 
            value="${webRoot}/${projectName}/dist" />

  <property name="sourceDest" 
            value="${webRoot}/${projectName}/source" />

  <property name="indexHtmlDest" 
            value="${webRoot}/${projectName}" />


  <target name="all" depends="compile, test, dist" />

  <target name="menu">
    <echo><![CDATA[

      ======= build.xml menu =======

      ant compile   compile all the code
      ant doc       create all the JavaDoc
      ant test      run the JUnit tests
      ant clean     clean up
      ant dist      publish a tarball, zip, source, doc distribution
      ant all       compile, test, distribute

      ]]>
    </echo>
  </target>


  <target name="compile">
    <mkdir dir="build" />
    <javac srcdir="src" destdir="build" 
	   debug="on" debuglevel="lines,vars,source" />

  </target>

 <target name="clean" >

   <delete quiet="true">
     <fileset dir="build" includes="**/*"/>
     <fileset dir="javadoc" includes="**/*"/>
     <fileset dir="temp" includes="**/*"/>
   </delete>

 </target>

 <target name="doc" depends="compile, htmlDist">

   <delete quiet="true">
     <fileset dir="javadoc" includes="**/*"/>
   </delete>

   <javadoc sourcepath="src"
            destdir="javadoc"
            author="true" version="true" use="true" >

     <fileset dir="." includes="**/*.java"/>

   </javadoc>

   <!-- copy everything you just made to the javadoc destination,
        and then make it readable -->

   <copy todir="${javadocDest}">
     <fileset dir="javadoc"/>
   </copy>

   <!-- Note: this only does the chmod command on the 
        javadoc subdirectory and its contents.  You will have to
	MANUALLY do the chmod on the parent directories.  However,
	you should only need to do that once. -->

   <chmod dir="${javadocDest}" perm="755"  type="dir"
       includes="**" verbose="true"/>

   <chmod dir="${javadocDest}" perm="755"  type="file"
       includes="**/*" verbose="true"/>

   

   <echo>Javadoc deployed to ${javadocURL}</echo>

  </target>


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

  <!-- We use haltonfailure no so that we can get a full report
       of all the tests that failed, not just the first test that fails.
 
       After all tests are done, we check the property SomeJunitTestsFailed
       and if it is set, we fail then
  -->

  <junit fork="yes" haltonfailure="no" failureproperty="SomeJUnitTestsFailed">
  
      <!-- The formatter element gives you a report if there is a failure.

           Take out usefile="false" if you want the report stored
           in a file called TEST-testname.txt 

           If you don't use formatter, you probably want printsummary="yes"
           as an attribute on the junit open tag -->
        
      <formatter type="plain" usefile="false" />
      
      <classpath>
        <pathelement location="build"/>
      </classpath>

      <test name="edu.udel.cisc370.pconrad.Formats.FormattedTitlesTest"/>

  </junit>


  <fail>
     <condition>
         <isset property="SomeJUnitTestsFailed"/>
     </condition>
   </fail>


</target>


<target name="dist" depends="clean,sourceDist,htmlDist,doc">


  <delete quiet="true">
     <fileset dir="temp" includes="**/*" />  
     <fileset dir="${distDest}" includes="**/*" />  
  </delete>

  <mkdir dir="${distDest}" />

  <mkdir dir="temp" />
  <mkdir dir="temp/${projectName}" />

  <copy todir="temp/${projectName}">
    <fileset dir="." 
     excludes="build/**, javadoc/**, **/*~, temp/**" />
  </copy>

  <tar destfile="temp/${projectName}.tar"
       basedir="temp"
       includes="${projectName}/**" 
   />

  <gzip zipfile="${distDest}/${projectName}.tgz" 
        src="temp/${projectName}.tar" />

  <zip destfile="${distDest}/${projectName}.zip"
       basedir="temp"
       includes="${projectName}/**"
  />

  <delete quiet="true">
     <fileset dir="temp" includes="**/*"/>  
  </delete>



   <!-- Note: this only does the chmod command on the 
        indicated subdirectory and its contents.  You will have to
	MANUALLY do the chmod on the parent directories.  However,
	you should only need to do that once. -->

   <chmod dir="${distDest}" perm="755"  type="dir"
       includes="**" verbose="true"/>

   <chmod dir="${distDest}" perm="755"  type="file"
       includes="**/*" verbose="true"/>


</target>


<target name="htmlDist" >


  <copy todir="${indexHtmlDest}" verbose="true">
    <fileset dir="./html" includes="**/*" excludes="**/*~" />
  </copy>


   <!-- Note: this only does the chmod command on the 
        indicated subdirectory and its contents.  You will have to
	MANUALLY do the chmod on the parent directories.  However,
	you should only need to do that once. -->

   <chmod dir="${indexHtmlDest}" perm="755"  type="dir"
       includes="**" verbose="true"/>

   <chmod dir="${indexHtmlDest}" perm="755"  type="file"
       includes="**/*" verbose="true"/>


</target>


<target name="sourceDist" depends="clean">

  <delete quiet="true">
     <fileset dir="${sourceDest}" includes="**/*" />  
  </delete>

  <mkdir dir="${sourceDest}" />

  <copy todir="${sourceDest}">
    <fileset dir="." 
    excludes="build/**, javadoc/**, **/*~, temp/**, html/**" />
  </copy>

   <!-- Note: this only does the chmod command on the 
        indicated subdirectory and its contents.  You will have to
	MANUALLY do the chmod on the parent directories.  However,
	you should only need to do that once. -->

   <chmod dir="${sourceDest}" perm="755"  type="dir"
       includes="**" verbose="true"/>

   <chmod dir="${sourceDest}" perm="755"  type="file"
       includes="**/*" verbose="true"/>



</target>



</project>



