<?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="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="testresourcecollection" depends="testsmallset">
    <fail>
      <condition>
        <not>
          <and>
            <resourcecount count="2" refid="result" />
            <resourcecount count="1">
              <intersect>
                <resources refid="result" />
                <file file="${classes.dir}/B.class" />
              </intersect>
            </resourcecount>
            <resourcecount count="1">
              <intersect>
                <resources refid="result" />
                <file file="${classes.dir}/C.class" />
              </intersect>
            </resourcecount>
          </and>
        </not>
      </condition>
    </fail>
  </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="testmethodparam" depends="src1setup, compile">
    <classfileset id="result" dir="${classes.dir}" rootclass="E"/>
  </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="testmethodparaminner" depends="src4setup, compile">
    <classfileset id="result" dir="${classes.dir}" rootclass="test.MethodParam"/>
  </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>
