<!-- ===================================================================== -->
<!-- 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 file="../build.properties"/>
  <property file="${user.home}/build.properties"/>
  <property file="../common.properties"/>
  <property name="classpath" value="${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>

  <!-- =================================================================== -->
  <!-- Perform an official release -->
  <!-- =================================================================== -->
  <target name="release" depends="library-dist,documentation-dist,examples-dist,dist">
    <mkdir dir="${release.dir}"/>
    <antcall target="${release.pre}"/>
    <!-- Copy the taglib to the release dir -->
    <copy todir="${release.dir}" >
      <fileset dir="${dist.dir}/${taglib.name}" excludes="doc/**"/>
    </copy>
    <copy file="../LICENSE"   tofile="${release.dir}/LICENSE"/>
    <copy file="../NOTICE"    tofile="${release.dir}/NOTICE"/>
    <copy file="../README"    tofile="${release.dir}/README"/>
    <zip zipfile="${dist.dir}/${release.name}.zip"
       basedir="${dist.dir}" includes="${release.name}/**"/>
    <tar tarfile="${dist.dir}/${release.name}.tar"
       basedir="${dist.dir}" includes="${release.name}/**"/>
    <gzip zipfile="${dist.dir}/${release.name}.tar.gz"
          src="${dist.dir}/${release.name}.tar"/>
    <antcall target="${release.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" unless="checkRequirements.done">
    <antcall target="${checkRequirements.pre}"/>
    <antcall target="checkRequiredFile">
       <param name="file" value="${servlet.jar}"/>
       <param name="fail.message" value="a jar file containing the servlet specification classes is required to compile jakarta taglibs. please set the servlet.jar property servlet.jar path in your build.properties file 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}"/>
    <property name="checkRequirements.done" value="true"/>
  </target>

  <!-- =================================================================== -->
  <!-- Prepare the build and dist directories                              -->
  <!-- =================================================================== -->
  <target name="prepare" depends="checkRequirements" unless="prepare.done">
    <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.doc}/META-INF"/>
    <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.examples}/META-INF"/>
    <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"/>
    <!-- See if we should use template to generate documentation and tld -->
    <available file="xml/${taglib.name}.xml" property="template.present"/>
    <!-- See if there is any documentation web app documents -->
    <available file="${doc.src}/web" property="documentation.present"/>
    <!-- Generate a manifest for the jar and war files -->
    <style in="${xml.src}/${taglib.name}.xml"
           destdir="${build.dir}/${taglib.name}"
           out="${build.dir}/${taglib.name}/${taglib.name}.mf"
           style="${manifest.xsl}">
      <param name="release" expression="${release}"/>
    </style>
    <antcall target="${prepare.post}"/>
    <property name="prepare.done" value="true"/>
  </target>

  <!-- =================================================================== -->
  <!-- Assemble the documentation application                              -->
  <!-- =================================================================== -->
  <target name="documentation" depends="prepare">
    <antcall target="${documentation.pre}"/>
    <antcall target="template-docs"/>
    <copy todir="${build.doc}/WEB-INF">
      <fileset dir="${doc.src}/conf"/>
    </copy>
    <!-- intro.xml isn't part of the documentation application,
         this is just a handy place to build it for the web site. -->
    <style in="${xml.src}/intro.xml"  
           destdir="${build.doc}"   
           out="${build.doc}/intro.html"
           style="${taglibs.xsl}">
      <param name="prefix" expression="../../"/>
    </style>
    <antcall target="copy.documentation"/>
    <uptodate property="javadoc.uptodate"
              targetfile="${build.doc}/javadoc/index.html">
      <srcfiles dir="${library.src}" includes="**/*.java"/>
    </uptodate>
    <antcall target="generate.javadoc"/>
    <antcall target="${documentation.post}"/>
  </target>

  <target name="copy.documentation" if="documentation.present">
    <copy todir="${build.doc}">
      <fileset dir="${doc.src}/web"/>
    </copy>
  </target>

  <target name="generate.javadoc" unless="javadoc.uptodate">
    <javadoc packagenames="org.apache.taglibs.*"
             sourcepath="${library.src}"
             classpath="${classpath}"
             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-2004 The Apache Software Foundation. All Rights Reserved."/>
  </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="${dist.library}/taglibs-${taglib.name}.jar"
          toFile="${build.examples}/WEB-INF/lib/taglibs-${taglib.name}.jar"/>
    <!-- Copy the .jsp files as .txt files -->
    <copy todir="${build.examples}" >
      <fileset dir="${examples.src}/web" includes="**/*.jsp" excludes="index.jsp"/>
      <mapper type="glob" from="*.jsp" to="*.txt"/>
    </copy>
    <!-- now escape the .txt files -->
    <replace dir="${build.examples}">
      <include name="**/*.txt"/>
      <replacetoken><![CDATA[&]]></replacetoken>
      <replacevalue><![CDATA[&amp;]]></replacevalue>
    </replace>
    <replace dir="${build.examples}">
      <include name="**/*.txt"/>
      <replacetoken><![CDATA[<]]></replacetoken>
      <replacevalue><![CDATA[&lt;]]></replacevalue>
    </replace>
    <replace dir="${build.examples}">
      <include name="**/*.txt"/>
      <replacetoken><![CDATA[>]]></replacetoken>
      <replacevalue><![CDATA[&gt;]]></replacevalue>
    </replace>
    <antcall target="examples.html"/>
    <antcall target="${examples.post}"/>
  </target>

  <!-- Generates example html files from the escaped txt files -->
  <target name="examples.html" unless="disable.examples.html">
    <!-- now format the .txt files as an xml file -->
    <replace dir="${build.examples}">
      <include name="**/*.txt"/>
      <replacetoken><![CDATA[&lt;!doctype]]></replacetoken>
      <replacevalue><![CDATA[<?xml version="1.0" ?>

<document>
&lt;!doctype]]></replacevalue>
    </replace>     
    <replace dir="${build.examples}">
      <include name="**/*.txt"/>
      <replacetoken><![CDATA[&lt;/html&gt;]]></replacetoken>
      <replacevalue><![CDATA[&lt;/html&gt;</document>]]></replacevalue>
    </replace>     
    <!-- now style the .txt files as .html files -->
    <style basedir="${build.examples}"
           destdir="${build.examples}"
           includes="**/*.txt"
           style="${taglib-doc.dir}/examples.xsl"/>
    <!-- delete the temporary text files -->
    <delete>                   
      <fileset dir="${build.examples}" includes="**/*.txt"/>
    </delete>
  </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" deprecation="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}"/>
    <antcall target="template-tld"/>
    <javac srcdir="${library.src}" destdir="${build.library}"
           classpath="${classpath}" debug="on" deprecation="on"/>
    <antcall target="${library.post}"/>
  </target>

  <!-- =================================================================== -->
  <!-- Create the documentation WAR file                                   -->
  <!-- =================================================================== -->
  <target name="documentation-dist" depends="documentation">
    <antcall target="${documentation-dist.pre}"/>
    <copy file="../LICENSE"
          toFile="${build.doc}/META-INF/LICENSE"/>
    <copy file="../NOTICE"
          toFile="${build.doc}/META-INF/NOTICE"/>
    <jar jarfile="${dist.doc}" basedir="${build.doc}" excludes="intro.html"
         manifest="${build.dir}/${taglib.name}/${taglib.name}.mf" />
    <mkdir dir="${taglibs.doc}"/>  
    <copy todir="${taglibs.doc}">
      <fileset dir="${build.doc}">
        <exclude name="WEB-INF/**"/>
      </fileset>
    </copy>
    <antcall target="${documentation-dist.post}"/>
  </target>

  <!-- =================================================================== -->
  <!-- Create the examples WAR file                                        -->
  <!-- =================================================================== -->
  <target name="examples-dist" depends="examples">
    <antcall target="${examples-dist.pre}"/>
    <copy file="../LICENSE"
          toFile="${build.examples}/META-INF/LICENSE"/>
    <copy file="../NOTICE"
          toFile="${build.examples}/META-INF/NOTICE"/>
    <jar jarfile="${dist.examples}" basedir="${build.examples}"
         manifest="${build.dir}/${taglib.name}/${taglib.name}.mf" />
    <antcall target="${examples-dist.post}"/>
  </target>

  <!-- =================================================================== -->
  <!-- Create the library JAR file                                         -->
  <!-- =================================================================== -->
  <target name="library-dist" depends="library">
    <antcall target="${library-dist.pre}"/>
    <copy file="${examples.tld}" toFile="${library.tld}"/>
    <copy file="../LICENSE"
          toFile="${build.library}/META-INF/LICENSE"/>
    <copy file="../NOTICE"
          toFile="${build.library}/META-INF/NOTICE"/>
    <jar jarfile="${dist.library}/taglibs-${taglib.name}.jar" basedir="${build.library}"
         manifest="${build.dir}/${taglib.name}/${taglib.name}.mf" />
    <copy file="${examples.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.dir}/${taglib.name}"/>
    <delete dir="${dist.dir}/${taglib.name}"/>
    <delete includeEmptyDirs="true">
      <fileset dir="${dist.dir}" includes="jakarta-taglibs-${taglib.name}*/**"/>
    </delete>
    <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>


  <!-- =================================================================== -->
  <!-- Generate TLD and HTML docs from XML files in ${xml.src}             -->
  <!-- based on the new src/taglib directory templates                     -->
  <!-- =================================================================== -->

  <!-- In the below styles we are transforming individual files,
       the destdir shouldn't be necessary, but ant complains if
       it isn't there.
       -->

  <target name="template-tld" depends="prepare" if="template.present">
    <antcall target="template-tld11"/>
    <antcall target="template-tld12"/>
    <!-- Remove call to gen-tld once taglibs converted to new template -->
    <antcall target="gen-tld"/>
  </target>

  <target name="template-tld11" depends="prepare" unless="gen-docs.present">
    <style in="${xml.src}/${taglib.name}.xml"
           destdir="${build.examples}/WEB-INF"
           out="${build.examples}/WEB-INF/taglibs-${taglib.name}.tld"
           style="${tld11.xsl}"/>
  </target>

  <target name="template-tld12" depends="prepare" if="jsp12.present">
    <style in="${xml.src}/${taglib.name}.xml"
           destdir="${build.examples}/WEB-INF"
           out="${build.examples}/WEB-INF/taglibs-${taglib.name}.tld"
           style="${tld12.xsl}"/>
  </target>

  <target name="template-docs" depends="prepare" if="template.present">
    <style in="${xml.src}/${taglib.name}.xml"
           destdir="${build.doc}"
           out="${build.doc}/index.html"
           style="${taglib-doc.xsl}"/>
    <style in="${xml.src}/${taglib.name}.xml"
           destdir="${build.doc}"
           out="${build.doc}/changes.html"          
           style="${changes-doc.xsl}"/>
    <!-- Remove call to gen-docs once taglibs converted to new template -->
    <antcall target="gen-docs"/>
  </target> 

  <!-- =================================================================== -->
  <!-- Generate TLD and HTML docs from XML files in ${xml.src}             -->
  <!-- using the old taglib-doc-kit, remove this after taglibs             -->
  <!-- have been converted to new src/taglib template.                     -->
  <!-- =================================================================== -->

  <!-- In the below styles we are transforming individual files,
       the destdir shouldn't be necessary, but ant complains if
       it isn't there.
       -->

  <target name="gen-tld" depends="prepare" if="gen-docs.present">
    <style in="${xml.src}/${taglib.name}.xml"   
           destdir="${build.examples}/WEB-INF"
           out="${build.examples}/WEB-INF/taglibs-${taglib.name}.tld"
           style="../taglib-doc-kit/xml/tld.xsl"/>
  </target>

  <target name="gen-docs" depends="prepare" if="gen-docs.present">
    <style in="${xml.src}/${taglib.name}.xml"   
           destdir="${build.doc}"           
           out="${build.doc}/index.html"
           style="../taglib-doc-kit/xml/taglib-doc.xsl"/> 
    <style in="doc/web/changes.xml"
           destdir="${build.doc}" 
           out="${build.doc}/changes.html"
           style="${taglibs.xsl}"/>   
  </target>

  <!-- ********************** Clean and Build Taglib ********************** -->

  <target name="all">
    <antcall target="clean"/>
    <antcall target="dist"/>
  </target>
