<?xml version="1.0"?>
<!--
 Licensed to the Apache Software Foundation (ASF) under one or more
  contributor license agreements.  See the NOTICE file distributed with
  this work for additional information regarding copyright ownership.
  The ASF licenses this file to You under the Apache License, Version 2.0
  (the "License"); you may not use this file except in compliance with
  the License.  You may obtain a copy of the License at

      http://www.apache.org/licenses/LICENSE-2.0

  Unless required by applicable law or agreed to in writing, software
  distributed under the License is distributed on an "AS IS" BASIS,
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  See the License for the specific language governing permissions and
  limitations under the License.
-->
<project name="Tomcat 6.0" default="deploy" basedir=".">


  <!-- ===================== Initialize Property Values =================== -->

  <!-- We read customizable properties from the file "build.properties.default" -->
  <!-- and also from "build.properties" if it exists.                           -->
  <!-- The values in "build.properties" have stronger preference.               -->
  <!-- If you want to customize your build, you can either change the values    -->
  <!-- directly in the default file, or create a new build.properties and set   -->
  <!-- the values there. This way you don't have to change a file which is part -->
  <!-- of the original project source code.                                     -->
  <!-- See "build.properties.default" in the top level directory for some       -->
  <!-- property values you may customize.                                       -->
  <property file="${user.home}/build.properties"/>
  <property file="build.properties"/>

  <property file="build.properties.default"/>

  <!-- Project Properties -->
  <property name="project"               value="apache-tomcat" />
  <property name="name"                  value="Apache Tomcat" />

  <property name="version.major"         value="6" />
  <property name="version.minor"         value="0" />
  <property name="version.build"         value="0" />
  <property name="version.patch"         value="0" />
  <property name="version.suffix"        value="-dev" />

  <property name="version"               value="${version.major}.${version.minor}.${version.build}${version.suffix}" />
  <property name="version.number"        value="${version.major}.${version.minor}.${version.build}.${version.patch}" />
  <property name="version.major.minor"   value="${version.major}.${version.minor}" />

  <property name="final.name"            value="${project}-${version}" />
  <property name="final-src.name"        value="${project}-${version}-src" />

  <!-- Locations to create build artifacts -->
  <property name="tomcat.home"           value="${basedir}"/>
  <property name="tomcat.output"         value="${basedir}/output"/>
  <property name="tomcat.build"          value="${tomcat.output}/build"/>
  <property name="tomcat.classes"        value="${tomcat.output}/classes"/>
  <property name="tomcat.dist"           value="${tomcat.output}/dist"/>
  <property name="tomcat.manifests"      value="${tomcat.output}/manifests"/>
  <property name="test.classes"          value="${tomcat.output}/testclasses"/>
  <property name="test.temp"             value="${tomcat.output}/test-tmp"/>
  <property name="test.reports"          value="${tomcat.build}/logs"/>
  <property name="test.apr.loc"          value="${tomcat.build}/bin/native"/>

  <!-- Can't be lower - jsp uses templates -->
  <property name="compile.source" value="1.5"/>
  <!-- Can't be higher - must run on 1.5 -->
  <property name="compile.target" value="1.5"/>

  <!-- Exact spec versions (for the manifests) -->
  <property name="servlet.revision" value="MR2" />
  <property name="jsp.revision" value="FR" />
  <property name="el.revision" value="FR" />

  <!-- JAR artifacts -->
  <property name="bootstrap.jar" value="${tomcat.build}/bin/bootstrap.jar"/>
  <property name="tomcat-juli.jar" value="${tomcat.build}/bin/tomcat-juli.jar"/>

  <property name="annotations-api.jar" value="${tomcat.build}/lib/annotations-api.jar"/>
  <property name="servlet-api.jar" value="${tomcat.build}/lib/servlet-api.jar"/>
  <property name="jsp-api.jar" value="${tomcat.build}/lib/jsp-api.jar"/>
  <property name="el-api.jar" value="${tomcat.build}/lib/el-api.jar"/>
  <property name="catalina.jar" value="${tomcat.build}/lib/catalina.jar"/>
  <property name="catalina-tribes.jar" value="${tomcat.build}/lib/catalina-tribes.jar"/>
  <property name="catalina-ha.jar" value="${tomcat.build}/lib/catalina-ha.jar"/>
  <property name="catalina-ant.jar" value="${tomcat.build}/lib/catalina-ant.jar"/>
  <property name="tomcat-coyote.jar" value="${tomcat.build}/lib/tomcat-coyote.jar"/>

  <property name="jasper.jar" value="${tomcat.build}/lib/jasper.jar"/>
  <property name="jasper-el.jar" value="${tomcat.build}/lib/jasper-el.jar"/>

  <property name="tomcat-dbcp.home" value="${base.path}/tomcat${version.major}-deps/dbcp" />
  <property name="tomcat-dbcp.jar" value="${tomcat-dbcp.home}/tomcat-dbcp.jar"/>
  <available property="tomcat-dbcp.present" file="${tomcat-dbcp.jar}" />
  <available property="jdk16.present" classname="javax.sql.StatementEvent" />

  <!-- Tests To Run -->
  <property name="test.name" value="**/Test*.java"/>
  <property name="test.formatter" value="-Dorg.apache.juli.formatter=java.util.logging.SimpleFormatter"/>

  <!-- Classpath -->
  <path id="tomcat.classpath">
    <pathelement location="${ant.jar}"/>
    <pathelement location="${jdt.jar}"/>
  </path>
  <path id="tomcat.test.classpath">
    <pathelement location="${tomcat.classes}"/>
    <pathelement location="${test.classes}"/>
    <pathelement location="${junit.jar}"/>
    <pathelement location="${hamcrest.jar}"/>
    <path refid="tomcat.classpath" />
  </path>

  <!-- Version info filter set -->
  <tstamp>
    <format property="year" pattern="yyyy" locale="en" timezone="UTC"/>
    <format property="TODAY" pattern="MMM d yyyy" locale="en" timezone="UTC"/>
    <format property="TSTAMP" pattern="HH:mm:ss" locale="en" timezone="UTC"/>
  </tstamp>
  <filterset id="version.filters">
    <filter token="YEAR" value="${year}"/>
    <filter token="VERSION" value="${version}"/>
    <filter token="VERSION_NUMBER" value="${version.number}"/>
    <filter token="VERSION_MAJOR" value="${version.major}"/>
    <filter token="VERSION_MAJOR_MINOR" value="${version.major.minor}"/>
    <filter token="VERSION_BUILT" value="${TODAY} ${TSTAMP} UTC"/>
    <filter token="JDT_VERSION" value="${jdt.version}"/>
  </filterset>

  <!-- Just build Tomcat -->
  <target name="build-prepare">

    <mkdir dir="${tomcat.classes}"/>

    <delete dir="${tomcat.build}/temp" />
    <delete dir="${tomcat.build}/work" />

    <mkdir dir="${tomcat.build}"/>
    <mkdir dir="${tomcat.build}/bin"/>
    <mkdir dir="${tomcat.build}/conf"/>
    <mkdir dir="${tomcat.build}/lib"/>
    <mkdir dir="${tomcat.build}/logs"/>
    <mkdir dir="${tomcat.build}/temp"/>
    <mkdir dir="${tomcat.build}/webapps"/>

  </target>

  <target name="compile-prepare">
    <!-- Add the builtin catalina.properties -->
    <copy todir="java/org/apache/catalina/startup"
          file="conf/catalina.properties" encoding="ISO-8859-1">
      <filterset refid="version.filters"/>
    </copy>
  </target>

  <target name="compile" depends="build-prepare,compile-prepare">

    <!-- Compile internal server components -->
    <javac srcdir="java" destdir="${tomcat.classes}"
           debug="${compile.debug}"
           deprecation="${compile.deprecation}"
           source="${compile.source}"
           target="${compile.target}"
           excludes="**/CVS/**,**/.svn/**"
           encoding="ISO-8859-1">
<!-- Comment this in to show unchecked warnings:
      <compilerarg value="-Xlint:unchecked"/>
 -->
      <classpath refid="tomcat.classpath" />
      <exclude name="org/apache/naming/factory/webservices/**" />
    </javac>
    <!-- Copy static resource files -->
    <copy todir="${tomcat.classes}" encoding="ISO-8859-1">
      <filterset refid="version.filters"/>
      <fileset dir="java">
        <include name="**/*.properties"/>
        <include name="**/*.dtd"/>
        <include name="**/*.tasks"/>
        <include name="**/*.xsd"/>
        <include name="**/*.xml"/>
      </fileset>
    </copy>
    <!-- Copy JSP Schemas and DTDs to be packed into servlet-api.jar -->
    <copy todir="${tomcat.classes}/javax/servlet/resources" encoding="ISO-8859-1">
      <fileset dir="${tomcat.classes}/javax/servlet/jsp/resources">
        <include name="*" />
        <exclude name="jspxml*" />
      </fileset>
    </copy>

  </target>

  <target name="build-only" depends="compile,package" />

  <!-- Pattern sets for jar files -->
  <patternset id="files.annotations-api">
    <include name="javax/annotation/*" />
    <include name="javax/annotation/security/*" />
    <include name="javax/ejb/*" />
    <include name="javax/persistence/*" />
    <include name="javax/xml/ws/*" />
  </patternset>

  <patternset id="files.servlet-api">
    <include name="javax/servlet/*" />
    <include name="javax/servlet/http/*" />
    <include name="javax/servlet/resources/*" />
  </patternset>

  <patternset id="files.jsp-api">
    <include name="javax/servlet/jsp/**" />
  </patternset>

  <patternset id="files.el-api">
    <include name="javax/el/*" />
  </patternset>

  <patternset id="files.bootstrap">
    <include name="org/apache/catalina/startup/Bootstrap.*" />
    <include name="org/apache/catalina/startup/catalina.properties" />
    <include name="org/apache/catalina/startup/CatalinaProperties.*" />
    <include name="org/apache/catalina/startup/ClassLoaderFactory.*" />
    <include name="org/apache/catalina/startup/Tool.*" />
    <include name="org/apache/catalina/loader/StandardClassLoader*.*" />
    <include name="org/apache/catalina/loader/Extension.*" />
    <include name="org/apache/catalina/loader/Reloader.*" />
    <include name="org/apache/catalina/security/SecurityClassLoad.*" />
    <include name="org/apache/naming/JndiPermission.*" />
    <include name="org/apache/tomcat/util/compat/*" />
  </patternset>

  <patternset id="files.tomcat-juli">
    <include name="org/apache/juli/**" />
  </patternset>

  <patternset id="files.catalina">
    <include name="org/apache/*" />
    <include name="org/apache/catalina/**" />
    <include name="org/apache/naming/**" />
    <!-- Modules -->
    <exclude name="org/apache/catalina/ant/**" />
    <exclude name="org/apache/catalina/cluster/**" />
    <exclude name="org/apache/catalina/ha/**" />
    <exclude name="org/apache/catalina/mbeans/JmxRemote*" />
    <exclude name="org/apache/catalina/tribes/**" />
    <exclude name="org/apache/catalina/launcher/**" />
    <exclude name="org/apache/catalina/storeconfig/**" />
    <exclude name="org/apache/naming/factory/webservices/**" />
  </patternset>

  <patternset id="files.catalina-tribes">
    <include name="org/apache/catalina/tribes/**" />
  </patternset>

  <patternset id="files.catalina-ha">
    <include name="org/apache/catalina/ha/**" />
  </patternset>

  <patternset id="files.catalina-ant">
    <include name="org/apache/catalina/ant/*" />
    <include name="org/apache/catalina/ant/jmx/*" />
    <include name="org/apache/catalina/util/Base64.*" />
  </patternset>

  <patternset id="files.tomcat-coyote">
    <include name="org/apache/coyote/**" />
    <include name="org/apache/tomcat/jni/**" />
    <include name="org/apache/jk/**" />
    <include name="org/apache/tomcat/util/**" />
  </patternset>

  <patternset id="files.jasper">
    <include name="org/apache/*" />
    <include name="org/apache/jasper/**" />
  </patternset>

  <patternset id="files.jasper-el">
    <include name="org/apache/el/**" />
  </patternset>


  <macrodef name="jarIt" description="utility macro for standard JAR packaging">
    <attribute name="jarfile" description="the name of the JAR file to create"/>
    <attribute name="filesId" description="the patternset id of the files to use"/>
    <attribute name="manifest" description="the manifest file use"
               default="${tomcat.manifests}/default.manifest" />
    <attribute name="notice" description="the LICENSE file to use"
               default="${tomcat.manifests}/default.notice" />
    <attribute name="license" description="the NOTICE file to use"
               default="${tomcat.manifests}/default.license" />
    <sequential>
      <jar  jarfile="@{jarfile}" manifest="@{manifest}">
        <fileset dir="${tomcat.classes}">
          <patternset refid="@{filesId}"/>
          <!-- Javadoc and i18n exclusions -->
          <exclude name="**/package.html" />
          <exclude name="**/LocalStrings_*" />
        </fileset>
        <zipfileset file="@{notice}" fullpath="META-INF/NOTICE" />
        <zipfileset file="@{license}" fullpath="META-INF/LICENSE" />
      </jar>
    </sequential>
  </macrodef>

  <target name="build-manifests" >
    <!-- Filtering tokens for JAR manifests-->
    <filter token="source.jdk" value="${compile.source}"/>
    <filter token="target.jdk" value="${compile.target}"/>
    <filter token="servlet.revision" value="${servlet.revision}"/>
    <filter token="jsp.revision" value="${jsp.revision}"/>
    <filter token="el.revision" value="${el.revision}"/>

    <mkdir dir="${tomcat.manifests}" />
    <copy todir="${tomcat.manifests}" overwrite="yes" filtering="yes"
      encoding="ISO-8859-1">
      <filterset refid="version.filters"/>
      <fileset dir="${tomcat.home}/res/META-INF" >
        <include name="*.manifest" />
        <include name="*.license" />
        <include name="*.notice" />
      </fileset>
    </copy>

  </target>

  <target name="package" depends="build-manifests" >
    <!-- Common Annotations 1.0 JAR File -->
    <jarIt jarfile="${annotations-api.jar}" filesId="files.annotations-api"
      manifest="${tomcat.manifests}/annotations-api.jar.manifest" />

    <!-- Servlet 2.5 Implementation JAR File -->
    <jarIt jarfile="${servlet-api.jar}" filesId="files.servlet-api"
      manifest="${tomcat.manifests}/servlet-api.jar.manifest"
      license="${tomcat.manifests}/servlet-api.jar.license"
      notice="${tomcat.manifests}/servlet-api.jar.notice" />

    <!-- JSP 2.1 Implementation JAR File -->
    <jarIt jarfile="${jsp-api.jar}" filesId="files.jsp-api"
      manifest="${tomcat.manifests}/jsp-api.jar.manifest" />


    <!-- JSP 2.1 EL Implementation JAR File -->
    <jarIt jarfile="${el-api.jar}" filesId="files.el-api"
      manifest="${tomcat.manifests}/el-api.jar.manifest" />

    <!-- Bootstrap JAR File -->
    <jarIt jarfile="${bootstrap.jar}" filesId="files.bootstrap"
      manifest="${tomcat.manifests}/bootstrap.jar.manifest" />

    <!-- Tomcat-juli JAR File -->
    <jarIt jarfile="${tomcat-juli.jar}" filesId="files.tomcat-juli" />

    <!-- Catalina Main JAR File -->
    <jarIt jarfile="${catalina.jar}" filesId="files.catalina" />

    <!-- Catalina GroupCom/Tribes JAR File -->
    <jarIt jarfile="${catalina-tribes.jar}" filesId="files.catalina-tribes" />

    <!-- Catalina Cluster/HA JAR File -->
    <jarIt jarfile="${catalina-ha.jar}" filesId="files.catalina-ha" />

    <!-- Catalina Ant Tasks JAR File -->
    <jarIt jarfile="${catalina-ant.jar}" filesId="files.catalina-ant" />

    <!-- Protocol handlers - Coyote -->
    <jarIt jarfile="${tomcat-coyote.jar}" filesId="files.tomcat-coyote" />

    <!-- Jasper Implementation JAR File -->
    <jarIt jarfile="${jasper.jar}" filesId="files.jasper" />

    <!-- Jasper EL Implementation JAR File -->
    <jarIt jarfile="${jasper-el.jar}" filesId="files.jasper-el" />

    <!-- i18n JARs -->
    <jar jarfile="${tomcat.build}/lib/tomcat-i18n-es.jar"
      manifest="${tomcat.manifests}/default.manifest" >
      <fileset dir="${tomcat.classes}">
        <include name="**/LocalStrings_es.properties" />
      </fileset>
      <zipfileset file="${tomcat.manifests}/default.notice"
        fullpath="META-INF/NOTICE" />
      <zipfileset file="${tomcat.manifests}/default.license"
        fullpath="META-INF/LICENSE" />
    </jar>
    <jar jarfile="${tomcat.build}/lib/tomcat-i18n-fr.jar"
      manifest="${tomcat.manifests}/default.manifest" >
      <fileset dir="${tomcat.classes}">
        <include name="**/LocalStrings_fr.properties" />
      </fileset>
      <zipfileset file="${tomcat.manifests}/default.notice"
        fullpath="META-INF/NOTICE" />
      <zipfileset file="${tomcat.manifests}/default.license"
        fullpath="META-INF/LICENSE" />
    </jar>
    <jar jarfile="${tomcat.build}/lib/tomcat-i18n-ja.jar"
      manifest="${tomcat.manifests}/default.manifest" >
      <fileset dir="${tomcat.classes}">
        <include name="**/LocalStrings_ja.properties" />
      </fileset>
      <zipfileset file="${tomcat.manifests}/default.notice"
        fullpath="META-INF/NOTICE" />
      <zipfileset file="${tomcat.manifests}/default.license"
        fullpath="META-INF/LICENSE" />
    </jar>

  </target>

  <target name="build-docs">

    <copy todir="${tomcat.build}/webapps">
      <fileset dir="webapps">
        <include name="docs/images/**"/>
        <include name="docs/**/*.html"/>
        <include name="docs/WEB-INF/**"/>
        <include name="docs/appdev/*.txt"/>
        <include name="docs/appdev/sample/**"/>
      </fileset>
        <fileset dir="webapps">
          <include name="docs/architecture/**"/>
          <exclude name="docs/architecture/*.xml"/>
        </fileset>
    </copy>
    <copy todir="${tomcat.build}/webapps/docs" encoding="ISO-8859-1">
      <filterset refid="version.filters"/>
      <fileset dir=".">
        <include name="BUILDING.txt"/>
        <include name="RUNNING.txt"/>
      </fileset>
    </copy>
    <copy tofile="${tomcat.build}/webapps/docs/RELEASE-NOTES.txt" file="RELEASE-NOTES" encoding="ISO-8859-1">
      <filterset refid="version.filters"/>
    </copy>

    <copy   tofile="${tomcat.build}/webapps/docs/appdev/sample/build.xml"
              file="webapps/docs/appdev/build.xml.txt"/>

    <mkdir dir="${tomcat.build}/webapps/docs/funcspecs" />

    <!-- XSL processing -->
    <xslt basedir="webapps/docs"
           destdir="${tomcat.build}/webapps/docs"
         extension=".html"
             style="webapps/docs/tomcat-docs.xsl"
          excludes="build.xml project.xml"
          includes="*.xml">
      <param name="relative-path" expression="."/>
      <param name="version" expression="${version}"/>
      <param name="build-date" expression="${TODAY}"/>
      <param name="year" expression="${year}"/>
    </xslt>
    <xslt basedir="webapps/docs/appdev"
           destdir="${tomcat.build}/webapps/docs/appdev"
         extension=".html"
             style="webapps/docs/tomcat-docs.xsl"
          excludes="project.xml"
          includes="*.xml">
      <param name="relative-path" expression=".."/>
      <param name="version" expression="${version}"/>
      <param name="build-date" expression="${TODAY}"/>
      <param name="year" expression="${year}"/>
    </xslt>
    <xslt basedir="webapps/docs/funcspecs"
           destdir="${tomcat.build}/webapps/docs/funcspecs"
         extension=".html"
             style="webapps/docs/tomcat-docs.xsl"
          excludes="project.xml"
          includes="*.xml">
      <param name="relative-path" expression=".."/>
      <param name="version" expression="${version}"/>
      <param name="build-date" expression="${TODAY}"/>
      <param name="year" expression="${year}"/>
    </xslt>
    <xslt basedir="webapps/docs/config"
           destdir="${tomcat.build}/webapps/docs/config"
         extension=".html"
             style="webapps/docs/tomcat-docs.xsl"
          excludes="project.xml"
          includes="*.xml">
      <param name="relative-path" expression=".."/>
      <param name="version" expression="${version}"/>
      <param name="build-date" expression="${TODAY}"/>
      <param name="year" expression="${year}"/>
    </xslt>
    <xslt basedir="webapps/docs/architecture"
           destdir="${tomcat.build}/webapps/docs/architecture"
         extension=".html"
             style="webapps/docs/tomcat-docs.xsl"
          excludes="project.xml"
          includes="*.xml">
      <param name="relative-path" expression=".."/>
      <param name="version" expression="${version}"/>
      <param name="build-date" expression="${TODAY}"/>
      <param name="year" expression="${year}"/>
    </xslt>

    <xslt basedir="webapps/docs/tribes"
               destdir="${tomcat.build}/webapps/docs/tribes"
             extension=".html"
                 style="webapps/docs/tomcat-docs.xsl"
              excludes="project.xml"
              includes="*.xml">
          <param name="relative-path" expression=".."/>
      <param name="version" expression="${version}"/>
      <param name="build-date" expression="${TODAY}"/>
      <param name="year" expression="${year}"/>
    </xslt>
  </target>

  <target name="warn.dbcp" unless="tomcat-dbcp.present">
    <echo>WARNING: tomcat-dbcp.jar not included, this build can't be used
    in a release. Please run 'ant download' with JDK1.5 if you are 
    building a tomcat release.</echo>
  </target>

  <target name="deploy" depends="build-only,build-docs,warn.dbcp">

    <copy tofile="${tomcat.build}/bin/tomcat-native.tar.gz"
            file="${tomcat-native.tar.gz}" />
    <copy tofile="${tomcat.build}/bin/commons-daemon-native.tar.gz"
            file="${commons-daemon.native.src.tgz}" />

    <copy tofile="${tomcat.build}/bin/commons-daemon.jar" file="${commons-daemon.jar}" />

    <!-- Copy scripts -->
    <copy todir="${tomcat.build}/bin">
      <fileset dir="bin">
         <exclude name="**/*.launch"/>
         <exclude name="**/*.sh"/>
         <exclude name="**/*.bat"/>
      </fileset>
    </copy>
    <copy todir="${tomcat.build}/bin" encoding="ISO-8859-1">
      <filterset refid="version.filters"/>
      <fileset dir="bin">
         <include name="**/*.sh"/>
         <include name="**/*.bat"/>
      </fileset>
    </copy>
    <!-- Copy doesn't retain permissions -->
    <chmod dir="${tomcat.build}/bin" includes="*.sh" perm="+x"/>

    <!-- Copy static resource files -->
    <copy todir="${tomcat.build}/conf" encoding="ISO-8859-1">
      <filterset refid="version.filters"/>
      <fileset dir="conf">
        <include name="**/*.policy"/>
        <include name="**/*.xml"/>
        <include name="**/*.properties"/>
      </fileset>
    </copy>

    <!-- Copy other regular webapps -->
    <copy todir="${tomcat.build}/webapps">
      <fileset dir="webapps">
        <include name="ROOT/**"/>
        <exclude name="ROOT/index.html"/>
        <exclude name="ROOT/index.jsp"/>
        <include name="examples/**"/>
        <include name="manager/**"/>
        <include name="host-manager/**"/>
      </fileset>
    </copy>
    <copy todir="${tomcat.build}/webapps" encoding="ISO-8859-1">
      <filterset refid="version.filters" />
      <fileset dir="webapps">
        <include name="ROOT/index.html"/>
        <include name="ROOT/index.jsp"/>
      </fileset>
    </copy>

    <copy tofile="${tomcat.build}/webapps/ROOT/RELEASE-NOTES.txt" file="RELEASE-NOTES" encoding="ISO-8859-1">
      <filterset refid="version.filters"/>
    </copy>

    <!-- Build classes for examples webapp -->
    <javac   srcdir="webapps/examples/WEB-INF/classes"
             destdir="${tomcat.build}/webapps/examples/WEB-INF/classes"
             debug="${compile.debug}" deprecation="${compile.deprecation}"
             source="${compile.source}"
             target="${compile.target}"
             classpath="${tomcat.classes}"
             excludes="**/CVS/**,**/.svn/**"
             encoding="ISO-8859-1">
    </javac>

    <javac   srcdir="webapps/examples/jsp/plugin/applet"
             destdir="${tomcat.build}/webapps/examples/jsp/plugin/applet"
             debug="${compile.debug}" deprecation="${compile.deprecation}"
             source="${compile.source}"
             target="${compile.target}"
             classpath="$tomcat.lcasses}"
             excludes="**/CVS/**,**/.svn/**"
             encoding="ISO-8859-1">
    </javac>

    <!-- Add sources for examples -->
    <taskdef    name="txt2html"
           classname="org.apache.tomcat.buildutil.Txt2Html"
           classpath="${tomcat.classes}" />
    <txt2html todir="${tomcat.build}/webapps/examples/jsp/jsp2/simpletag">
      <fileset dir="webapps/examples/WEB-INF/classes/jsp2/examples">
        <include name="BookBean.java"/>
      </fileset>
      <fileset dir="webapps/examples/WEB-INF/classes/jsp2/examples/simpletag">
        <include name="FindBookSimpleTag.java"/>
        <include name="RepeatSimpleTag.java"/>
        <include name="HelloWorldSimpleTag.java"/>
      </fileset>
      <fileset dir="webapps/examples/WEB-INF/classes/jsp2/examples/el">
        <include name="Functions.java"/>
      </fileset>
    </txt2html>

    <txt2html todir="${tomcat.build}/webapps/examples/jsp/jsp2/jspattribute">
      <fileset dir="webapps/examples/WEB-INF/classes/jsp2/examples">
        <include name="FooBean.java"/>
      </fileset>
      <fileset dir="webapps/examples/WEB-INF/classes/jsp2/examples/simpletag">
        <include name="ShuffleSimpleTag.java"/>
        <include name="TileSimpleTag.java"/>
        <include name="HelloWorldSimpleTag.java"/>
      </fileset>
    </txt2html>

    <txt2html todir="${tomcat.build}/webapps/examples/jsp/cal">
      <fileset dir="webapps/examples/WEB-INF/classes/cal">
        <include name="Entries.java"/>
        <include name="Entry.java"/>
        <include name="JspCalendar.java"/>
        <include name="TableBean.java"/>
      </fileset>
    </txt2html>

    <txt2html todir="${tomcat.build}/webapps/examples/jsp/jsptoserv">
      <fileset dir="webapps/examples/WEB-INF/classes">
        <include name="servletToJsp.java"/>
      </fileset>
    </txt2html>

    <txt2html todir="${tomcat.build}/webapps/examples/jsp/jsp2/el">
      <fileset dir="webapps/examples/WEB-INF/classes/jsp2/examples/el">
        <include name="Functions.java"/>
      </fileset>
    </txt2html>

    <txt2html todir="${tomcat.build}/webapps/examples/jsp/jsp2/misc">
      <fileset dir="webapps/examples/WEB-INF/classes/jsp2/examples/simpletag">
        <include name="EchoAttributesTag.java"/>
      </fileset>
    </txt2html>

    <txt2html todir="${tomcat.build}/webapps/examples/jsp/jsp2/tagfiles">
      <fileset dir="webapps/examples/WEB-INF/tags">
        <include name="**/*.tag" />
      </fileset>
    </txt2html>

    <txt2html todir="${tomcat.build}/webapps/examples">
      <fileset dir="webapps/examples">
        <include name="**/*.jsp" />
        <include name="**/*.jspx" />
        <include name="**/*.jspf" />
        <exclude name="error/errorpge.jsp"/>
        <exclude name="forward/one.jsp"/>
        <exclude name="include/foo.jsp"/>
        <exclude name="jsptoserv/hello.jsp"/>
        <exclude name="security/protected/error.jsp"/>
        <exclude name="security/protected/index.jsp"/>
        <exclude name="security/protected/login.jsp"/>
        <exclude name="source.jsp"/>
      </fileset>
    </txt2html>

    <copy file="${tomcat-dbcp.jar}" todir="${tomcat.build}/lib"
      failonerror="false"/>
    <copy file="${jdt.jar}" todir="${tomcat.build}/lib" />

  </target>

  <target name="clean-depend"
          description="Clean depend src components">
     <delete dir="${tomcat-dbcp.home}"/>
  </target>

  <target name="clean">
    <delete dir="${tomcat.classes}" />
    <delete dir="${tomcat.build}" />
    <delete dir="${tomcat.manifests}" />
    <delete dir="${test.classes}" />
    <delete dir="${test.temp}" />
    <!-- Remove the copied catalina.properties -->
    <delete file="java/org/apache/catalina/startup/catalina.properties" />
  </target>

  <!-- ========================= Testing ========================== -->

  <target name="test-compile" depends="compile" >
    <mkdir dir="${test.classes}"/>
    <!-- Compile -->
    <javac srcdir="test" destdir="${test.classes}"
           debug="${compile.debug}"
           deprecation="${compile.deprecation}"
           source="${compile.source}"
           target="${compile.target}"
           encoding="ISO-8859-1"
           includeantruntime="true">
      <classpath refid="tomcat.test.classpath" />
      <include name="org/apache/**" />
      <include name="javax/**" />
    </javac>
    <copy todir="${test.classes}">
        <fileset dir="test">
          <include name="META-INF/**"/>
        </fileset>
    </copy>
  </target>

  <!-- Default JUnit log output formatter -->
  <property name="junit.formatter.type" value="plain" />
  <property name="junit.formatter.usefile" value="true" />
  <property name="junit.formatter.extension" value=".txt" />

  <!-- Workaround against http://bugs.sun.com/view_bug.do?bug_id=6202721 -->
  <available file="/dev/urandom" property="test.jvmarg.egd" value="-Djava.security.egd=file:/dev/./urandom"/>
  <property name="test.jvmarg.egd" value="" />

  <target name="test" description="Runs the JUnit test cases"
          depends="test-bio,test-nio,test-apr" >
    <fileset id="test.result.skippedtests" dir="${test.reports}" includes="*.txt">
      <not>
        <contains text="Skipped: 0" />
      </not>
    </fileset>
    <fileset id="test.result.failedtests" dir="${test.reports}" includes="*.txt">
      <not>
        <contains text="Failures: 0, Errors: 0" />
      </not>
    </fileset>
    <concat>
      <header>Testsuites with skipped tests:${line.separator}</header>
      <string>${toString:test.result.skippedtests}</string>
      <filterchain>
        <tokenfilter delimOutput="${line.separator}">
          <stringtokenizer delims=";"/>
        </tokenfilter>
      </filterchain>
    </concat>
    <concat>
      <header>Testsuites with failed tests:${line.separator}</header>
      <string>${toString:test.result.failedtests}</string>
      <filterchain>
        <tokenfilter delimOutput="${line.separator}">
          <stringtokenizer delims=";"/>
        </tokenfilter>
      </filterchain>
    </concat>

    <fail if="test.result.error" message='Some tests completed with an Error. See ${tomcat.build}/logs for details, search for "ERROR".' />
    <fail if="test.result.failure" message='Some tests completed with a Failure. See ${tomcat.build}/logs for details, search for "FAILED".' />
  </target>

  <target name="test-bio" description="Runs the JUnit test cases for BIO. Does not stop on errors."
          depends="test-compile,deploy" if="${execute.test.bio}">
    <runtests protocol="org.apache.coyote.http11.Http11Protocol"
              extension=".BIO" />
  </target>

  <target name="test-nio" description="Runs the JUnit test cases for NIO. Does not stop on errors."
          depends="test-compile,deploy" if="${execute.test.nio}">
    <runtests protocol="org.apache.coyote.http11.Http11NioProtocol"
              extension=".NIO" />
  </target>

  <target name="test-apr" description="Runs the JUnit test cases for APR. Does not stop on errors."
          depends="test-compile,deploy,test-apr-exists"
          if="${apr.exists}">
    <runtests protocol="org.apache.coyote.http11.Http11AprProtocol"
              extension=".APR" />
  </target>

  <target name="test-apr-exists" description="Checks for APR lib"
          if="${execute.test.apr}">
    <available file="${test.apr.loc}" property="apr.exists" />
  </target>

  <macrodef name="runtests"
            description="Runs the unit tests using the specified connector.
              Does not stop on errors, but sets 'test.result.error' and 'test.result.failure' properties.">
    <attribute name="protocol"
               description="The class name for the connector protocol"/>
    <attribute name="extension"
               description="The extension to use to distinguish the output"/>

    <sequential>
      <mkdir dir="${test.reports}" />
      <junit printsummary="yes" fork="yes" dir="." showoutput="yes"
        errorproperty="test.result.error"
        failureproperty="test.result.failure"
        haltonfailure="${test.haltonfailure}">

        <jvmarg value="${test.jvmarg.egd}"/>
        <jvmarg value="-Djava.library.path=${test.apr.loc}"/>
        <jvmarg value="${test.formatter}"/>
        <jvmarg value="-Djava.net.preferIPv4Stack=${java.net.preferIPv4Stack}"/>

        <classpath refid="tomcat.test.classpath" />

        <sysproperty key="tomcat.test.temp" value="${test.temp}" />
        <sysproperty key="tomcat.test.basedir" value="${test.basedir}" />
        <sysproperty key="tomcat.test.tomcatbuild" value="${tomcat.build}" />
        <sysproperty key="tomcat.test.protocol" value="@{protocol}" />
        <sysproperty key="tomcat.test.accesslog" value="${test.accesslog}" />
        <sysproperty key="tomcat.test.reports" value="${test.reports}" />
        <sysproperty key="tomcat.test.openssl.path" value="${test.openssl.path}" />
        <sysproperty key="tomcat.test.relaxTiming" value="${test.relaxTiming}" />

        <formatter type="${junit.formatter.type}"
                   usefile="${junit.formatter.usefile}"
                   extension="@{extension}${junit.formatter.extension}" />

        <!-- If test.entry is defined, run a single test, otherwise run all valid tests -->
        <test todir="${test.reports}" name="${test.entry}"
              if="test.entry" unless="test.entry.methods"
           />
        <test todir="${test.reports}" name="${test.entry}" methods="${test.entry.methods}"
              if="test.entry.methods"
           />
        <batchtest todir="${test.reports}" unless="test.entry">
          <!-- Include all by default -->
          <fileset dir="test" includes="${test.name}">
            <!-- Exclude helper classes -->
            <exclude name="**/Tester*.java" />
            <!-- Exclude the tests known to fail -->
            <exclude name="org/apache/catalina/tribes/test/**" />
            <!-- Exclude performance tests. E.g. on systems with slow/inconsistent timing -->
            <exclude name="**/*Performance.java" if="${test.excludePerformance}" />
          </fileset>
        </batchtest>
      </junit>
    </sequential>
  </macrodef>

  <!-- ================ Download and dependency building =================== -->

  <target name="proxyflags">
    <!-- check proxy parameters. -->
    <condition property="useproxy">
      <equals arg1="${proxy.use}" arg2="on" />
    </condition>
  </target>

  <target name="setproxy" depends="proxyflags" if="useproxy">
    <taskdef name="setproxy"
            classname="org.apache.tools.ant.taskdefs.optional.net.SetProxy" />
    <setproxy proxyhost="${proxy.host}" proxyport="${proxy.port}"
              proxyuser="${proxy.user}" proxypassword="${proxy.password}" />
    <echo message="Using ${proxy.host}:${proxy.port} to download ${sourcefile}"/>
  </target>

  <target name="testexist">
    <echo message="Testing  for ${destfile}"/>
    <available file="${destfile}" property="exist"/>
  </target>

  <target name="downloadgz" unless="exist" depends="setproxy,testexist">
    <!-- Download and extract the package -->
    <get src="${sourcefile}" dest="${base.path}/file.tar.gz" />
    <gunzip src="${base.path}/file.tar.gz" dest="${base.path}/file.tar"/>
    <untar src="${base.path}/file.tar" dest="${base.path}"/>
    <delete file="${base.path}/file.tar"/>
    <delete file="${base.path}/file.tar.gz"/>
  </target>

  <target name="downloadgz-2" unless="exist" depends="setproxy,testexist">
    <!-- Download and extract the package from the two alternative locations -->
    <delete file="${base.path}/file.tar" quiet="true" />
    <delete file="${base.path}/file.tar.gz" quiet="true" />
    <antcall target="trydownload">
      <param name="sourcefile" value="${sourcefile.1}" />
      <param name="destfile" value="${base.path}/file.tar.gz" />
    </antcall>
    <antcall target="trydownload">
      <param name="sourcefile" value="${sourcefile.2}" />
      <param name="destfile" value="${base.path}/file.tar.gz" />
    </antcall>
    <gunzip src="${base.path}/file.tar.gz" dest="${base.path}/file.tar"/>
    <untar src="${base.path}/file.tar" dest="${base.path}"/>
    <delete file="${base.path}/file.tar"/>
    <delete file="${base.path}/file.tar.gz"/>
  </target>

  <target name="downloadzip" unless="exist" depends="setproxy,testexist">
    <!-- Download and extract the package -->
    <get src="${sourcefile}" dest="${base.path}/file.zip" />
    <mkdir dir="${destdir}" />
    <unzip src="${base.path}/file.zip" dest="${destdir}"/>
    <delete file="${base.path}/file.zip"/>
  </target>

  <target name="downloadzip-2" unless="exist" depends="testexist">
    <!-- Download and extract the package from the two alternative locations -->
    <delete file="${base.path}/file.zip" quiet="true" />
    <antcall target="trydownload">
      <param name="sourcefile" value="${sourcefile.1}" />
      <param name="destfile" value="${base.path}/file.zip" />
    </antcall>
    <antcall target="trydownload">
      <param name="sourcefile" value="${sourcefile.2}" />
      <param name="destfile" value="${base.path}/file.zip" />
    </antcall>
    <mkdir dir="${destdir}" />
    <unzip src="${base.path}/file.zip" dest="${destdir}"/>
    <delete file="${base.path}/file.zip"/>
  </target>

  <target name="downloadfile" unless="exist" depends="setproxy,testexist">
    <!-- Download extract the file -->
    <mkdir dir="${destdir}" />
    <get src="${sourcefile}" dest="${destfile}" />
  </target>

  <target name="downloadfile-2" unless="exist" depends="testexist">
    <!-- Download the file from the two alternative locations -->
    <mkdir dir="${destdir}" />

    <antcall target="trydownload">
      <param name="sourcefile" value="${sourcefile.1}" />
    </antcall>

    <antcall target="trydownload">
      <param name="sourcefile" value="${sourcefile.2}" />
    </antcall>

    <available file="${destfile}" property="exist"/>
    <fail unless="exist" message="Failed to download [${destfile}]. All download sources are unavailable." />
  </target>

  <target name="trydownload.check" depends="setproxy">
    <condition property="trydownload.run">
      <and>
        <not>
          <available file="${destfile}" />
        </not>
        <http url="${sourcefile}" />
      </and>
    </condition>
  </target>

  <target name="trydownload" if="trydownload.run" depends="trydownload.check">
    <!-- Downloads a file if not yet downloaded and the source URL is available -->
    <get src="${sourcefile}" dest="${destfile}" />
  </target>

  <target name="download"
          description="Download (and build as necessary) dependent components"
          depends="build-manifests">

    <!-- Download Apache Tomcat Native -->
    <antcall target="downloadfile-2">
      <param name="sourcefile.1" value="${tomcat-native.loc.1}"/>
      <param name="sourcefile.2" value="${tomcat-native.loc.2}"/>
      <param name="destfile" value="${tomcat-native.tar.gz}"/>
      <param name="destdir" value="${tomcat-native.home}"/>
    </antcall>

    <antcall target="downloadzip-2">
      <param name="sourcefile.1" value="${tomcat-native.win.1}"/>
      <param name="sourcefile.2" value="${tomcat-native.win.2}"/>
      <param name="destfile" value="${tomcat-native.home}/LICENSE"/>
      <param name="destdir" value="${tomcat-native.home}"/>
    </antcall>

    <!-- Download Apache Commons Daemon -->
    <antcall target="downloadgz-2">
      <param name="sourcefile.1" value="${commons-daemon.bin.loc.1}"/>
      <param name="sourcefile.2" value="${commons-daemon.bin.loc.2}"/>
      <param name="destfile" value="${commons-daemon.jar}"/>
    </antcall>

    <antcall target="downloadfile-2">
      <param name="sourcefile.1" value="${commons-daemon.native.src.loc.1}"/>
      <param name="sourcefile.2" value="${commons-daemon.native.src.loc.2}"/>
      <param name="destfile" value="${commons-daemon.native.src.tgz}"/>
      <param name="destdir" value="${commons-daemon.home}"/>
    </antcall>

    <antcall target="downloadzip-2">
      <param name="sourcefile.1" value="${commons-daemon.native.win.loc.1}"/>
      <param name="sourcefile.2" value="${commons-daemon.native.win.loc.2}"/>
      <param name="destfile" value="${commons-daemon.native.win.mgr.exe}"/>
      <param name="destdir" value="${commons-daemon.native.win.home}"/>
    </antcall>

    <!-- Build Tomcat DBCP bundle -->
    <antcall target="downloadgz-2">
      <param name="sourcefile.1" value="${commons-pool-src.loc.1}"/>
      <param name="sourcefile.2" value="${commons-pool-src.loc.2}"/>
      <param name="destfile" value="${commons-pool.home}/build.xml" />
    </antcall>
    <antcall target="downloadgz-2">
      <param name="sourcefile.1" value="${commons-dbcp-src.loc.1}"/>
      <param name="sourcefile.2" value="${commons-dbcp-src.loc.2}"/>
      <param name="destfile" value="${commons-dbcp.home}/build.xml" />
    </antcall>
    <mkdir dir="${tomcat-dbcp.home}"/>
    <antcall target="build-tomcat-dbcp" />

    <!-- Download JDT (Eclipse compiler) -->
    <antcall target="downloadfile-2">
      <param name="sourcefile.1" value="${jdt.loc.1}"/>
      <param name="sourcefile.2" value="${jdt.loc.2}"/>
      <param name="destfile" value="${jdt.jar}"/>
      <param name="destdir" value="${jdt.home}"/>
    </antcall>

    <!-- Download NSIS (Nullsoft Scriptable Install System) -->
    <antcall target="downloadzip">
      <param name="sourcefile" value="${nsis.loc}"/>
      <param name="destfile" value="${nsis.exe}"/>
      <param name="destdir" value="${nsis.home}/.."/>
    </antcall>

    <!-- Libraries used for testing. JUnit, Hamcrest -->
    <antcall target="downloadfile">
      <param name="sourcefile" value="${junit.loc}"/>
      <param name="destfile" value="${junit.jar}"/>
      <param name="destdir" value="${junit.home}"/>
    </antcall>

    <antcall target="downloadfile">
      <param name="sourcefile" value="${hamcrest.loc}"/>
      <param name="destfile" value="${hamcrest.jar}"/>
      <param name="destdir" value="${hamcrest.home}"/>
    </antcall>

  </target>

  <target name="build-tomcat-dbcp" unless="jdk16.present"
          depends="build-manifests">
    <copy todir="${tomcat-dbcp.home}">
      <fileset dir="${commons-pool.home}">
        <include name="**/*.java" />
        <exclude name="**/test/**" />
      </fileset>
      <fileset dir="${commons-dbcp.home}">
        <include name="**/*.java" />
        <exclude name="**/test/**" />
        <exclude name="**/managed/**" />
      </fileset>
    </copy>
    <replace dir="${tomcat-dbcp.home}/src/java/org/apache/commons"
        encoding="ISO-8859-1">
      <replacefilter token="org.apache.commons"
            value="org.apache.tomcat.dbcp" />
    </replace>
    <replace dir="${tomcat-dbcp.home}/src/java/org/apache/commons/pool/impl"
        encoding="ISO-8859-1">
      <replacefilter token="enum"
            value="enumeration" />
    </replace>

    <mkdir dir="${tomcat-dbcp.home}/src/java/org/apache/tomcat/dbcp" />
    <move todir="${tomcat-dbcp.home}/src/java/org/apache/tomcat/dbcp">
      <fileset dir="${tomcat-dbcp.home}/src/java/org/apache/commons" />
    </move>
    <mkdir dir="${tomcat-dbcp.home}/classes"/>
    <javac destdir="${tomcat-dbcp.home}/classes"
           debug="${compile.debug}"
           deprecation="${compile.deprecation}"
           source="${compile.source}"
           target="${compile.target}"
           sourcepath="${tomcat-dbcp.home}/src/java"
           srcdir="${tomcat-dbcp.home}/src/java"
           encoding="ISO-8859-1">
      <include name="**" />
    </javac>
    <jar jarfile="${tomcat-dbcp.jar}"
         manifest="${tomcat.manifests}/default.manifest">
      <fileset dir="${tomcat-dbcp.home}/classes">
        <include name="**/*.class" />
        <include name="**/*.properties" />
      </fileset>
      <zipfileset file="${tomcat.manifests}/default.notice"
        fullpath="META-INF/NOTICE" />
      <zipfileset file="${tomcat.manifests}/default.license"
        fullpath="META-INF/LICENSE" />
    </jar>
  </target>

</project>
