<?xml version="1.0"?>

<project name="depend" basedir="." default="help">
  <property name="src1.dir" value="src1"/>
  <property name="src2.dir" value="src2"/>
  <property name="src3.dir" value="src3"/>
  <property name="src4.dir" value="src4"/>
  <property name="src5.dir" value="src5"/>
  
  <property name="tempsrc.dir" value="working"/>
  <property name="cache.dir" value="working"/>
  <property name="classes.dir" value="classes"/>
  <target name="help">
    <echo>This buildfile is used as part of Ant's test suite.</echo>
  </target>

  <target name="basesetup" depends="clean">
    <mkdir dir="${tempsrc.dir}"/>
  </target>
  
  <target name="src1setup" depends="basesetup">
    <copy todir="${tempsrc.dir}">
      <fileset dir="${src1.dir}"/>
    </copy>
  </target>
  
  <target name="src2setup" depends="basesetup">
    <copy todir="${tempsrc.dir}">
      <fileset dir="${src2.dir}"/>
    </copy>
  </target>

  <target name="src3setup" depends="basesetup">
    <copy todir="${tempsrc.dir}">
      <fileset dir="${src3.dir}"/>
    </copy>
  </target>

  <target name="src4setup" depends="basesetup">
    <copy todir="${tempsrc.dir}">
      <fileset dir="${src4.dir}"/>
    </copy>
  </target>

  <target name="src5setup" depends="basesetup">
    <copy todir="${tempsrc.dir}">
      <fileset dir="${src5.dir}"/>
    </copy>
  </target>

  <target name="compile">
    <mkdir dir="${classes.dir}"/>
    <javac srcdir="${tempsrc.dir}" destdir="${classes.dir}"/>
  </target>
  
  <target name="clean">
    <delete dir="${classes.dir}"/>
    <delete dir="${tempsrc.dir}"/>
  </target>

  <target name="testdirect" depends="src1setup, compile">
    <sleep seconds="3"/>
    <delete file="${tempsrc.dir}/C.java"/>
    <copy file="${src1.dir}/C.java" tofile="${tempsrc.dir}/C.java"/>
    <depend srcdir="${tempsrc.dir}" destdir="${classes.dir}"/>
    <fileset id="result" dir="${classes.dir}"/>
  </target>

  <target name="testclosure" depends="src1setup, compile">
    <sleep seconds="3"/>
    <delete file="${tempsrc.dir}/C.java"/>
    <copy file="${src1.dir}/C.java" tofile="${tempsrc.dir}/C.java"/>
    <depend srcdir="${tempsrc.dir}" destdir="${classes.dir}" closure="yes"/>
    <fileset id="result" dir="${classes.dir}"/>
  </target>

  <target name="testbasicset" depends="src1setup, compile">
    <classfileset id="result" dir="${classes.dir}" rootclass="A"/>
  </target>

  <target name="testsmallset" depends="src1setup, compile">
    <classfileset id="result" dir="${classes.dir}" rootclass="B"/>
  </target>

  <target name="testcomboset" depends="src1setup, compile">
    <classfileset id="result" dir="${classes.dir}" rootclass="B">
      <include name="**/C.class"/>
    </classfileset>
  </target>
  
  <target name="testbyreference" depends="src1setup, compile">
    <classfileset id="classSet" dir="${classes.dir}" rootclass="A">
      <include name="**/C.class"/>
    </classfileset>
    <jar destfile="${tempsrc.dir}/test.jar">
      <fileset refid="classSet"/>
    </jar>
  </target>
  
  <target name="testinner" depends="src2setup, compile">
    <sleep seconds="3"/>
    <delete file="${tempsrc.dir}/B.java"/>
    <copy file="${src2.dir}/B.java" tofile="${tempsrc.dir}/B.java"/>
    <depend srcdir="${tempsrc.dir}" destdir="${classes.dir}" closure="yes"/>
    <fileset id="result" dir="${classes.dir}"/>
  </target>

  <target name="testinnerinner" depends="src3setup, compile">
    <sleep seconds="3"/>
    <delete file="${tempsrc.dir}/B.java"/>
    <copy file="${src3.dir}/B.java" tofile="${tempsrc.dir}/B.java"/>
    <depend srcdir="${tempsrc.dir}" destdir="${classes.dir}" closure="yes"/>
    <fileset id="result" dir="${classes.dir}"/>
  </target>
  
  <target name="testnosource" depends="src1setup, compile">
    <depend destdir="${classes.dir}" closure="yes"/>
  </target>

  <target name="testemptysource" depends="src1setup, compile">
    <depend srcdir="" destdir="${classes.dir}" closure="yes"/>
  </target>

  <target name="testinnerclosure" depends="src4setup">
    <mkdir dir="${classes.dir}"/>
    <path id="path.compile">
        <pathelement location="${classes.dir}"/>
    </path>

    <javac srcdir="${tempsrc.dir}" destdir="${classes.dir}"
           classpathref="path.compile"/>
    
    <sleep seconds="3"/>
    <depend srcdir="${tempsrc.dir}" destdir="${classes.dir}" 
            closure="yes" dump="yes"
            classpathref="path.compile"/>
           
    <fileset id="result" dir="${classes.dir}"/>
  </target>
  
  <target name="testcache" depends="src1setup, compile">
    <depend cache="${cache.dir}" srcdir="${tempsrc.dir}" 
            destdir="${classes.dir}" closure="yes"/>
    <depend cache="${cache.dir}" srcdir="${tempsrc.dir}" 
            destdir="${classes.dir}" closure="yes"/>
  </target>

  <target name="testnonpublic" depends="src5setup, compile">
    <sleep seconds="3"/>
    <delete file="${tempsrc.dir}/B.java"/>
    <copy file="${src2.dir}/B.java" tofile="${tempsrc.dir}/B.java"/>
    <depend srcdir="${tempsrc.dir}" destdir="${classes.dir}" closure="yes"/>
    <fileset id="result" dir="${classes.dir}"/>
  </target>
</project>
