<!--  Ant build file for project bookstore -->
<project name="bookstore" default="all" basedir=".">

  <!-- set global properties for this build -->
  <property name="srcDir" value="src"/>
  <property name="buildDir" value="../bookstoreBuild"/>
  <property name="WEBAPP" value="bookstore"/>
  <property name="DEPLOYDIR" value="/home/jd/bea/user_projects/domains/mydomain/applications:"/> 

  <property name="htmlDir" value="html"/>
  <property name="images" value="images"/>
  <property name="css" value="css"/>
  <property name="jspDir" value="jsp"/>
  <property name="javascript" value="js"/>
  <property name="libDir" value="lib"/>
  <property name="xmlDir" value="xml"/>
  <property name="jspcLibDir" value="jspclib"/>
  <property name="tempDir" value="../build-work-bookstore-jsp-syntax-check"/>

  <!-- define our class path for later use -->
  <path id="project.class.path">
    <pathelement path="${buildDir}"/>
    <fileset dir="lib">
      <include name="**/*.jar"/>
    </fileset>
    <!-- Add the weblogic.jar file to class path for the javax.servlet classes -->
    <!-- This file is too big to put in our lib directory. -->
    <fileset dir="/home/jd/bea/weblogic81/server/lib">
      <include name="**/weblogic.jar"/>
    </fileset>
    <fileset dir="${jspcLibDir}"> 
      <include name="**/*.jar"/>
    </fileset>           
    <!-- Include the Oracle JDBC driver included with Weblogic -->
    <fileset dir="/home/jd/bea/weblogic81/server/ext/jdbc/oracle/920"> 
      <include name="**/*.jar"/>
    </fileset>           

    <pathelement path="${buildDir}/WEB-INF/classes"/> 
  </path>

  <target name="all" depends="init, compile, copyJsp, copyLib, copyXml, copyImages, copyStyleSheets,
  copyJavaScript"/>

  <target name="init">
     <echo> running task init</echo>
    <!-- Create the time stamp -->
    <tstamp/>
    <!-- Create the build directory structure used by compile and copy the deployment descriptors to it-->
    <mkdir dir="${buildDir}"/>
    <mkdir dir="${buildDir}/html"/>
    <mkdir dir="${buildDir}/images"/>
    <mkdir dir="${buildDir}/js"/>
    <mkdir dir="${buildDir}/jsp"/>
    <mkdir dir="${buildDir}/jsp/model"/>
    <mkdir dir="${buildDir}/css"/>
    <mkdir dir="${buildDir}/WEB-INF"/>
    <mkdir dir="${buildDir}/WEB-INF/classes"/>
    <mkdir dir="${buildDir}/WEB-INF/lib"/>
    <mkdir dir="${tempDir}"/>
    <mkdir dir="${tempDir}/hold-classes"/>
    <mkdir dir="${tempDir}/dependencies"/>
  </target>

  <target name="clean">
    <echo> running task clean</echo>
    <delete dir="${tempDir}" failonerror="false"/>
    <delete dir="${buildDir}"/>
    <delete file="${DEPLOYDIR}/${WEBAPP}.war"/>
    <delete dir="${DEPLOYDIR}/${WEBAPP}"/>
  </target>

  <target name="compile" depends="init"> 
     <echo> running task compile</echo>
     <javac srcdir="${srcDir}" destdir="${buildDir}/WEB-INF/classes" debug="on"> 
     <classpath refid="project.class.path"/> 
    </javac>
  </target> 

  <target name="copyJsp" depends="compile" >
    <copy todir="${buildDir}/jsp">
      <fileset dir="${jspDir}" />
    </copy>
  </target>

  <target name="syntaxCheckJsp" depends="copyJsp" >
    <jspc srcdir="${jspDir}"
      destdir="${tempDir}"
      package="com.cvc.jsp"
      compiler="jasper"
      uriroot="."
      verbose="9">
      <include name="**/*.jsp" />
      <classpath refid="project.class.path"/> 
    </jspc>
    <javac
      srcdir="${tempDir}"
      destdir="${tempDir}/hold-classes"
      debug="on">
      <classpath refid="project.class.path"/> 
   </javac>
  </target>

	<target name="copyLib" depends="syntaxCheckJsp" >
   <copy todir="${buildDir}/WEB-INF/lib">
      <fileset dir="${libDir}" />
   </copy>
  </target>

  <target name="copyXml" depends="copyLib" >
   <copy todir="${buildDir}/WEB-INF">
      <fileset dir="${xmlDir}" />
   </copy>
  </target>

  <target name="copyHtml" depends="copyXml" >
   <copy todir="${buildDir}/html">
      <fileset dir="${htmlDir}" />
   </copy>
  </target>

  <target name="copyImages" depends="copyHtml" >
   <copy todir="${buildDir}/images">
      <fileset dir="${images}" />
   </copy>
  </target>

  <target name="copyStyleSheets" depends="copyImages" >
   <copy todir="${buildDir}/css">
      <fileset dir="${css}" />
   </copy>
  </target>

  <target name="copyJavaScript" depends="copyStyleSheets" >
   <copy todir="${buildDir}/js">
      <fileset dir="${javascript}" />
   </copy>
  </target>

  <target name="deployExplodedWebApp" depends="copyJavaScript" >
   <copy todir="${DEPLOYDIR}/${WEBAPP}">
      <fileset dir="${buildDir}" />
   </copy>
  </target>

  <target name="createWar" depends="copyJavaScript" >
    <jar jarfile="${DEPLOYDIR}/${WEBAPP}.war"
      basedir="${buildDir}">
    </jar>
 </target>

 <target name="testAuthor" depends="compile">
    <echo>buildDir = ${buildDir}</echo>
    <java classname="junit.textui.TestRunner" fork ="yes" failonerror="true" maxmemory="512m">
      <arg value="com.jdonohue.bookstore.test.AuthorTestCase"/> 
     <classpath refid="project.class.path"/> 
  </java>
</target>

 <target name="testObituary" depends="compile">
    <echo>buildDir = ${buildDir}</echo>
    <java classname="junit.textui.TestRunner" fork ="yes" failonerror="true" maxmemory="512m">
      <arg value="com.jdonohue.bookstore.test.ObituaryTestCase"/> 
     <classpath refid="project.class.path"/> 
  </java>
</target>

 <target name="testPublisher" depends="compile">
    <echo>buildDir = ${buildDir}</echo>
    <java classname="junit.textui.TestRunner" fork ="yes" failonerror="true" maxmemory="512m">
      <arg value="com.jdonohue.bookstore.test.PublisherTestCase"/> 
     <classpath refid="project.class.path"/> 
  </java>
</target>

 <target name="testCategory" depends="compile">
    <echo>buildDir = ${buildDir}</echo>
    <java classname="junit.textui.TestRunner" fork ="yes" failonerror="true" maxmemory="512m">
      <arg value="com.jdonohue.bookstore.test.CategoryTestCase"/> 
     <classpath refid="project.class.path"/> 
  </java>
</target>

 <target name="testTitle" depends="compile">
    <echo>buildDir = ${buildDir}</echo>
    <java classname="junit.textui.TestRunner" fork ="yes" failonerror="true" maxmemory="512m">
      <arg value="com.jdonohue.bookstore.test.TitleTestCase"/> 
     <classpath refid="project.class.path"/> 
  </java>
</target>

 <target name="testSale" depends="compile">
    <echo>buildDir = ${buildDir}</echo>
    <java classname="junit.textui.TestRunner" fork ="yes" failonerror="true" maxmemory="512m">
      <arg value="com.jdonohue.bookstore.test.SaleTestCase"/> 
     <classpath refid="project.class.path"/> 
  </java>
</target>


</project>

