<?xml version="1.0" encoding="UTF-8"?>
<!--
    Ant buildfile for testing TET with the Lucene search software.
    
    To try this out, drop the Lucene JAR file into the same directory
    as this build.xml file. Invoke "ant index" to create an index
    over the PDF files that come with the TET distribution. Then invoke
    "ant search" to run a simple command-line based query environment.
    
    The search application accepts the Lucene query language. After entering
    the query the results will be displayed in a simple query pager. The pager
    must be exited by entering "q", before the next query can be entered. 
    
    As the search application will run under Ant, there will be a "[java]"
    prefix before each output line. The prefix will not appear when running
    the applications directly with the JVM under the "java" command.
    
    $Id: build.xml,v 1.2 2008/11/13 11:17:27 stm Exp $
-->
<project name="tet-lucene" default="all">
    <!--
        For optionally overriding the default properties with a platform-specific
        "unix.properties" or "windows.properties" file and a generic 
        "build.properties" file.
    -->
    <condition property="os.family" value="unix">
        <or>
            <os family="unix"/>
            <os family="mac"/>
        </or>
    </condition>

    <condition property="os.family" value="windows">
        <os family="windows"/>
    </condition>

    <property file="${os.family}.properties"/>
    <property file="build.properties" />
    
    <!-- Location of the TET Java binaries. -->
    <property name="tet.java.dir" value="../../bind/java" />
    <property name="tet.jni.dir" value="${tet.java.dir}" />
    <property name="tet.jar" value="${tet.java.dir}/TET.jar" />
    
    <!-- Searchpath for the indexer, to find the CJK CMaps and other resources -->
    <property name="tet.searchpath" value="../../resource/cmap ../../resource" />

    <!-- Location of the Lucene JAR file. -->
    <property name="lucene.jar" value="lucene-core-2.4.0.jar" />

    <!-- Java source and target directories. -->
    <property name="src.dir" value="src" />
    <property name="bin.dir" value="bin" />
   
    <!-- Directory for storing the Lucene index. -->
    <property name="index.dir" value="index" />
    
    <!--
        Root of the directory tree that is searched recursively for PDF
        documents to be added to the index, the default is the "data" directory
        of the TET distribution.
    -->
    <property name="root.dir" value="../../bind/data" />

    <path id="classpath">
        <pathelement location="${lucene.jar}" />
        <pathelement location="${tet.jar}" />
        <pathelement location="${bin.dir}" />
    </path>
    
    <target name="all" depends="compile" />

    <target name="compile">
        <mkdir dir="${bin.dir}"/>
        <javac srcdir="${src.dir}" destdir="${bin.dir}">
            <classpath refid="classpath" />
        </javac>
    </target>

    <target name="index" depends="compile">
        <echo>Indexing PDF files in directory "${root.dir}"</echo>
        <java classname="com.pdflib.tet.lucene.IndexPdfFiles" fork="true">
            <jvmarg value="-Djava.library.path=${tet.jni.dir}" />
            <jvmarg value="-Dtet.searchpath=${tet.searchpath}" />
            <classpath refid="classpath" />
            <arg value="-index" />
            <arg value="${index.dir}" />
            <arg value="${root.dir}" />
        </java>
    </target>

    <target name="search" depends="compile">
        <java classname="com.pdflib.tet.lucene.SearchFiles" fork="true">
            <jvmarg value="-Djava.library.path=${tet.jni.dir}" />
            <classpath refid="classpath" />
            <arg value="-index" />
            <arg value="${index.dir}" />
        </java>
    </target>
    
    <target name="clean">
        <delete includeemptydirs="true">
            <fileset dir="${bin.dir}" includes="**/*" />
        </delete>
        <delete dir="${index.dir}" />
    </target>
</project>