<!--  
Taken from Core Servlets and JavaServer Pages Volume II
from Prentice Hall and Sun Microsystems Press,
http://volume2.coreservlets.com/.
Copyright 2006 Marty Hall, Larry Brown, and Yaakov Chaikin. 
May be freely used or adapted.
 -->
<project name="jstl" default="all">
  <property file="build.properties" />
  <property name="src.root" value="WEB-INF/classes"/>
  <property name="web.lib.dir" value="WEB-INF/lib"/>
  
  <path id="web.classpath">
    <pathelement path="${web.preconfig.classpath}"/>
    <fileset dir="${web.lib.dir}">
      <include name="*.jar"/>
    </fileset>
  </path>
  
  <fileset id="deploy.exclude" dir=".">
    <exclude name="**/*.java"/>
    <exclude name="**/.*"/>
    <exclude name=".*"/>
    <exclude name="build.properties"/>
    <exclude name="build.xml"/>
  </fileset>

  <target name="all"
          depends="clean-src, stage"
          description="Invokes clean-src and stage targets.">
  </target>
  
  <target name="init"
          depends="check-properties"
          description="Initial checks and setup.">
    <mkdir dir="WEB-INF/lib"/>
    <mkdir dir="WEB-INF/classes"/>
  </target>
  
  <target name="check-properties"
          description="Makes sure the minimum needed properties are set.">
    <fail unless="server.autodeploy.dir" message="server.autodeploy.dir property is missing."/>
    <fail unless="web.preconfig.classpath" message="web.preconfig.classpath property is missing."/>
    <echo>Minimum required properties found!</echo>
  </target>
  
  <target name="compile"
          depends="clean-src"
          description="Compiles all java code in the project.">
    <javac srcdir="${src.root}"
           destdir="${src.root}"
           classpathref="web.classpath"
           includes="**/*.java"/>
  </target>
  
  <target name="stage"
          depends="clean-deploy, init, compile"
          description="Deploys Web application to the server in its exploded form.">
    <copy todir="${server.autodeploy.dir}/${ant.project.name}">
      <fileset refid="deploy.exclude" />
    </copy>
  </target>
  
  <target name="deploy"
          depends="clean-stage, init, compile"
          description="Deploys Web application to the server as a WAR file.">
    <jar destfile="${server.autodeploy.dir}/${ant.project.name}.war">
      <fileset refid="deploy.exclude"/>
    </jar>
  </target>
  
  <target name="clean"
          depends="clean-src"
          description="Invokes clean-src target">
  </target>
  
  <target name="clean-src"
          description="Removes generated artifacts from the source code tree.">
    <delete>
      <fileset dir="${src.root}">
        <include name="**/*.class"/>
      </fileset>
    </delete>
  </target>
  
  <target name="clean-stage"
          description="Removes staged deployment from the server.">
    <delete dir="${server.autodeploy.dir}/${ant.project.name}"/>
  </target>
  
  <target name="clean-deploy"
          description="Removes deployed WAR file from the server.">
    <delete file="${server.autodeploy.dir}/${ant.project.name}.war"/>
  </target>
  
  <target name="clean-all"
          depends="clean-src, clean-stage, clean-deploy"
          description="Invokes clean-src, clean-stage, clean-deploy">
  </target>
</project>