<?xml version="1.0"?>

<!--
  =======================================================================
    Apache Ant own build file

   Copyright (c) 2000-2002 The Apache Software Foundation.  All rights
   reserved.

  =======================================================================
-->
<project default="main" basedir=".">

  <!-- Give user a chance to override without editing this file
       (and without typing -D each time it compiles it) -->
  <property file=".ant.properties" />
  <property file="${user.home}/.ant.properties" />

  <property name="Name" value="Apache Ant"/>
  <property name="name" value="ant"/>
  <property name="version" value="1.5alpha"/>

  <property name="debug" value="true" />
  <property name="chmod.fail" value="true" />
  <property name="deprecation" value="false" />
  <property name="optimize" value="true" />
  <property name="junit.fork" value="false" />
  <property name="junit.filtertrace" value="off"/>
  <property name="junit.summary" value="no"/>
  
  <!--
       ===================================================================
         Set the properties related to the source tree
       ===================================================================
  -->
  <property name="src.dir" value="src"/>
  <property name="java.dir" value="${src.dir}/main"/>
  <property name="script.dir" value="${src.dir}/script"/>
  <property name="lib.dir" value="lib"/>
  <property name="docs.dir" value="docs"/>
  <property name="etc.dir" value="src/etc"/>
  <property name="tests.dir" value="src/testcases"/>
  <property name="tests.etc.dir" value="src/etc/testcases"/>

  <property name="ant.package" value="org/apache/tools/ant"/>
  <property name="optional.package" value="${ant.package}/taskdefs/optional"/>
  <property name="optional.type.package" value="${ant.package}/types/optional"/>
  <property name="util.package" value="${ant.package}/util"/>
  <property name="regexp.package" value="${util.package}/regexp"/>

  <property name="manifest" value="src/etc/manifest"/>


  <!--
       ===================================================================
         Set the properties for the build area
       ===================================================================
  -->
  <property name="build.dir" value="build"/>
  <property name="bootstrap.dir" value="bootstrap"/>
  <property name="build.classes" value="${build.dir}/classes"/>
  <property name="build.lib" value="${build.dir}/lib"/>
  <property name="build.javadocs" value="${build.dir}/javadocs"/>
  <property name="build.tests" value="${build.dir}/testcases"/>

  <path id="classpath">
  </path>

  <!-- empty for JDK 1.2+, contains classes.zip otherwise -->
  <path id="classes.zip">
    <fileset dir="${java.home}" includes="lib/classes.zip" />
  </path>

  <path id="tests-classpath">
    <pathelement location="${build.classes}" />
    <pathelement location="${build.tests}" />
    <!--
        include the test source and test data dirs
        so that we can pick resources via getResource(AsStream)
     -->
    <pathelement location="${tests.dir}"/>
    <pathelement location="${tests.etc.dir}"/>
    <path refid="classpath" />
  </path>
<!--   turn this path into a string which is passed to the tests -->
  <property name="tests-classpath.value"
            refid="tests-classpath"/>

 <!--
       ===================================================================
         Set up properties for the distribution area
       ===================================================================
  -->
  <property name="dist.name" value="jakarta-${name}-${version}"/>
  <property name="dist.base" value="distribution"/>
  <property name="dist.dir" value="dist"/>
  <property name="dist.bin" value="${dist.dir}/bin"/>
  <property name="dist.lib" value="${dist.dir}/lib"/>
  <property name="dist.docs" value="${dist.dir}/docs"/>
  <property name="dist.etc" value="${dist.dir}/etc"/>
  <property name="dist.javadocs" value="${dist.dir}/docs/manual/api"/>

  <property name="src.dist.dir" value="dist-src"/>
  <property name="src.dist.src" value="${src.dist.dir}/src"/>
  <property name="src.dist.docs" value="${src.dist.dir}/docs"/>
  <property name="src.dist.lib" value="${src.dist.dir}/lib"/>
  


  <!--
       ===================================================================
         Set up patternsets to be used by javac and junit to exclude
         files that have dependencies that are not available
       ===================================================================
  -->
  <!-- depends on JDK version -->
  <patternset id="needs.jdk1.2+">
    <exclude name="${util.package}/optional/NoExitSecurityManager.java"
             unless="jdk1.2+" />
    <exclude name="${optional.package}/Javah.java" 
             unless="jdk1.2+" />
    <exclude name="${optional.package}/metamata/*.java" 
             unless="jdk1.2+" />
    <exclude name="${optional.type.package}/depend/*.java"
             unless="jdk1.2+" />
    <exclude name="${util.package}/depend/*.java"
             unless="jdk1.2+" />
    <exclude name="${optional.package}/ejb/EjbJar.java"
             unless="jdk1.2+" />
    <exclude name="${optional.package}/ejb/*DeploymentTool.java"
             unless="jdk1.2+" />
    <exclude name="${optional.package}/ejb/IPlanet*.java"
             unless="jdk1.2+" />
    <!-- uses the context classloader -->
    <exclude name="${optional.package}/junit/JUnitClassLoaderTest.java"
             unless="jdk1.2+" />
  </patternset>
  <patternset id="needs.jdk1.3+">
    <exclude name="${ant.package}/taskdefs/TestProcess.java"
             unless="jdk1.3+" />
  </patternset>
  <patternset id="needs.jdk1.4+">
    <exclude name="${regexp.package}/Jdk14Regexp*.java"
             unless="jdk1.4+" />
  </patternset>

  <!-- classes that should be present in Sun based JVMs, but not in
  Kaffe for example -->
  <patternset id="needs.sun.tools">
    <exclude name="${optional.package}/Native2Ascii.java"
             unless="sun.tools.present" />
    <exclude name="${optional.package}/Javah.java"
             unless="sun.tools.present" />
  </patternset>
  <patternset id="needs.sun.uue">
    <exclude name="${ant.package}/taskdefs/email/UUMailer.java"
             unless="sunuue.present" />
  </patternset>
  <patternset id="needs.sun.b64">
    <exclude name="${ant.package}/taskdefs/Get.java"
             unless="base64.present" />
    <exclude name="${optional.package}/splash/SplashTask.java"
             unless="base64.present" />
  </patternset>

  <!-- depends on external libraries -->
  <patternset id="needs.trax">
    <exclude name="${optional.package}/TraXLiaison*.java"
             unless="trax.present" />
    <exclude name="${optional.package}/junit/XMLResultAggregator.java"
             unless="trax.present" />
    <exclude name="${optional.package}/junit/AggregateTransformer.java"
             unless="trax.present" />
    <exclude name="${optional.package}/sitraka/**" 
             unless="trax.present"/>
    <exclude name="${optional.package}/metamata/MMetrics*" 
             unless="trax.present"/>
  </patternset>
  <patternset id="needs.xalan1">
    <exclude name="${optional.package}/XalanLiaison*.java"
             unless="xalan.present" />
    <exclude name="${optional.package}/junit/Xalan1Executor.java"
             unless="xalan.present" />
  </patternset>
  <patternset id="needs.xalan2">
    <exclude name="${optional.package}/junit/XMLResultAggregator.java"
             unless="xalan2.present" />
    <exclude name="${optional.package}/junit/AggregateTransformer.java"
             unless="xalan2.present" />
    <exclude name="${optional.package}/junit/XalanExecutor.java"
             unless="xalan2.present" />
    <exclude name="${optional.package}/junit/Xalan2Executor.java"
             unless="xalan2.present" />
  </patternset>
  <patternset id="needs.xslp">
    <exclude name="${optional.package}/XslpLiaison*.java" 
             unless="xslp.present" />
  </patternset>
  <patternset id="needs.junit">
    <exclude name="${optional.package}/junit/*.java" unless="junit.present" />
  </patternset>
  <patternset id="needs.jakarta.regexp">
    <exclude name="${regexp.package}/JakartaRegexp*.java"
             unless="jakarta.regexp.present" />
  </patternset>
  <patternset id="needs.jakarta.oro">
    <exclude name="${regexp.package}/JakartaOro*.java" 
             unless="jakarta.oro.present" />
    <exclude name="${optional.package}/perforce/*.java" 
             unless="jakarta.oro.present" />
    <exclude name="${optional.package}/metamata/MAudit*.java" 
             unless="jakarta.oro.present"/>
  </patternset>
  <patternset id="needs.jakarta.bcel">
    <exclude name="${ant.package}/filters/util/JavaClassHelper.java" 
             unless="bcel.present" />
    <exclude name="${util.package}/depend/bcel/*.java"
             unless="bcel.present" />
  </patternset>
  <patternset id="needs.jakarta.log4j">
    <exclude name="${ant.package}/listener/Log4jListener.java"
             unless="log4j.present" />
  </patternset>
  <patternset id="needs.bsf">
    <exclude name="${optional.package}/Script.java" 
             unless="bsf.present" />
  </patternset>
  <patternset id="needs.stylebook">
    <exclude name="${optional.package}/StyleBook.java" 
             unless="stylebook.present" />
  </patternset>
  <patternset id="needs.javamail">
    <exclude name="${ant.package}/taskdefs/email/MimeMailer.java"
             unless="javamail.complete" />
  </patternset>
  <patternset id="needs.icontract">
    <exclude name="${optional.package}/IContract.java"
             unless="icontract.present" />
  </patternset>
  <patternset id="needs.netrexx">
    <exclude name="${optional.package}/NetRexxC.java"
             unless="netrexx.present" />
  </patternset>
  <patternset id="needs.weblogic.ejbc">
    <exclude name="${optional.package}/ejb/Ejbc*.java" 
             unless="ejb.ejbc.present" />
  </patternset>
  <patternset id="needs.weblogic.ddcreator">
    <exclude name="${optional.package}/ejb/DDCreator*.java"
             unless="ejb.DDCreator.present" />
  </patternset>
  <patternset id="needs.weblogic.server">
    <exclude name="${optional.package}/ejb/WLRun.java"
             unless="ejb.wls.present" />
    <exclude name="${optional.package}/ejb/WLStop.java" 
             unless="ejb.wls.present" />
  </patternset>
  <patternset id="needs.netcomponents">
    <exclude name="${optional.package}/net/FTP.java"
             unless="netcomp.present" />
    <exclude name="${optional.package}/net/TelnetTask.java"
             unless="netcomp.present" />
  </patternset>
  <patternset id="needs.starteam">
    <exclude name="${optional.package}/scm/AntStarTeam*.java"
             unless="starteam.present" />
    <exclude name="${optional.package}/starteam/*.java"
             unless="starteam.present" />
  </patternset>
  <patternset id="needs.vaj">
    <exclude name="${optional.package}/ide/VAJ*.java" 
             unless="vaj.present" />
  </patternset>
  <patternset id="needs.antlr">
    <exclude name="${optional.package}/ANTLR*.java" unless="antlr.present" />
  </patternset>
  <patternset id="needs.servletapi">
    <exclude name="${optional.package}/ide/VAJ*Servlet.java"
             unless="servlet.present" />
  </patternset>
  <patternset id="needs.jmf">
    <exclude name="${optional.package}/sound/*.java" unless="jmf.present" />
  </patternset>
  <patternset id="needs.jdepend">
    <exclude name="${optional.package}/jdepend/*" unless="jdepend.present" />
  </patternset>
  <patternset id="onlinetests">
    <exclude name="**/GetTest.java" if="offline" />
  </patternset>
  <patternset id="needs.swing">
    <exclude name="${optional.package}/splash/*.java" unless="swing.present" />
  </patternset>

  <!--
       ===================================================================
         Check to see what optional dependencies are available
       ===================================================================
  -->
  <target name="check_for_optional_packages">
    <available property="jdk1.2+" classname="java.lang.ThreadLocal" />
    <available property="jdk1.3+" classname="java.lang.StrictMath" />
    <available property="jdk1.4+" classname="java.lang.CharSequence" />
    <available property="bsf.present"
               classname="com.ibm.bsf.BSFManager"
               classpathref="classpath" />
    <available property="netrexx.present"
               classname="netrexx.lang.Rexx"
               classpathref="classpath" />
    <available property="trax.present"
               classname="javax.xml.transform.Transformer"
               classpathref="classpath" />
    <available property="xslp.present"
               classname="com.kvisco.xsl.XSLProcessor"
               classpathref="classpath" />
    <available property="xalan.present"
               classname="org.apache.xalan.xslt.XSLTProcessorFactory"
               classpathref="classpath" />
    <available property="xalan2.present"
               classname="org.apache.xalan.transformer.TransformerImpl"
               classpathref="classpath" />
    <available property="ejb.ejbc.present"
               classname="weblogic.ejbc"
               classpathref="classpath" />
    <available property="ejb.DDCreator.present"
               classname="weblogic.ejb.utils.DDCreator"
               classpathref="classpath" />
    <available property="ejb.wls.present"
               classname="weblogic.Server"
               classpathref="classpath" />
    <available property="junit.present"
               classname="junit.framework.TestCase"
               classpathref="classpath" />
    <available property="netcomp.present"
               classname="com.oroinc.net.ftp.FTPClient"
               classpathref="classpath" />
    <available property="starteam.present"
               classname="com.starbase.util.Platform"
               classpathref="classpath" />
    <available property="antlr.present"
               classname="antlr.Tool"
               classpathref="classpath"/>
    <available property="vaj.present"
               classname="com.ibm.ivj.util.base.Workspace"
               classpathref="classpath"/>
    <available property="stylebook.present"
               classname="org.apache.stylebook.Engine"
               classpathref="classpath"/>
    <available property="jakarta.regexp.present"
               classname="org.apache.regexp.RE"
               classpathref="classpath"/>
    <available property="jakarta.oro.present"
               classname="org.apache.oro.text.regex.Perl5Matcher"
               classpathref="classpath" />
    <available property="jmf.present"
               classname="javax.sound.sampled.Clip"
               classpathref="classpath"/>
    <available property="icontract.present"
               classname="com.reliablesystems.iContract.IContracted"
               classpathref="classpath"/>
    <available property="jdepend.present"
               classname="jdepend.framework.JDepend"
               classpathref="classpath"/>
    <available property="log4j.present"
               classname="org.apache.log4j.Category"
               classpathref="classpath"/>
    <!-- this is just a way to check for a TraX implementation -->
    <available property="trax.impl.present"
               resource="META-INF/services/javax.xml.transform.TransformerFactory"
               classpathref="classpath"/>
    <available property="xalan.envcheck"
               classname="org.apache.xalan.xslt.EnvironmentCheck"
               classpathref="classpath" />
    <available property="which.present"
               classname="org.apache.env.Which"
               classpathref="classpath" />

    <available property="servlet.present"
               classname="javax.servlet.Servlet"
               classpathref="classpath"/>

    <available property="xerces.present"
               classname="org.apache.xerces.parsers.SAXParser"
               classpathref="classpath" />
    <available property="bcel.present"
               classname="org.apache.bcel.Constants"
               classpathref="classpath" />
    <available property="sunuue.present"
               classname="sun.misc.UUEncoder"
               classpathref="classpath" />

    <condition property="javamail.complete">
      <and>
        <available classname="javax.activation.DataHandler"
                   classpathref="classpath"/>
        <available classname="javax.mail.Transport"
                   classpathref="classpath"/>
      </and>
    </condition>

    <condition property="some.regexp.support">
      <or>
        <isset property="jdk1.4+" />
        <isset property="jakarta.regexp.present" />
        <isset property="jakarta.oro.present" />
      </or>
    </condition>
    
    <condition property="tests.and.ant.share.classloader">
      <or>
        <equals arg1="${junit.fork}" arg2="true" />
        <equals arg1="${build.sysclasspath}" arg2="only" />
      </or>
    </condition>

    <condition property="sun.tools.present">
      <and>
        <available classname="sun.tools.native2ascii.Main" />
        <available classname="com.sun.tools.javah.Main" />
      </and>
    </condition>

    <available property="base64.present" classname="sun.misc.BASE64Encoder" />

    <property name="build.tests.resolved" location="${build.tests}" />
    <condition property="tests.are.on.system.classpath">
      <or>
        <!-- relative paths in CLASSPATH -->
        <contains string="${java.class.path}"
                  substring="${build.tests}" />
        <!-- absolute paths in CLASSPATH -->
        <contains string="${java.class.path}"
                  substring="${build.tests.resolved}" />
      </or>
    </condition>
    
    <condition property="jasper.present">
      <and>
        <available classname="org.apache.jasper.compiler.Compiler" />
        <available classname="org.apache.jasper.JasperException" />
      </and>
    </condition>
    
    <available property="swing.present"
               classname="javax.swing.ImageIcon"
               classpathref="classpath"/>
  </target>


  <!--
       ===================================================================
         Prepare the build
       ===================================================================
  -->
  <target name="prepare">
    <tstamp>
      <format property="year" pattern="yyyy" />
    </tstamp>
    <filterset id="ant.filters">
      <filter token="VERSION" value="${version}" />
      <filter token="DATE" value="${TODAY}" />
      <filter token="TIME" value="${TSTAMP}" />
    </filterset>
  </target>

  <!--
       ===================================================================
         Build the code
       ===================================================================
  -->
  <target name="build"
          depends="prepare, check_for_optional_packages"
          description="--> compiles the source code">
    <mkdir dir="${build.dir}"/>
    <mkdir dir="${build.classes}"/>
    <mkdir dir="${build.lib}"/>

    <javac srcdir="${java.dir}"
           destdir="${build.classes}"
           debug="${debug}"
           deprecation="${deprecation}"
           optimize="${optimize}" >
      <classpath refid="classpath" />

      <patternset refid="needs.jdk1.2+" />
      <patternset refid="needs.jdk1.4+" />

      <patternset refid="needs.jakarta.regexp" />
      <patternset refid="needs.jakarta.oro" />
      <patternset refid="needs.jakarta.log4j" />
      <patternset refid="needs.sun.uue" />
      <patternset refid="needs.javamail" />
      <patternset refid="needs.icontract" />
      <patternset refid="needs.bsf" />
      <patternset refid="needs.stylebook" />
      <patternset refid="needs.netrexx" />
      <patternset refid="needs.trax" />
      <patternset refid="needs.xslp" />
      <patternset refid="needs.xalan1" />
      <patternset refid="needs.weblogic.ejbc" />
      <patternset refid="needs.weblogic.ddcreator" />
      <patternset refid="needs.weblogic.server" />
      <patternset refid="needs.junit" />
      <patternset refid="needs.netcomponents" />
      <patternset refid="needs.starteam" />
      <patternset refid="needs.antlr" />
      <patternset refid="needs.vaj" />
      <patternset refid="needs.servletapi" />
      <patternset refid="needs.jmf" />
      <patternset refid="needs.xalan2" />
      <patternset refid="needs.jdepend" />
      <patternset refid="needs.sun.tools" />
      <patternset refid="needs.sun.b64" />
      <patternset refid="needs.jakarta.bcel" />
      <patternset refid="needs.swing" />
    </javac>

    <copy todir="${build.classes}">
      <fileset dir="${java.dir}">
        <include name="**/*.properties" />
        <include name="**/*.dtd" />
      </fileset>
    </copy>

    <copy todir="${build.classes}"
          overwrite="true">
      <fileset dir="${java.dir}">
        <include name="**/version.txt" />
        <include name="**/defaultManifest.mf" />
      </fileset>
      <filterset refid="ant.filters"/>
    </copy>

    <copy todir="${build.classes}/${optional.package}/junit/xsl">
       <fileset dir="${etc.dir}">
         <include name="junit-frames.xsl" />
         <include name="junit-noframes.xsl" />
       </fileset>
    </copy>

  </target>

  <!--
       ===================================================================
         Create the Apache Ant jars: ant.jar and optional.jar
       ===================================================================
  -->
  <target name="jars"
          depends="build"
          description="--> creates the Apache Ant jars">

    <copy todir="${build.dir}">
      <fileset dir=".">
        <include name="LICENSE" />
        <include name="LICENSE.crimson" />
      </fileset>
      <mapper type="glob" from="*" to="*.txt" />
    </copy>

    <jar destfile="${build.lib}/${name}.jar"
         basedir="${build.classes}"
         manifest="${manifest}">
      <exclude name="${optional.package}/**" />
      <exclude name="${optional.type.package}/**" />
      <exclude name="${util.package}/depend/**" />
      <exclude name="${util.package}/optional/**" />
      <exclude name="${util.package}/regexp/**" />
      <exclude name="${ant.package}/listener/Log4jListener.class" />
      <exclude name="${ant.package}/taskdefs/email/UUMailer.class" />
      <exclude name="${ant.package}/taskdefs/email/MimeMailer.class" />
      <exclude name="${ant.package}/taskdefs/Get.class" />
      <metainf dir="${build.dir}" includes="LICENSE.txt"/>

      <manifest>
        <section name="${ant.package}">
          <attribute name="Specification-Title"
                     value="Apache Ant" />
          <attribute name="Specification-Version"
                     value="${version}" />
          <attribute name="Specification-Vendor"
                     value="Apache Software Foundation" />
          <attribute name="Implementation-Title"
                     value="org.apache.tools.ant" />
          <attribute name="Implementation-Version"
                     value="${version} ${TODAY}" />
          <attribute name="Implementation-Vendor"
                     value="Apache Software Foundation" />
        </section>
      </manifest>

      <fileset dir="${docs.dir}">
        <include name="images/ant_logo_large.gif" />
      </fileset>
    </jar>

    <jar destfile="${build.lib}/optional.jar"
         basedir="${build.classes}"
         manifest="${manifest}">
      <include name="${optional.package}/**" />
      <include name="${optional.type.package}/**" />
      <include name="${util.package}/depend/**" />
      <include name="${util.package}/optional/**" />
      <include name="${util.package}/regexp/**" />
      <include name="${ant.package}/listener/Log4jListener.class" />
      <include name="${ant.package}/taskdefs/email/UUMailer.class" />
      <include name="${ant.package}/taskdefs/email/MimeMailer.class" />
      <include name="${ant.package}/taskdefs/Get.class" />
      <metainf dir="${build.dir}" includes="LICENSE.txt"/>

      <manifest>
        <section name="${optional.package}">
          <attribute name="Specification-Title"
                     value="Apache Ant Optional Tasks" />
          <attribute name="Specification-Version"
                     value="${version}" />
          <attribute name="Specification-Vendor"
                     value="Apache Software Foundation" />
          <attribute name="Implementation-Title"
                     value="org.apache.tools.ant.taskdefs.optional" />
          <attribute name="Implementation-Version"
                     value="${version} ${TODAY}" />
          <attribute name="Implementation-Vendor"
                     value="Apache Software Foundation" />
        </section>
      </manifest>
    </jar>

  </target>

  <!--
       ===================================================================
         Create the essential distribution that can run Apache Ant
       ===================================================================
  -->
  <target name="dist-lite"
          depends="jars"
          description="--> creates a minimum distribution to run Apache Ant">

    <mkdir dir="${dist.dir}"/>
    <mkdir dir="${dist.bin}"/>
    <mkdir dir="${dist.lib}"/>

    <copy todir="${dist.lib}">
      <fileset dir="${build.lib}"/>
    </copy>

    <copy todir="${dist.bin}">
      <fileset dir="${script.dir}/" />
    </copy>

    <fixcrlf srcdir="${dist.bin}" eol="crlf" includes="*.bat" />
    <fixcrlf srcdir="${dist.bin}" eol="lf">
      <include name="ant" />
      <include name="antRun" />
      <include name="*.pl" />
    </fixcrlf>

    <chmod perm="ugo+rx" dir="${dist.dir}" type="dir" includes="**" 
           failonerror="${chmod.fail}" />
    <chmod perm="ugo+r" dir="${dist.dir}" type="file" includes="**" 
           failonerror="${chmod.fail}" />
    <chmod perm="ugo+x" type="file" failonerror="${chmod.fail}">
       <fileset dir="${dist.bin}">
         <include name="**/ant" />
         <include name="**/antRun" />
         <include name="**/*.pl" />
         <include name="**/*.py" />
       </fileset>
    </chmod>

  </target>

 <!--
       ===================================================================
         Create the complete distribution
       ===================================================================
  -->
  <target name="dist" description="--> creates a complete distribution">
    <antcall inheritAll="false" target="internal_dist">
      <param name="dist.dir" value="${dist.name}" />
    </antcall>
  </target>

  <target name="dist_javadocs" depends="javadocs">
    <mkdir dir="${dist.javadocs}"/>
    <copy todir="${dist.javadocs}" overwrite="true">
      <fileset dir="${build.javadocs}"/>
    </copy>
  </target>


  <target name="internal_dist" depends="dist-lite,dist_javadocs">
    <mkdir dir="${dist.docs}"/>
    <mkdir dir="${dist.etc}"/>

    <copy todir="${dist.lib}">
      <fileset dir="${lib.dir}">
        <include name="*.jar" />
        <include name="*.zip" />
      </fileset>
    </copy>

    <copy todir="${dist.lib}" file="${lib.dir}/README"/>

    <copy todir="${dist.docs}">
      <fileset dir="${docs.dir}">
        <exclude name="**/images/**"/>
      </fileset>
      <filterset refid="ant.filters"/>
    </copy>

    <copy todir="${dist.docs}" filtering="false">
      <fileset dir="${docs.dir}">
        <include name="**/images/**"/>
      </fileset>
    </copy>

    <copy todir="${dist.dir}">
      <fileset dir=".">
        <include name="README"/>
        <include name="LICENSE"/>
        <include name="LICENSE.crimson"/>
        <include name="TODO"/>
        <include name="WHATSNEW"/>
        <include name="KEYS"/>
      </fileset>
    </copy>

    <chmod perm="ugo+rx" dir="${dist.dir}" type="dir" includes="**" 
           failonerror="${chmod.fail}" />
    <chmod perm="ugo+r" dir="${dist.dir}" type="file" includes="**" 
           failonerror="${chmod.fail}" />
    <chmod perm="ugo+x" type="file" failonerror="${chmod.fail}">
       <fileset dir="${dist.bin}">
         <include name="**/ant" />
         <include name="**/antRun" />
         <include name="**/*.pl" />
         <include name="**/*.py" />
       </fileset>
    </chmod>

    <!-- publish some useful stylesheets -->
    <copy todir="${dist.etc}">
        <fileset dir="${etc.dir}">
            <include name="junit-frames.xsl"/>
            <include name="junit-noframes.xsl"/>
            <include name="coverage-frames.xsl"/>
            <include name="maudit-frames.xsl"/>
            <include name="mmetrics-frames.xsl"/>
            <include name="jdepend.xsl"/>
            <include name="jdepend-frames.xsl"/>
            <include name="checkstyle-frames.xsl"/>
            <include name="log.xsl"/>
        </fileset>
    </copy>

  </target>


  <!--
       ===================================================================
         Target to create bootstrap build
       ===================================================================
  -->
  <target name="bootstrap" description="--> creates a bootstrap build">
    <antcall inheritAll="false" target="dist-lite">
      <param name="dist.dir" value="${bootstrap.dir}" />
    </antcall>
  </target>


  <!--
       ===================================================================
         Create the source distribution
       ===================================================================
  -->
  <target name="src-dist"
          description="--> creates a source distribution">

    <mkdir dir="${src.dist.dir}" />

    <copy todir="${src.dist.lib}">
      <fileset dir="${lib.dir}">
        <include name="*.jar" />
        <include name="*.zip" />
        <include name="README"/>
      </fileset>
    </copy>

    <copy todir="${src.dist.src}">
      <fileset dir="${src.dir}"/>
    </copy>

    <copy todir="${src.dist.docs}">
      <fileset dir="${docs.dir}">
        <exclude name="manual/api/**"/>
      </fileset>
    </copy>

    <copy todir="${src.dist.dir}">
      <fileset dir=".">
        <include name="README"/>
        <include name="LICENSE"/>
        <include name="LICENSE.crimson"/>
        <include name="TODO"/>
        <include name="WHATSNEW"/>
        <include name="KEYS"/>
        <include name="build.bat"/>
        <include name="build.sh"/>
        <include name="bootstrap.bat"/>
        <include name="bootstrap.sh"/>
        <include name="build.xml"/>
      </fileset>
    </copy>

    <fixcrlf srcdir="${src.dist.dir}" eol="crlf" includes="*.bat" />
    <fixcrlf srcdir="${src.dist.dir}" eol="lf">
      <include name="**/*.sh" />
      <include name="**/*.pl" />
      <include name="**/ant" />
      <include name="**/antRun" />
    </fixcrlf>
    <fixcrlf srcdir="${src.dist.dir}">
      <include name="**/*.java" />
    </fixcrlf>

    <chmod perm="ugo+x" dir="${src.dist.dir}" type="dir"
           failonerror="${chmod.fail}" />
    <chmod perm="ugo+r" dir="${src.dist.dir}" failonerror="${chmod.fail}" />
    <chmod perm="ugo+x" failonerror="${chmod.fail}">
       <fileset dir="${src.dist.dir}">
         <include name="**/.sh" />
         <include name="**/.pl" />
         <include name="**/.py" />
         <include name="**/ant" />
         <include name="**/antRun" />
       </fileset>
    </chmod>

  </target>

  <!--
       ===================================================================
         Create the binary distribution
       ===================================================================
  -->
  <target name="main_distribution"
          description="--> creates the zip and tar distributions">
    <delete dir="${dist.name}" />
    <mkdir dir="${dist.base}"/>
    <mkdir dir="${dist.base}/src"/>
    <mkdir dir="${dist.base}/bin"/>

    <antcall inheritAll="false" target="internal_dist">
      <param name="dist.dir" value="${dist.name}" />
    </antcall>
    <zip destfile="${dist.base}/bin/${dist.name}-bin.zip"
         basedir="${dist.name}/.."
         includes="${dist.name}/**"/>
    <tar longfile="gnu"
         destfile="${dist.base}/bin/${dist.name}-bin.tar">
      <tarfileset dir="${dist.name}/.." mode="755" username="ant" group="ant">
        <include name="${dist.name}/bin/ant"/>
        <include name="${dist.name}/bin/antRun"/>
        <include name="${dist.name}/bin/*.pl"/>
        <include name="${dist.name}/bin/*.py"/>
      </tarfileset>
      <tarfileset dir="${dist.name}/.." username="ant" group="ant">
        <include name="${dist.name}/**"/>
        <exclude name="${dist.name}/bin/ant"/>
        <exclude name="${dist.name}/bin/antRun"/>
        <include name="${dist.name}/bin/*.pl"/>
        <include name="${dist.name}/bin/*.py"/>
      </tarfileset>
    </tar>
    <gzip zipfile="${dist.base}/bin/${dist.name}-bin.tar.gz"
          src="${dist.base}/bin/${dist.name}-bin.tar"/>
    <bzip2 zipfile="${dist.base}/bin/${dist.name}-bin.tar.bz2"
           src="${dist.base}/bin/${dist.name}-bin.tar"/>
    <delete file="${dist.base}/bin/${dist.name}-bin.tar"/>
    <delete dir="${dist.name}" />
    <checksum fileext=".md5">
      <fileset dir="${dist.base}/bin/" />
    </checksum>

    <antcall inheritAll="false" target="src-dist">
      <param name="src.dist.dir" value="${dist.name}" />
    </antcall>
    <zip destfile="${dist.base}/src/${dist.name}-src.zip"
         basedir="${dist.name}/.."
         includes="${dist.name}/**"/>
    <tar longfile="gnu"
         destfile="${dist.base}/src/${dist.name}-src.tar" >
      <tarfileset dir="${dist.name}/.." mode="755" username="ant" group="ant">
        <include name="${dist.name}/bootstrap.sh"/>
        <include name="${dist.name}/build.sh"/>
      </tarfileset>
      <tarfileset dir="${dist.name}/.." username="ant" group="ant">
        <include name="${dist.name}/**"/>
        <exclude name="${dist.name}/bootstrap.sh"/>
        <exclude name="${dist.name}/build.sh"/>
      </tarfileset>
    </tar>
    <gzip zipfile="${dist.base}/src/${dist.name}-src.tar.gz"
          src="${dist.base}/src/${dist.name}-src.tar"/>
    <bzip2 zipfile="${dist.base}/src/${dist.name}-src.tar.bz2"
           src="${dist.base}/src/${dist.name}-src.tar"/>
    <delete file="${dist.base}/src/${dist.name}-src.tar"/>
    <delete dir="${dist.name}" />
    <checksum fileext=".md5">
      <fileset dir="${dist.base}/src/" />
    </checksum>
  </target>

  <target name="rpm_check">
    <available property="rpm.present"
               file="/bin/rpm"/>
  </target>

  <target name="rpm" description="Build the RPM files for ant"
          depends="prepare, rpm_check"
          if="rpm.present">
    <tstamp>
      <format property="rpmyear" pattern="yyyyMMdd"/>
      <format property="nightlybuild.dir" pattern="yyyy-MM-dd"/>
    </tstamp>
    <property name="rpm.release" value="cvs${rpmyear}"/>
    <property name="rpm.source" value="nightly/${nightlybuild.dir}/"/>

    <mkdir dir="build/rpm/SPECS"/>
    <mkdir dir="build/rpm/SOURCES"/>
    <mkdir dir="build/rpm/BUILD"/>
    <mkdir dir="build/rpm/RPMS"/>
    <mkdir dir="build/rpm/SRPMS"/>

    <property name="disttar" location="${dist.base}/bin/${dist.name}-bin.tar.gz"/>
    <copy file="src/etc/ant.spec" tofile="build/rpm/SPECS/ant.spec">
      <filterset refid="ant.filters"/>
      <filterset>
        <filter token="RPM_RELEASE" value="${rpm.release}"/>
        <filter token="RPM_SOURCE" value="${rpm.source}"/>
        <filter token="DIST_TAR" value="${disttar}"/>
      </filterset>
    </copy>
    <copy file="src/etc/antsrc.spec" tofile="build/rpm/SPECS/antsrc.spec">
      <filterset refid="ant.filters"/>
      <filterset>
        <filter token="RPM_RELEASE" value="${rpm.release}"/>
        <filter token="RPM_SOURCE" value="${rpm.source}"/>
      </filterset>
    </copy>
    <rpm topDir="build/rpm"
         specfile="ant.spec"
         command="-bb"/>

    <copy file="distribution/src/${dist.name}-src.tar.gz" todir="build/rpm/SOURCES"/>
    <rpm topDir="build/rpm"
         specfile="antsrc.spec"
         command="-bs"/>

    <mkdir dir="${dist.base}/rpms"/>
    <copy todir="${dist.base}/rpms">
      <fileset dir="build/rpm/RPMS/noarch"/>
    </copy>
    <copy todir="${dist.base}/rpms">
      <fileset dir="build/rpm/SRPMS"/>
    </copy>
  </target>

  <target name="distribution" depends="main_distribution, rpm">
  </target>


  <!--
       ===================================================================
         Cleans up build and distribution directories
       ===================================================================
  -->
  <target name="clean"
          description="--> cleans up build and dist directories">
    <delete dir="${build.dir}" />
    <delete dir="${dist.base}" />
    <delete dir="${dist.dir}" />
    <delete>
      <fileset dir="." includes="**/*~" defaultexcludes="no"/>
    </delete>
  </target>

  <!--
       ===================================================================
         Cleans everything
       ===================================================================
  -->
  <target name="allclean"
          depends="clean"
          description="--> cleans up everything">
    <delete file="${bootstrap.dir}/bin/antRun" />
    <delete file="${bootstrap.dir}/bin/antRun.bat" />
    <delete file="${bootstrap.dir}/bin/*.pl" />
    <delete file="${bootstrap.dir}/bin/*.py" />
  </target>

  <!--
       ===================================================================
         Installs Apache Ant
       ===================================================================
  -->
  <target name="install" if="ant.install">
    <antcall inheritAll="false" target="internal_dist">
      <param name="dist.dir" value="${ant.install}" />
    </antcall>
  </target>

  <target name="install-lite" if="ant.install">
    <antcall inheritAll="false" target="dist-lite">
      <param name="dist.dir" value="${ant.install}" />
    </antcall>
  </target>

  <!--
       ===================================================================
         Creates the API documentation
       ===================================================================
  -->
  <target name="javadoc_check">
    <uptodate property="javadoc.notrequired"
              targetfile="${build.javadocs}/packages.html" >
        <srcfiles dir= "${java.dir}" includes="**/*.java"/>
    </uptodate>
  </target>

  <target name="javadocs" depends="prepare, javadoc_check"
          unless="javadoc.notrequired"
          description="--> creates the API documentation">
    <mkdir dir="${build.javadocs}"/>
    <javadoc packagenames="org.apache.*"
             useexternalfile="yes"
             sourcepath="${java.dir}"
             destdir="${build.javadocs}"
             author="true"
             version="true"
             windowtitle="${Name} API"
             doctitle="${Name}">
      <tag name="todo" description="To do:" scope="all" />
      <tag name="ant.task" enabled="false" description="Task:" scope="types" />
      <group title="Apache Ant Core" packages="org.apache.tools.ant*" />
      <group title="Core Tasks" packages="org.apache.tools.ant.taskdefs*" />
      <group title="Optional Tasks" packages="org.apache.tools.ant.taskdefs.optional*" />

      <bottom>Copyright &#169; 2000-${year} Apache Software Foundation. All Rights Reserved.</bottom>
    </javadoc>
  </target>

  <!--
       ===================================================================
         Compile testcases
       ===================================================================
  -->
  <target name="compile-tests" depends="build" if="junit.present">
    <mkdir dir="${build.tests}"/>

    <javac srcdir="${tests.dir}"
           destdir="${build.tests}"
           debug="${debug}"
           deprecation="${deprecation}" >
      <classpath refid="tests-classpath" />

      <patternset refid="needs.antlr" />

      <patternset refid="needs.jdk1.2+" />
      <patternset refid="needs.jdk1.3+" />
      <patternset refid="needs.jdk1.4+" />

      <patternset refid="needs.jakarta.regexp" />
      <patternset refid="needs.jakarta.oro" />

      <patternset refid="needs.trax" />
      <patternset refid="needs.xslp" />
      <patternset refid="needs.xalan1" />
    </javac>
  </target>

  <target name="dump-info" depends="dump-sys-properties,run-which" />

  <target name="dump-sys-properties" unless="which.present" 
          depends="xml-check">
    <echo message="java.vm.info=${java.vm.info}" />
    <echo message="java.vm.name=${java.vm.name}" />
    <echo message="java.vm.vendor=${java.vm.vendor}" />
    <echo message="java.vm.version=${java.vm.version}" />
    <echo message="os.arch=${os.arch}" />
    <echo message="os.name=${os.name}" />
    <echo message="os.version=${os.version}" />
    <echo message="file.encoding=${file.encoding}" />
    <echo message="user.language=${user.language}" />
  </target>

  <!-- helper class from Xalan2 to check for jar versioning of xml/xsl processors -->
  <target name="xml-check" depends="check_for_optional_packages" 
          if="xalan.envcheck" unless="which.present">
      <java classname="org.apache.xalan.xslt.EnvironmentCheck"/>
  </target>

  <target name="run-which" depends="check_for_optional_packages"
          if="which.present">
      <java classname="org.apache.env.Which" taskname="which"/>
  </target>

  <!-- test to see if we are online or not. can take a while when we are off line, so
    setting the property is a good shortcut-->
  <target name="probe-offline">
      <condition property="offline">
      <or>
        <isset property="offline"/>
        <not>
          <http  url="http://www.apache.org/"/>
        </not>
      </or>
    </condition>
    <echo level="verbose" > offline=${offline}</echo>
  </target>
  
  <!--
       ===================================================================
         Run testcase
       ===================================================================
  -->
  <target name="test" depends="run-tests" description="--> run JUnit tests"/>

  <target name="run-tests" depends="dump-info,compile-tests,probe-offline" if="junit.present">

    <junit printsummary="${junit.summary}" haltonfailure="yes" 
           filtertrace="${junit.filtertrace}"
           fork="${junit.fork}">
<!--      <jvmarg value="-classic"/> -->
      <classpath refid="tests-classpath"/>
      <classpath refid="classes.zip" />

      <sysproperty key="ant.home" value="${ant.home}" />
      <sysproperty key="build.tests" value="${build.tests}"/>
      <sysproperty key="tests-classpath.value" 
                   value="${tests-classpath.value}" />

      <formatter type="brief" usefile="false" />

      <batchtest>
        <fileset dir="${tests.dir}">
          <include name="**/*Test*" />

          <!-- abstract classes, not testcases -->
          <exclude name="${ant.package}/taskdefs/TaskdefsTest.java" />
          <exclude name="${ant.package}/BuildFileTest.java" />
          <exclude name="${regexp.package}/RegexpMatcherTest.java" />
          <exclude name="${regexp.package}/RegexpTest.java" />
          <exclude name="${optional.package}/AbstractXSLTLiaisonTest.java" />
          
          <!-- helper classes, not testcases -->
          <exclude name="org/example/**" />
          <exclude name="${ant.package}/taskdefs/TaskdefTest*Task.java" />

          <!-- interactive test -->
          <exclude name="${ant.package}/taskdefs/TestProcess.java" />

          <!-- only run these tests if their required libraries are
               installed -->
          <patternset refid="needs.jdk1.2+" />
          <patternset refid="needs.jdk1.4+" />
          <patternset refid="needs.jakarta.regexp" />
          <patternset refid="needs.jakarta.oro" />
          <patternset refid="needs.vaj" />
          <patternset refid="needs.antlr" />
          <patternset refid="needs.xalan1" />
          <patternset refid="needs.xslp" />

          <!-- tests excluded if the test is run in offline mode -->
          <patternset refid="onlinetests"/> 

          <!-- runtime dependencies that are different from compile
               time dependencies -->
          <exclude name="${optional.package}/ReplaceRegExpTest.java"
                   unless="some.regexp.support" />
          <exclude name="${optional.package}/sitraka/*.java"
                   unless="some.regexp.support" />

          <!-- fail if testcases can be loaded from the system classloader -->
          <exclude name="${optional.package}/junit/JUnitClassLoaderTest.java"
                   if="tests.are.on.system.classpath"/>
          <exclude name="${optional.package}/sitraka/XMLReportTest.java"
                   if="tests.are.on.system.classpath"/>

          <!-- these tests need to be localised before being ran???? -->
          <exclude name="${optional.package}/PvcsTest.java" />

          <!-- ehm, this is not really a TraX test but rather a xalan2 test..-->
          <exclude name="${optional.package}/TraXLiaisonTest.java"
                   unless="xalan2.present"/>

          <!-- needs BSF to work -->
          <exclude name="${optional.package}/XalanLiaisonTest.java" 
                   unless="bsf.present" />

          <!--
          XXX need to figure out what's causing this InvocationTargetException
          -->
          <exclude name="${optional.package}/junit/JUnitTestRunnerTest.java"
                   unless="jdk1.2+" />
          <!-- DateTime handling seems to be broken in JDK 1.1 -->
          <exclude name="${util.package}/DateUtilsTest.java"
                   unless="jdk1.2+" />

          <exclude name="${optional.package}/JspcTest.java"
                   unless="jasper.present" />
                   
          <!--  These tests only passes if testcases and Ant classes have
          been loaded by the same classloader - will throw
          IllegalAccessExceptions otherwise.  -->
          <exclude name="${ant.package}/taskdefs/SQLExecTest.java"
                   unless="tests.and.ant.share.classloader" />
          <exclude name="${optional.package}/sos/SOSTest.java"
                   unless="tests.and.ant.share.classloader" />
          <exclude name="${optional.package}/TraXLiaisonTest.java"
                   unless="tests.and.ant.share.classloader" />
          <exclude name="${optional.package}/metamata/MAuditParserTest.java"
                   unless="tests.and.ant.share.classloader" />

          <!-- failure of this test case kills the current JVM
          so until the defect is actually fixed it is taken
          out of the test list -->
          <exclude name="${ant.package}/taskdefs/JavaTest.java" />
        </fileset>
      </batchtest>

    </junit>
  </target>

  <target name="run-single-test" if="testcase" depends="compile-tests"
    description="--> runs the single unit test defined in the testcase property">


    <junit printsummary="${junit.summary}"
          haltonfailure="yes" 
          fork="${junit.fork}"
          filtertrace="${junit.filtertrace}">
<!--      <jvmarg value="-classic"/> -->
      <sysproperty key="ant.home" value="${ant.home}" />
      <sysproperty key="build.tests" value="${build.tests}"/>
      <sysproperty key="tests-classpath.value" 
                   value="${tests-classpath.value}" />
      <classpath refid="classes.zip" />
      <classpath refid="tests-classpath"/>
      <formatter type="plain" usefile="false" />
      <test name="${testcase}" />
    </junit>
  </target>

  <target name="interactive-tests" description="--> runs interactive tests"
          depends="compile-tests"
          if="jdk1.3+">
    <java classpathref="tests-classpath"
          classname="org.apache.tools.ant.taskdefs.TestProcess" 
          fork="true" />
  </target>
  
  <!--
       ===================================================================
         Main target - runs dist-lite by default
       ===================================================================
  -->
  <target name="main"
          description="--> creates a minimum distribution in ./dist"
          depends="dist-lite" />

</project>
