<?xml version="1.0"?>

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

<project name="Ant" default="runtests" basedir=".">

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

  <property name="Name" value="Ant"/>
  <property name="name" value="ant"/>
  <property name="version" value="1.2"/>

  <taskdef name="foreach"
           classname="com.arsdigita.build.ForeachFileAntTask">
  </taskdef>

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

  <property name="build.compiler" value="classic"/>
  <property name="build.compiler.emacs" value="on"/>

  <target name="check_for_optional_packages">
    <available property="jdk1.2+" classname="java.lang.ThreadLocal" />
    <available property="jdk1.3+" classname="java.lang.StrictMath" />
    <available property="junit.present" classname="junit.framework.TestCase" />
  </target>

  <!-- =================================================================== -->
  <!-- Compiles the source code                                            -->
  <!-- =================================================================== -->
  <target name="compile" depends="check_for_optional_packages">
    <javac srcdir="."
           debug="on"
           deprecation="off"
           optimize="on" >

      <classpath refid="classpath" />

      <exclude name="**/EjbJar.java" unless="jdk1.2+" />
      <exclude name="**/*DeploymentTool.java" unless="jdk1.2+" />
      <exclude name="**/junit/*" unless="junit.present" />
    </javac>
 
    <filter token="DATE" value="${TODAY}" />
    <filter token="TIME" value="${TSTAMP}" />
  </target>

  <!-- =================================================================== -->
  <!-- Run testcase                                                        -->
  <!-- =================================================================== -->
  <target name="runtests" depends="compile" if="junit.present">
    <antcall target="runsubtests">
      <param name="package.srcdir" value="acs-kernel"/>
    </antcall>
    <foreach target="runsubtests"
             varname="package.srcdir"
             filterregexp="([^/]*)/java/src"
             dir=".">
      <include name="**/java/src"/>
      <exclude name="**/acs-kernel/java/src"/>
    </foreach>
  </target>

  <target name="runsubtests">
    <echo message="Running subtests in package ${package.srcdir}"/>
    <junit printsummary="no"
           haltonfailure="no"
           fork="yes"
           dir="${package.srcdir}/java/src">
      <jvmarg value="-Dserver.url=http://64.64.107.58" />
      <jvmarg value="-Dserver.username=testuser@testusers.org" />
      <jvmarg value="-Dserver.password=testuser" />
      <jvmarg value="-Dserver.adminUsername=pmcneill@arsdigita.com" />
      <jvmarg value="-Dserver.adminPassword=shadows" />

      <classpath refid="classpath" />

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

      <batchtest>
        <fileset dir="${package.srcdir}/java/src">
          <include name="**/*Test*.class" />
        </fileset>
      </batchtest>
    </junit>
  </target>
  

  <target name="run.single.test" if="testcase" depends="compile">
    <junit printsummary="no" haltonfailure="yes">
      <classpath>
        <path refid="classpath" />
        <pathelement path="${java.class.path}" />
      </classpath>

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

      <test name="${testcase}" />
    </junit>
  </target>

</project>