<project default="ant1compat" name="Ant1Compat" basedir="..">

  <property name="src.dir" value="src"/>
  <property name="lib.dir" value="lib"/>
  <property name="java.dir" value="${src.dir}/java"/>

  <property name="bin.dir" value="bin"/>
  <property name="dist.dir" value="dist"/>
  <property name="javadocs.dir" value="${dist.dir}/javadocs"/>
  <property name="distlib.dir" value="${dist.dir}/lib"/>
  
  <property name="debug" value="true"/>

  <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"/>

  <patternset id="deprecated">
    <exclude name="org/apache/tools/ant/taskdefs/Copydir.java"/>
    <exclude name="org/apache/tools/ant/taskdefs/Copyfile.java"/>
  </patternset>
  
  <patternset id="toohard">
    <exclude name="org/apache/tools/ant/taskdefs/AntStructure.java"/>
    <exclude name="org/apache/tools/ant/taskdefs/Recorder.java"/>
    <exclude name="org/apache/tools/ant/taskdefs/RecorderEntry.java"/>
    <exclude name="org/apache/tools/ant/taskdefs/optional/jdepend/*.java"/>
  </patternset>
  
  <patternset id="converted">
    <exclude name="org/apache/tools/ant/taskdefs/Ant.java"/>
    <exclude name="org/apache/tools/ant/taskdefs/CallTarget.java"/>
  </patternset>

  <fileset id="ant1src" dir="../../src/main">
    <include name="**/*.properties"/>
    <include name="**/*.mf"/>
    <include name="org/apache/tools/ant/taskdefs/**/*.java"/>
    <include name="org/apache/tools/ant/types/**/*.java"/>
    <include name="org/apache/tools/ant/filters/**/*.java"/>
    <exclude name="org/apache/tools/ant/types/DataType.java"/>
    <include name="org/apache/tools/ant/util/**/*.java"/>
    <include name="org/apache/tools/zip/**/*.java"/>
    <include name="org/apache/tools/bzip2/**/*.java"/>
    <include name="org/apache/tools/mail/**/*.java"/>
    <include name="org/apache/tools/tar/**/*.java"/>
    <include name="org/apache/tools/ant/BuildException.java"/>
    <include name="org/apache/tools/ant/ExitException.java"/>
    <include name="org/apache/tools/ant/DirectoryScanner.java"/>
    <include name="org/apache/tools/ant/PathTokenizer.java"/>
    <include name="org/apache/tools/ant/FileScanner.java"/>
    <include name="org/apache/tools/ant/TaskAdapter.java"/>
    <include name="org/apache/tools/ant/MatchingTask.java"/>
    <include name="org/apache/tools/ant/Location.java"/>
    <include name="org/apache/tools/ant/AntClassLoader.java"/>
    <include name="org/apache/tools/ant/BuildEvent.java"/>
    <include name="org/apache/tools/ant/BuildListener.java"/>
    <!-- <patternset refid="deprecated"/> -->
    <patternset refid="toohard"/>
    <patternset refid="converted"/>
  </fileset>

  <path id="classpath">
    <pathelement location="${distlib.dir}/init.jar"/>
    <fileset dir="${lib.dir}/parser" includes="*.jar"/>
    <fileset dir="${lib.dir}/ant1compat" includes="*.jar"/>
    <pathelement location="${distlib.dir}/common/common.jar"/>
    <pathelement location="${distlib.dir}/antlibs/system.jar"/>
  </path>

  <!--
       ===================================================================
         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" />
  </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>

  <!--
       ===================================================================
         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="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" />

  </target>

  <target name="ant1compat" depends="check_for_optional_packages">
    <mkdir dir="${bin.dir}/ant1src"/>
    <mkdir dir="${bin.dir}/ant1compat"/>
    <copy todir="${bin.dir}/ant1src">
      <fileset refid="ant1src"/>
    </copy>
    <depend destdir="${bin.dir}/ant1compat" srcdir="${bin.dir}/ant1src;${java.dir}/antlibs/ant1compat">
      <classpath refid="classpath"/>
    </depend>
    <javac destdir="${bin.dir}/ant1compat" 
           srcdir="${bin.dir}/ant1src:${java.dir}/antlibs/ant1compat"
           debug="${debug}">
      <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" />
     </javac>
    <copy todir="${bin.dir}/ant1compat">
      <fileset dir="${bin.dir}/ant1src" excludes="**/*.java"/>
    </copy>
    <jar basedir="${bin.dir}/ant1compat" jarfile="${distlib.dir}/antlibs/ant1compat.jar">
      <metainf dir="${java.dir}/antlibs/ant1compat" 
                includes="antlib.xml"/>
    </jar>
  </target>
  
  <target name="clean">
    <delete dir="${bin.dir}/ant1src"/>
    <delete dir="${bin.dir}/ant1compat"/>
  </target>

</project>
