<project>
  <property file="ant-${opencv.build.type}.properties"/>
  <property name="test.dir" value="testResults"/>
  <property name="build.dir" value="build"/>

  <path id="master-classpath">
    <fileset dir="lib">
      <include name="*.jar"/>
    </fileset>
    <fileset dir="bin">
      <include name="*.jar"/>
    </fileset>
  </path>

  <target name="clean">
    <delete dir="build"/>
    <delete dir="${test.dir}"/>
  </target>

  <target name="compile">
    <mkdir dir="build/classes"/>

    <javac sourcepath="" srcdir="src" destdir="build/classes" includeantruntime="false" >
      <include name="**/*.java"/>
      <classpath refid="master-classpath"/>
    </javac>
  </target>

  <target name="jar">
    <mkdir dir="build/jar"/>
    <jar destfile="build/jar/opencv-test.jar" basedir="build/classes">
      <manifest>
        <attribute name="Main-Class" value="org.opencv.test.OpenCVTestRunner"/>
      </manifest>
    </jar>
  </target>

  <target name="test">
    <mkdir dir="${test.dir}"/>
    <junit printsummary="true" haltonfailure="false" haltonerror="false" showoutput="false" logfailedtests="true" maxmemory="256m">
      <sysproperty key="java.library.path" path="${opencv.lib.path}"/>
      <env key="PATH" path="${opencv.lib.path}"/>
      <classpath refid="master-classpath"/>
      <classpath>
        <pathelement location="build/classes"/>
      </classpath>

      <formatter type="xml"/>

      <batchtest fork="yes" todir="${test.dir}">
        <zipfileset src="build/jar/opencv-test.jar" includes="**/*.class" excludes="**/OpenCVTest*">
          <exclude name="**/*$*.class"/>
        </zipfileset>
      </batchtest>
    </junit>
    <junitreport todir="${test.dir}">
      <fileset dir="${test.dir}">
        <include name="TEST-*.xml"/>
      </fileset>
      <report format="noframes" todir="${test.dir}"/>
    </junitreport>
  </target>

  <target name="build">
    <antcall target="compile"/>
    <antcall target="jar"/>
  </target>

  <target name="buildAndTest">
    <antcall target="compile"/>
    <antcall target="jar"/>
    <antcall target="test"/>
  </target>
</project>