<project name="standard" default="build" basedir=".">

  <!-- =================================================================== -->
  <!-- Version Number                                                      -->
  <!-- =================================================================== -->

  <property name="standard-version" value="1.1.0" />
  <property name="release.name" value="jakarta-taglibs-standard-${standard-version}" />
  <property name="release.pre" value="nop" />
  <property name="release.post" value="nop" />

  <!-- =================================================================== -->
  <!-- Inherited properties                                                -->
  <!-- =================================================================== -->

  <property file="build.properties"/>			<!-- Component local -->
  <property file="../build.properties"/>		<!-- Commons local   -->
  <property file="${user.home}/build.properties"/>	<!-- User local      -->
  <property file="../common.properties"/>

  <!-- =================================================================== -->
  <!-- taglib specific properties                                                -->
  <!-- =================================================================== -->
    
  <property name="taglib.name"    value="standard"/>

  <!--
        These property values are derived from the previously defined values,
	and should not normally be overridden from the command line.

        build.library               Target directory for tag library
        build.examples		    Target directory for examples app
        build.doc                   Target directory for documentation app
	dist.library                Destination JAR for tag library
	dist.examples		    Destination WAR for examples app
	dist.doc                    Destination WAR for documentation app
	dist.tld                    Destination TLD file for tag library
  -->

  <!-- =================================================================== -->
  <!-- Destination Preparation                                             -->
  <!-- =================================================================== -->

  <target name="prepare-dependencies">

    <!-- info on build environment -->

    <echo>---------- Environment Information ----------</echo>
    <echo>java.home: ${java.home}</echo>
    <echo>ant.java.version: ${ant.java.version}</echo>
    <echo>debug: ${compile.debug}</echo>
    <echo>deprecation: ${compile.deprecation}</echo>
    <echo>optimize: ${optimize.debug}</echo>
    <echo>---------- Dependencies ---------------------</echo>
    <echo>servlet24.jar: ${servlet24.jar}</echo>
    <echo>jsp20.jar: ${jsp20.jar}</echo>
    <echo>jdbc2_0-stdext.jar: ${jdbc2_0-stdext.jar}</echo>
    <echo>jaxp-api.jar: ${jaxp-api.jar}</echo>
    <echo>dom.jar: ${dom.jar}</echo>
    <echo>sax.jar: ${sax.jar}</echo>
    <echo>xalan.jar: ${xalan.jar}</echo>
    <echo>xercesImpl.jar: ${xercesImpl.jar}</echo>
    <echo>---------- Build directories ----------------</echo>
    <echo>build.dir: ${build.dir}</echo>
    <echo>build.library: ${build.library}</echo>
    <echo>build.examples: ${build.examples}</echo>
    <echo>build.doc: ${build.doc}</echo>
    <echo>---------- Distribution directories ---------</echo>
    <echo>dist.dir: ${dist.dir}</echo>
    <echo>dist.library: ${dist.library}</echo>
    <echo>dist.examples: ${dist.examples}</echo>
    <echo>dist.doc: ${dist.doc}</echo>
    <!-- <echo>dist.tld: ${dist.tld}</echo> -->
    <echo>---------------------------------------------</echo>
    
    <!-- Check the build/runtime dependencies -->

    <antcall target="requiredJar">
       <param name="prop" value="servlet24.jar"/>
       <param name="file" value="${servlet24.jar}"/>
       <param name="desc" value="Servlet 2.4 API classes"/>
    </antcall>

    <antcall target="requiredJar">
       <param name="prop" value="jsp20.jar"/>
       <param name="file" value="${jsp20.jar}"/>
       <param name="desc" value="JSP 2.0 API classes"/>
    </antcall>

    <antcall target="processIfPropSet">
       <param name="prop" value="jdbc2_0-stdext.jar"/>
       <param name="task" value="requiredJarIfPropSet"/>
       <param name="file" value="${jdbc2_0-stdext.jar}"/>
       <param name="desc" value="Sun JDBC 2.0 API classes"/>
    </antcall>

    <antcall target="processIfPropSet">
       <param name="prop" value="jaxp-api.jar"/>
       <param name="task" value="requiredJarIfPropSet"/>
       <param name="file" value="${jaxp-api.jar}"/>
       <param name="desc" value="JAXP 1.2 API classes"/>
    </antcall>

    <antcall target="processIfPropSet">
       <param name="prop" value="dom.jar"/>
       <param name="task" value="requiredJarIfPropSet"/>
       <param name="file" value="${dom.jar}"/>
       <param name="desc" value="JAXP 1.2 DOM API classes"/>
    </antcall>

    <antcall target="processIfPropSet">
       <param name="prop" value="sax.jar"/>
       <param name="task" value="requiredJarIfPropSet"/>
       <param name="file" value="${sax.jar}"/>
       <param name="desc" value="JAXP 1.2 SAX API classes"/>
    </antcall>

    <antcall target="processIfPropSet">
       <param name="prop" value="xalan.jar"/>
       <param name="task" value="requiredJarIfPropSet"/>
       <param name="file" value="${xalan.jar}"/>
       <param name="desc" value="Xalan implementation"/>
    </antcall>

    <antcall target="processIfPropSet">
       <param name="prop" value="xercesImpl.jar"/>
       <param name="task" value="requiredJarIfPropSet"/>
       <param name="file" value="${xercesImpl.jar}"/>
       <param name="desc" value="Xerces implementation"/>
    </antcall>
    
  </target>

  <!-- Set up build directories -->
  <target name="prepare-build" depends="prepare-dependencies">
    <mkdir dir="${build.dir}"/>
    <mkdir dir="${build.library}"/>
    <mkdir dir="${build.library}/META-INF"/>
    <mkdir dir="${build.library}/classes"/>
    <mkdir dir="${build.library}/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.doc}"/>
    <mkdir dir="${build.doc}/WEB-INF"/>
  </target>

  <!-- Set up distribution directory -->
  <target name="prepare-dist" depends="prepare-build">
    <mkdir dir="${dist.dir}"/>
    <mkdir dir="${dist.library}"/>
    <mkdir dir="${dist.library}/lib"/>
    <mkdir dir="${dist.library}/tld"/>
    <mkdir dir="${dist.library}/javadoc"/>
  </target>

  <!-- =================================================================== -->
  <!-- Build Tag Library Components                                      -->
  <!-- =================================================================== -->

  <target name="build" depends="library-build, examples-build, documentation-build"/>

  <!-- Build the tag library itself -->
  <target name="library-build" depends="prepare-build">  
    
    <!-- Compile the taglib.
         Need to override xalan classes if using J2SE 1.4, that's why we
         use bootclasspath. Works with J2SE 1.3 as well. -->
<!-- DELETE don't need to specify bootclaspath on a mac
      bootclasspath="${xalan.jar}:${java.home}/lib/rt.jar"
-->
    <javac 
      srcdir="${library.src}" 
      destdir="${build.library}/classes"
      classpath="${servlet24.jar}:${jsp20.jar}:${jdbc2_0-stdext.jar}:${jaxp-api.jar}:${dom.jar}:${sax.jar}"
      excludes="org/apache/taglibs/standard/lang/jstl/parser/jsp20/* org/apache/taglibs/standard/lang/jpath/** org/apache/taglibs/standard/lang/spel/**"
      debug="${compile.debug}"
      deprecation="${compile.deprecation}"
      optimize="${compile.optimize}"/> 
      
    <!-- copy the TLDs in META-INF -->
    <copy todir="${build.library}/META-INF">
      <fileset dir="conf" includes="*.tld"/>
    </copy>    

    <!-- Copy the resource properties files -->
    <copy todir="${build.library}/classes">
      <fileset dir="${library.src}">
	<include name="**/*.properties"/>
      </fileset>
    </copy>
    
    <!-- Create the JSTL API jar -->
    <jar jarfile="${build.library}/lib/jstl.jar"
         basedir="${build.library}/classes"
         includes="javax/**">
      <manifest>
        <attribute name="Specification-Title" value="JavaServer Pages Standard Tag Library (JSTL)"/>
        <attribute name="Specification-Version" value="1.1"/>
        <attribute name="Implementation-Title" value="JavaServer Pages Standard Tag Library API Reference Implementation"/>
        <attribute name="Implementation-Version" value="${standard-version}"/>
        <attribute name="Implementation-Vendor" value="Sun Microsystems, Inc."/>
        <attribute name="Implementation-Vendor-Id" value="com.sun"/>
        <attribute name="Extension-Name" value="javax.servlet.jsp.jstl"/>
      </manifest>         
    </jar>        
    
    <!-- Create the implementation jar -->
    <jar jarfile="${build.library}/lib/standard.jar">
      <fileset dir="${build.library}/classes">
        <include name="org/**"/>
      </fileset>
      <fileset dir="${build.library}">
        <include name="META-INF/*.tld"/>
      </fileset>
      <manifest>
        <attribute name="Specification-Title" value="JavaServer Pages Standard Tag Library (JSTL)"/>
        <attribute name="Specification-Version" value="1.1"/>
        <attribute name="Implementation-Title" value="jakarta-taglibs 'standard': an implementation of JSTL"/>
        <attribute name="Implementation-Version" value="${standard-version}"/>
        <attribute name="Implementation-Vendor" value="Apache Software Foundation"/>
        <attribute name="Implementation-Vendor-Id" value="org.apache"/>
        <attribute name="Extension-Name" value="org.apache.taglibs.standard"/>
      </manifest>         
    </jar>        
    
    <!-- All jar files required at runtime are copied in the 'lib' dir -->
     
    <antcall target="processIfPropSet">
      <param name="prop" value="jdbc2_0-stdext.jar"/>
      <param name="task" value="copyIfPropSet"/>
      <param name="file" value="${jdbc2_0-stdext.jar}"/>
      <param name="todir" value="${build.library}/lib/old-dependencies"/>
    </antcall>

    <antcall target="processIfPropSet">
      <param name="prop" value="jaxp-api.jar"/>
      <param name="task" value="copyIfPropSet"/>
      <param name="file" value="${jaxp-api.jar}"/>
      <param name="todir" value="${build.library}/lib/old-dependencies"/>
    </antcall>

    <antcall target="processIfPropSet">
      <param name="prop" value="dom.jar"/>
      <param name="task" value="copyIfPropSet"/>
      <param name="file" value="${dom.jar}"/>
      <param name="todir" value="${build.library}/lib/old-dependencies"/>
    </antcall>

    <antcall target="processIfPropSet">
      <param name="prop" value="sax.jar"/>
      <param name="task" value="copyIfPropSet"/>
      <param name="file" value="${sax.jar}"/>
      <param name="todir" value="${build.library}/lib/old-dependencies"/>
    </antcall>
           
    <antcall target="processIfPropSet">
      <param name="prop" value="xalan.jar"/>
      <param name="task" value="copyIfPropSet"/>
      <param name="file" value="${xalan.jar}"/>
      <param name="todir" value="${build.library}/lib/old-dependencies"/>
    </antcall>

    <antcall target="processIfPropSet">
      <param name="prop" value="xercesImpl.jar"/>
      <param name="task" value="copyIfPropSet"/>
      <param name="file" value="${xercesImpl.jar}"/>
      <param name="todir" value="${build.library}/lib/old-dependencies"/>
    </antcall>

  </target>

  <!-- Compile the examples application -->
  <target name="examples-build" depends="library-build">

    <!-- Compile the examples source code -->
    <javac srcdir="${examples.src}" destdir="${build.examples}/WEB-INF/classes"
           classpath="${servlet24.jar}:${jsp20.jar}:${build.library}/classes"
           debug="${compile.debug}"
           deprecation="${compile.deprecation}"
           optimize="${compile.optimize}"/>
  
    <!-- Copy web.xml + examples TLD -->
    <copy todir="${build.examples}/WEB-INF">
      <fileset dir="${examples.src}/conf"/>
    </copy>
    
    <!-- Copy web pages -->
    <copy todir="${build.examples}">
      <fileset dir="${examples.src}/web"/>
    </copy>
        
    <!-- copy the runtime jar files -->
    <copy todir="${build.examples}/WEB-INF/lib">
      <fileset dir="${build.library}/lib" includes="*.jar"/>
    </copy>
    
  </target>

  <!-- Compile the documentation application -->
  <target name="documentation-build" depends="prepare-build">
  
    <copy todir="${build.doc}/WEB-INF">
      <fileset dir="${doc.src}/conf"/>
    </copy>
    
    <copy todir="${build.doc}">
      <fileset dir="${doc.src}/web">
        <include name="**/*.html"/>
      </fileset>
    </copy>    
  </target>
  
  <!-- =================================================================== -->
  <!-- Create the Distribution                                             -->
  <!-- =================================================================== -->

  <!-- Create the entire set of distribution files -->
  <target name="dist" depends="library-dist,examples-dist,documentation-dist,javadoc-dist"/>

  <!-- Create the library distribution files -->
  <target name="library-dist" depends="library-build, prepare-dist">

    <!-- Copy the runtime jar files -->
    <copy todir="${dist.library}/lib">
      <fileset dir="${build.library}/lib" includes="**/*.jar"/>
    </copy>

    <!-- All TLDs are copied in the 'tld' dir of the distribution -->
    <copy todir="${dist.dir}/${taglib.name}/tld">
      <fileset dir="${conf.src}" includes="*.tld"/>
    </copy>
      
    <!-- LICENSE and NOTICE files copied at the top level of the distribution -->
    <copy file="../LICENSE" tofile="${dist.library}/LICENSE"/>
    <copy file="../NOTICE" tofile="${dist.library}/NOTICE"/>

    <!-- README file copied at the top level of the distribution -->
    <copy file="README_bin.txt" tofile="${dist.library}/README"/>
    
  </target>

  <!-- Create the examples application WAR file -->
  <target name="examples-dist" depends="examples-build, prepare-dist">    
      <!-- create the jar for the examples webapp -->  
      <jar jarfile="${dist.examples}" basedir="${build.examples}"/>
  </target>

  <!-- Create the documentation application WAR file -->
  <target name="documentation-dist" depends="documentation-build, prepare-dist">
      <jar jarfile="${dist.doc}" basedir="${build.doc}" excludes="intro.html"/>
      <mkdir dir="${taglibs.doc}"/>
      <copy todir="${taglibs.doc}">
          <fileset dir="${build.doc}">
              <exclude name="WEB-INF/**"/>
          </fileset>
      </copy>
  </target>
  
  <!-- Create the javadocs -->
  <target name="javadoc-dist" depends="prepare-dist">
   <javadoc packagenames="javax.servlet.jsp.jstl.*"
            sourcepath="src"
            classpath="${servlet24.jar}:${jsp20.jar}:${jdbc2_0-stdext.jar}:${jaxp-api.jar}:${dom.jar}:${sax.jar}:${xercesImpl.jar}:${xalan.jar}"
            destdir="${dist.library}/javadoc"
            bottom='&lt;font size="-1"&gt;Copyright 2003 Sun Microsystems, Inc. All Rights Reserved.&lt;/font&gt;'/>
  </target>

  <!-- =================================================================== -->
  <!-- Nightly (components generated for the website)                      -->
  <!-- =================================================================== -->
  
  <target name="dist-nightly" depends="dist">
    <!-- website intro page for the taglib -->
    <style in="${xml.src}/intro.xml"
           destdir="${build.doc}"                                          
           out="${build.doc}/intro.html"
           style="${taglibs.xsl}">
      <param name="prefix" expression="../../"/>
    </style>
    <copy file="${build.doc}/intro.html" todir="${taglibs.doc}"/>
  </target>    
  
  <!-- =================================================================== -->
  <!-- Public utility targets                                              -->
  <!-- =================================================================== -->
 
  <!-- Delete build and dist directories so we can start from scratch -->
  <target name="clean">
    <delete dir="${build.dir}/${taglib.name}"/>
    <delete dir="${dist.dir}/${taglib.name}"/>
  </target>

  <!-- =================================================================== -->
  <!-- Private utility targets                                              -->
  <!-- =================================================================== -->
  
  <!-- Check the availability of a required jar -->
  <target name="requiredJar">
    <echo message="  ${prop}"/>
    <available file="${file}" property="requirement.satisfied"/>
    <antcall target="requiredJarFailed"/>
  </target>

  <!-- Support for target 'requiredJar' -->
  <target name="requiredJarFailed" unless="requirement.satisfied">
    <echo message="The property ${prop} must be set to a jar file containing"/>
    <echo message="the '${desc}'."/>
    <fail message="Current value for ${prop} is: ${file}."/>
  </target>
  
  <!-- Process a target only if a property is set.
       Allows us to ignore some dependencies that are included in
       J2SE 1.4 but were not prior to that. -->
  <target name="processIfPropSet">
    <echo message="  ${prop}"/>
    <condition property="prop.specified">
      <isSet property="${prop}"/>
    </condition>
    <antcall target="${task}"/>
    <antcall target="${task}Not"/>
  </target>

  <!-- Check the availability of a required jar only if property is set -->
  <target name="requiredJarIfPropSet" if="prop.specified">
    <antcall target="requiredJar"/>
  </target>

  <!-- Warning message when required jar is ignored because the property
       is not set. -->
  <target name="requiredJarIfPropSetNot" unless="prop.specified">
    <echo message="  Ignoring dependency on ${prop} because property is not set."/>
    <echo message="  OK as long as both compile and run-time environments are at least J2SE 1.4."/>
  </target>

  <!-- Copy file only if property is set -->
  <target name="copyIfPropSet" if="prop.specified">
    <copy file="${file}" todir="${todir}"/>
  </target>

  <!-- Warning message when file is not copied because the property
       is not set. -->
  <target name="copyIfPropSetNot" unless="prop.specified">
    <echo message="  Ignoring copy of ${prop} because property is not set."/>
  </target>  

  <!-- =================================================================== -->
  <!-- Perform an official release -->
  <!-- =================================================================== -->
  <target name="release" depends="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"/>
    <delete dir="${dist.dir}/${release.name}"/> 
    <delete file="${dist.dir}/${release.name}.tar"/> 
    <antcall target="${release.post}"/>
  </target>

  <!-- target that does nothing -->
  <target name="nop"/>

  <!-- =================================================================== -->
  <!-- Unit Test PassThru Targets -->
  <!-- =================================================================== -->
  <target name="test" depends="build">
    <ant antfile="build-tests.xml" target="run.test"/>
  </target>

  <target name="run.cactus" depends="build">
    <ant antfile="build-tests.xml" target="run.cactus"/>
  </target>

  <target name="run.junit" depends="build">
    <ant antfile="build-tests.xml" target="junit"/>
  </target>

</project>
