<?xml version="1.0"?>
<!-- ant compile script -->
<project name="Lucene" default="default" basedir=".">

  <!-- Give user a chance to override without editing this file
      (and without typing -D each time it compiles it -->
  <property name="build.dir" location="../build/tmp"/>
  <property name="dist.dir" location="../build"/>
  <property name="javac.debug" value="off"/>
  <property name="javac.deprecation" value="on"/>
  <property name="build.encoding" value="utf-8"/>
  <property name="name" value="clucene"/>
  <property name="version" value="0.1-dev"/>
  <property name="final.name" value="${name}-${version}"/>
  <property name="demo.name" value="${name}-demos-${version}"/>
  
  <property name="junit.output.dir" location="${dist.dir}/test"/>
  <property name="junit.reports" location="${dist.dir}/test/reports"/>
  
  <!-- Build classpath -->
  <path id="classpath">
    <pathelement location="${build.dir}/java"/>
  </path>
  
  <path id="demo.classpath">
    <path refid="classpath"/>
    <pathelement location="${build.dir}/demo"/>
  </path>
  
  <path id="test.classpath">
    <path refid="classpath"/>
    <pathelement location="${build.dir}/java-test"/>
  </path>
  
  <path id="junit.classpath">
    <pathelement location="${build.dir}/java-test"/>
    <pathelement location="${build.dir}/java"/>
    <fileset dir="lib">
      <include name="*.jar"/>
    </fileset>
    <pathelement path="${java.class.path}"/>
  </path>
  
  
	<!-- ================================================================== -->
  <!-- Prepares the build directory                                       -->
  <!-- ================================================================== -->
  <target name="init">
    <mkdir dir="${build.dir}"/>
    <mkdir dir="${dist.dir}"/>
  </target>
  
  <!-- ================================================================== -->
  <!-- C O M P I L E                                                      -->
  <!-- ================================================================== -->
  <!--                                                                    -->
  <!-- ================================================================== -->
  <target name="compile" depends="compile-core"/>
  <target name="compile-core" depends="init"
    description="Compiles core classes">
    <mkdir dir="${build.dir}/java"/>    
    <javac
      encoding="${build.encoding}"
      srcdir="java"
      includes="**/*.java"
      destdir="${build.dir}/java"
      deprecation="${javac.deprecation}"
      debug="${javac.debug}">
      <classpath refid="classpath"/>
    </javac>
  </target>
  
  <target name="compile-demo" depends="compile-core">
    <mkdir dir="${build.dir}/java-demo"/>

    <javac
      encoding="${build.encoding}"
      srcdir="demo"
      includes="**/*.java"
      destdir="${build.dir}/java-demo"
      debug="${javac.debug}">
      <classpath refid="demo.classpath"/>
    </javac>
  </target>
  
  
  <!-- ================================================================== -->
  <!-- J A R                                                              -->
  <!-- ================================================================== -->
  <!--                                                                    -->
  <!-- ================================================================== -->
  <target name="jar" depends="jar-core"/>
  <target name="jar-core" depends="compile-core"
    description="Generates the Jar file">
    <jar
      destfile="${dist.dir}/${final.name}.jar"
      basedir="${build.dir}/java"
      excludes="**/*.java">
      <manifest>
        <attribute name="Created-By" value="CLucene"/>
      </manifest>
    </jar>
  </target>
  
  <target name="jar-demo" depends="compile-demo">
    <jar
      destfile="${dist.dir}/${demo.name}.jar"
      basedir="${build.dir}/java-demo"
      excludes="**/*.java"
      />
  </target>


  <!-- ================================================================== -->
  <!-- B U I L D  T E S T                                                 -->
  <!-- ================================================================== -->
  <!--                                                                    -->
  <!-- ================================================================== -->
  <target name="compile-test" depends="compile-core">
    <mkdir dir="${build.dir}/java-test"/>
    <javac
      encoding="${build.encoding}"
      srcdir="test"
      includes="**/*.java"
      destdir="${build.dir}/java-test"
      debug="true">
      <classpath refid="test.classpath"/>
    </javac>
  </target>
  
  <!-- ================================================================== -->
  <!-- R U N  T E S T S                                                   -->
  <!-- ================================================================== -->
  <!--                                                                    -->
  <!-- ================================================================== -->
  <target name="run-test" description="Runs unit tests">
    <mkdir dir="${junit.output.dir}"/>
    <junit printsummary="off" haltonfailure="no" dir="${dist.dir}"
      errorProperty="tests.failed" failureProperty="tests.failed">
      <classpath refid="junit.classpath"/>
      <sysproperty key="dataDir" file="test"/>
      <sysproperty key="tempDir" file="${build.dir}/tmp-test"/>
      <formatter type="xml"/>
      <formatter type="brief" usefile="false"/>
      <batchtest fork="yes" todir="${junit.output.dir}" unless="testcase">
        <fileset dir="test" includes="**/Test*.java"/>
      </batchtest>
      <batchtest fork="yes" todir="${junit.output.dir}" if="testcase">
        <fileset dir="test" includes="**/${testcase}.java"/>
      </batchtest>
    </junit>

    <fail if="tests.failed">Tests failed!</fail>
  </target>
  <target name="test" description="Compiles and runs unit tests" 
    depends="compile-test,run-test" />

  <!-- backwards compatible target - may be removed -->
  <target name="test-unit" depends="test"/>

  <target name="generate-test-reports" description="Generates test reports">
    <mkdir dir="${junit.reports}"/>
    <junitreport todir="${junit.output.dir}">
      <fileset dir="${junit.output.dir}">
        <include name="TEST-*.xml"/>
      </fileset>
      <report format="frames" todir="${junit.reports}"/>
    </junitreport>
  </target>
  
  
  
   <target name="default" depends="compile"/>
</project>
