<!-- ===================================================================== -->
<!-- standard Ant targets for custom tag libraries                         -->
<!-- note: this is not a proper xml file (there is no root element)        -->
<!--       it is intended to be imported from the taglib build.xml         -->
<!-- ===================================================================== -->

  <!-- =================================================================== -->
  <!-- Properties setup                                                    -->
  <!-- =================================================================== -->
  <property environment="env"/>
  <property file="../common.properties"/>
  <property name="classpath" value="${env.SERVLET_JAR}" />

  <!-- =================================================================== -->
  <!-- Compile the library as well as the associated applications          -->
  <!-- =================================================================== -->
  <target name="main" depends="library,documentation,examples">
    <antcall target="${main.pre}"/>
    <antcall target="${main.post}"/>
  </target>

  <!-- =================================================================== -->
  <!-- Create the entire set of distribution files -->
  <!-- =================================================================== -->
  <target name="dist" depends="library-dist,documentation-dist,examples-dist">
    <antcall target="${dist.pre}"/>
    <antcall target="${dist.post}"/>
  </target>
  
  <!-- =================================================================== -->
  <!-- Default pre & post actions                                          -->
  <!-- =================================================================== -->
  <target name="default.pre"/>
  <target name="default.post"/>
  
  <!-- =================================================================== -->
  <!-- Check required components (xerces and xalan)                        -->
  <!-- =================================================================== -->
  <target name="checkRequirements">
    <antcall target="${checkRequirements.pre}"/>
    <antcall target="checkRequiredFile">
       <param name="file" value="${env.SERVLET_JAR}"/>
       <param name="fail.message" value="a jar file containing the servlet specification classes is required to compile jakarta taglibs. please define the environment variable SERVLET_JAR and ensure that the file exists"/>
    </antcall>
    <antcall target="checkRequiredClass">
       <param name="class" value="org.apache.xerces.framework.XMLParser"/>
       <param name="fail.message" value="xerces is required for the &lt;style&gt; task in the &quot;documentation&quot; target. please install xerces.jar in ANT_HOME/lib"/>
    </antcall>
    <antcall target="checkRequiredClass">
       <param name="class" value="org.apache.xalan.xslt.Stylesheet"/>
       <param name="fail.message" value="xalan is required for the &lt;style&gt; task in the &quot;documentation&quot; target. please install xalan.jar in ANT_HOME/lib"/>
    </antcall>
    <antcall target="${checkRequirements.post}"/>
  </target>

  <!-- =================================================================== -->
  <!-- Prepare the build and dist directories                              -->
  <!-- =================================================================== -->
  <target name="prepare" depends="checkRequirements">
    <antcall target="${prepare.pre}"/>
    <!-- Set up build directories -->
    <mkdir dir="${build.dir}"/>
    <mkdir dir="${build.doc}"/>
    <mkdir dir="${build.doc}/javadoc"/>
    <mkdir dir="${build.doc}/WEB-INF"/>
    <mkdir dir="${build.doc}/WEB-INF/classes"/>
    <mkdir dir="${build.doc}/WEB-INF/lib"/>
    <mkdir dir="${build.examples}"/>
    <mkdir dir="${build.examples}/WEB-INF"/>
    <mkdir dir="${build.examples}/WEB-INF/classes"/>
    <mkdir dir="${build.examples}/WEB-INF/lib"/>
    <mkdir dir="${build.library}"/>
    <mkdir dir="${build.library}/META-INF"/>
    <!-- Set up distribution directory -->
    <mkdir dir="${dist.dir}"/>
    <mkdir dir="${dist.library}"/>
    <!-- See if the examples dir has any source to compile -->
    <available file="${examples.src}/src" property="examples.src.present"/>

    <antcall target="${prepare.post}"/>
  </target>

  <!-- =================================================================== -->
  <!-- Assemble the documentation application                              -->
  <!-- =================================================================== -->
  <target name="documentation" depends="prepare">
    <antcall target="${documentation.pre}"/>
    <copy todir="${build.doc}/WEB-INF">
      <fileset dir="${doc.src}/conf"/>
    </copy>
    <style basedir="${doc.src}/web" destdir="${build.doc}"
           extension=".html" style="${taglibs.xsl}" includes="*.xml"/>
    <copy todir="${build.doc}">
      <fileset dir="${doc.src}/web" includes="**/*.html"/>
    </copy>
    <javadoc packagenames="org.apache.taglibs.*"
	     classpath="${classpath}"
             sourcepath="src"
             destdir="${build.doc}/javadoc"
             author="true"   
             version="true"
	     use="true"
             windowtitle="Jakarta '${taglib.name}' custom tag library API"
             doctitle="Jakarta '${taglib.name}' custom tag library"
             bottom="Copyright &#169; 2000 Apache Software Foundation. All Rights Reserved."
    />
    <antcall target="${documentation.post}"/>
  </target>

  <!-- =================================================================== -->
  <!-- Assemble the examples application                                   -->
  <!-- =================================================================== -->
  <target name="examples" depends="compile-examples,library-dist">
    <antcall target="${examples.pre}"/>
    <copy toDir="${build.examples}/WEB-INF">
      <fileset dir="${examples.src}/conf"/>
    </copy>
    <copy toDir="${build.examples}">
      <fileset dir="${examples.src}/web"/>
    </copy>
    <copy file="${source.tld}" toFile="${examples.tld}"/>
    <copy file="${dist.library}/${taglib.name}.jar"
          toFile="${build.examples}/WEB-INF/lib/${taglib.name}.jar"/>
    <copy todir="${build.examples}" >
      <fileset dir="${examples.src}/web" includes="*.jsp"/>
      <mapper type="glob" from="*.jsp" to="*.txt"/>
    </copy>
    <antcall target="${examples.post}"/>
  </target>
  
  <!-- =================================================================== -->
  <!-- Compile the examples application                                    -->
  <!-- =================================================================== -->
  <target name="compile-examples" depends="prepare" if="examples.src.present">
    <antcall target="${compile-examples.pre}"/>
    <javac srcdir="${examples.src}/src"
           destdir="${build.examples}/WEB-INF/classes"
           classpath="${classpath}" debug="on"/>
    <copy todir="${build.examples}/WEB-INF/classes">
      <fileset dir="${examples.src}/src">
        <include name="**/*.properties"/>
      </fileset>
    </copy>
    <antcall target="${compile-examples.post}"/>
  </target>

  <!-- =================================================================== -->
  <!-- Compile the tag library itself                                      -->
  <!-- =================================================================== -->
  <target name="library" depends="prepare">
    <antcall target="${library.pre}"/>
    <copy file="${source.tld}" toFile="${library.tld}"/>
    <javac srcdir="${library.src}" destdir="${build.library}"
           classpath="${classpath}" debug="on"/>
    <antcall target="${library.post}"/>
  </target>

  <!-- =================================================================== -->
  <!-- Create the documentation WAR file                                   -->
  <!-- =================================================================== -->
  <target name="documentation-dist" depends="documentation">
    <antcall target="${documentation-dist.pre}"/>
    <jar jarfile="${dist.doc}" basedir="${build.doc}"/>
    <antcall target="${documentation-dist.pre}"/>
  </target>

  <!-- =================================================================== -->
  <!-- Create the examples WAR file                                        -->
  <!-- =================================================================== -->
  <target name="examples-dist" depends="examples">
    <antcall target="${examples-dist.pre}"/>
    <jar jarfile="${dist.examples}" basedir="${build.examples}"/>
    <antcall target="${examples-dist.post}"/>
  </target>

  <!-- =================================================================== -->
  <!-- Create the library JAR file                                         -->
  <!-- =================================================================== -->
  <target name="library-dist" depends="library">
    <antcall target="${library-dist.pre}"/>
    <jar jarfile="${dist.library}/${taglib.name}.jar"
         basedir="${build.library}"/>
    <copy file="${source.tld}" toFile="${dist.tld}"/>
    <antcall target="${library-dist.post}"/>
  </target>

  <!-- =================================================================== -->
  <!-- Delete output directories and files so we can build from scratch    -->
  <!-- =================================================================== -->
  <target name="clean">
    <antcall target="${clean.pre}"/>
    <delete dir="${build.doc}"/>
    <delete dir="${build.examples}"/>
    <delete dir="${build.library}"/>
    <delete dir="${dist.dir}/${taglib.name}"/>
    <antcall target="${clean.post}"/>
  </target>

  <!-- =================================================================== -->
  <!-- Scripts used with antcall for checking for required classes or jars -->
  <!-- Must provide "class" or "file" and "fail.message" parameters        -->
  <!-- =================================================================== -->
  <target name="checkRequiredClass">
    <available classname="${class}" property="requirement.satisfied"/>
    <antcall target="checkRequired.fail"/>
  </target>
  <target name="checkRequiredFile">
    <available file="${file}" property="requirement.satisfied"/>
    <antcall target="checkRequired.fail"/>
  </target>
  <target name="checkRequired.fail" unless="requirement.satisfied">
    <fail message="${fail.message}"/>
  </target>
