<!-- $Id: build.xml,v 12.4 2008/02/08 22:10:16 mark Exp $ -->
<project name="clover" default="build" basedir=".">

  <property name="db" location="../../.."/>
  <property name="src" location="${db}/java/src"/>
  <property name="test.src" location="${db}/test/scr024/src"/>
  <property name="examples.src" location="${db}/examples_java/src"/>
  <property name="testserialdir" value="testserial"/>
  <property name="clover.initstring" location="reports/clover.db"/>
  <property name="clover.excludes" value="**/test/** collections/** db/** com/sleepycat/db/**"/>
  <!--
  <property name="build.compiler"
            value="org.apache.tools.ant.taskdefs.CloverCompilerAdapter"/>
  -->

  <target name="all" depends="clean,test,report"/>

  <target name="clean">
    <delete dir="classes"/>
    <delete dir="tmp"/>
    <delete dir="reports"/>
  </target>

  <target name="init">
    <mkdir dir="classes"/>
    <mkdir dir="tmp"/>
    <mkdir dir="reports"/>
  </target>

  <path id="clover.classpath">
    <pathelement location="clover.jar"/>
    <pathelement location="velocity.jar"/>
  </path>

  <path id="classpath">
    <pathelement location="classes"/>
    <path refid="clover.classpath"/>
  </path>

  <target name="build" depends="init">
    <javac destdir="classes" debug="on" source="1.5" target="1.5">
      <src path="${src}"/>
      <src path="${test.src}"/>
      <src path="${examples.src}"/>
      <exclude name="com/sleepycat/**/release/**"/>
      <exclude name="com/sleepycat/xa/**"/>
    </javac>
    <!-- Compile original version of TestSerial.java.original. -->
    <property name="testserialpath"
              value="com/sleepycat/collections/test/serial/TestSerial"/>
    <copy file="${test.src}/${testserialpath}.java.original"
          tofile="${testserialdir}/${testserialpath}.java"/>
    <javac destdir="${testserialdir}" debug="on" source="1.5" target="1.5"
           includeAntRuntime="true" srcdir="${testserialdir}">
      <include name="${testserialpath}.java"/>
    </javac>
    <!-- Compile original version of EvolveClasses. -->
    <copy file=
      "${test.src}/com/sleepycat/persist/test/EvolveClasses.java.original"
          tofile=
      "testevolvedir/com/sleepycat/persist/test/EvolveClasses.java"/>
    <copy file=
      "${test.src}/com/sleepycat/persist/test/EvolveCase.java"
          tofile=
      "testevolvedir/com/sleepycat/persist/test/EvolveCase.java"/>
    <copy file=
      "${test.src}/com/sleepycat/persist/test/PersistTestUtils.java"
          tofile=
      "testevolvedir/com/sleepycat/persist/test/PersistTestUtils.java"/>
    <javac debug="on" source="1.5" target="1.5" classpath="classes">
      <src path="testevolvedir"/>
    </javac>
  </target>

  <target name="test" depends="build">

    <!-- Determine which tests to run. -->
    <condition property="dotestserial">
      <or>
        <not><isset property="testcase"/></not>
        <equals arg1="${testcase}" arg2=
         "com.sleepycat.collections.test.serial.StoredClassCatalogTest"/>
      </or>
    </condition>
    <condition property="dotestevolve">
      <or>
        <not><isset property="testcase"/></not>
        <equals arg1="${testcase}"
                arg2="com.sleepycat.persist.test.EvolveTest"/>
      </or>
    </condition>

    <!-- Performs initialization needed before StoredClassCatalogTest. -->
    <junit fork="yes" dir="." printsummary="on" haltonfailure="on"
           showoutput="on">
      <jvmarg value="-ea"/>
      <classpath path="${testserialdir}"/> <!-- Must be first -->
      <classpath refid="classpath"/>
      <sysproperty key="testdestdir" value="./tmp"/>
      <sysproperty key="longtest" value="${longtest}"/>
      <formatter type="plain" usefile="false"/>
      <formatter type="xml"/>
      <test name=
            "com.sleepycat.collections.test.serial.StoredClassCatalogTestInit"
            todir="reports" if="dotestserial"/>
    </junit>

    <!-- Performs initialization needed before persist EvolveTest. -->
    <junit fork="yes" dir="." printsummary="on" haltonfailure="on"
           showoutput="on">
      <jvmarg value="-ea"/>
      <classpath path="testevolvedir"/>
      <classpath refid="classpath"/>
      <sysproperty key="testdestdir" value="./tmp"/>
      <sysproperty key="longtest" value="${longtest}"/>
      <formatter type="plain" usefile="false"/>
      <formatter type="xml"/>
      <test name="com.sleepycat.persist.test.EvolveTestInit"
            todir="reports" if="dotestevolve"/>
    </junit>

    <!-- Performs testcase if set, or batch tests. -->
    <junit fork="yes" dir="." printsummary="on" haltonfailure="on"
           showoutput="on">
      <jvmarg value="-ea"/>
      <classpath refid="classpath"/>
      <sysproperty key="testdestdir" value="./tmp"/>
      <sysproperty key="longtest" value="${longtest}"/>
      <formatter type="plain" usefile="false"/>
      <formatter type="xml"/>
      <test name="${testcase}" todir="reports" if="testcase"/>
      <batchtest todir="reports" unless="testcase">
        <fileset dir="classes" includes="**/*Test.class"/>
      </batchtest>
    </junit>
  </target>

  <target name="testevolve" depends="build">
  </target>

  <target name="examples" depends="build">
    <echo message="=== HelloDatabaseWorld ==="/>
    <java dir="." fork="yes" classpathref="classpath"
         classname="collections.hello.HelloDatabaseWorld"/>
    <echo message=""/>
    <antcall target="one_shipment_example">
      <param name="param_name" value="basic"/>
    </antcall>
    <antcall target="one_shipment_example">
      <param name="param_name" value="index"/>
    </antcall>
    <antcall target="one_shipment_example">
      <param name="param_name" value="entity"/>
    </antcall>
    <antcall target="one_shipment_example">
      <param name="param_name" value="tuple"/>
    </antcall>
    <antcall target="one_shipment_example">
      <param name="param_name" value="sentity"/>
    </antcall>
    <antcall target="one_shipment_example">
      <param name="param_name" value="marshal"/>
    </antcall>
    <antcall target="one_shipment_example">
      <param name="param_name" value="factory"/>
    </antcall>
    <antcall target="one_persist_example">
      <param name="param_name" value="CustomKeyOrderExample"/>
    </antcall>
    <antcall target="one_persist_example">
      <param name="param_name" value="EventExample"/>
    </antcall>
    <antcall target="one_persist_example">
      <param name="param_name" value="EventExampleDPL"/>
    </antcall>
    <antcall target="one_persist_example">
      <param name="param_name" value="PersonExample"/>
    </antcall>
    <antcall target="DplDump">
      <param name="home" value="tmp"/>
      <param name="store" value="PersonStore"/>
    </antcall>
  </target>

  <target name="one_shipment_example">
    <echo message="=== ${param_name} ==="/>
    <delete dir="tmp"/>
    <mkdir dir="tmp"/>
    <java dir="." fork="yes" classpathref="classpath"
     classname="collections.ship.${param_name}.Sample"/>
  </target>

  <target name="one_persist_example">
    <echo message="=== ${param_name} ==="/>
    <delete dir="tmp"/>
    <mkdir dir="tmp"/>
    <java fork="yes" dir="." classname="persist.${param_name}">
      <jvmarg value="-ea"/>
      <arg line="-h tmp"/>
      <classpath refid="classpath"/>
    </java>
  </target>

  <target name="DplDump">
    <echo message="=== DplDump ${home} ${store} ==="/>
    <java fork="yes" dir="." classname="persist.DplDump">
      <jvmarg value="-ea"/>
      <arg line="-h ${home} -s ${store}"/>
      <classpath refid="classpath"/>
    </java>
  </target>

    <!-- Using fork="yes" does not work for AccessExample, apparently because
         it is interactive and the input stream of the forked process isn't
         functional; therefore this sample writes to the base directory.
    -->
  <target name="access_example" depends="build">
    <echo message="=== AccessExample ==="/>
    <java classpathref="classpath"
          classname="collections.access.AccessExample">
    </java>
  </target>

  <target name="report">
    <java classname="com.cortexeb.tools.clover.reporters.html.HtmlReporter"
          fork="true">
       <arg line="--outputdir reports --showSrc --initstring ${clover.initstring} --title 'Berkeley DB Java BDB API'"/>
       <classpath refid="clover.classpath"/>
    </java>
  </target>

</project>

