<?xml version="1.0"?>

<!--
    Licensed to the Apache Software Foundation (ASF) under one or more
    contributor license agreements.  See the NOTICE file distributed with
    this work for additional information regarding copyright ownership.
    The ASF licenses this file to You under the Apache License, Version 2.0
    the "License"); you may not use this file except in compliance with
    the License.  You may obtain a copy of the License at
 
        http://www.apache.org/licenses/LICENSE-2.0
 
    Unless required by applicable law or agreed to in writing, software
    distributed under the License is distributed on an "AS IS" BASIS,
    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    See the License for the specific language governing permissions and
    limitations under the License.
 -->

<project name="lucene" default="default" basedir="."
         xmlns:artifact="antlib:org.apache.maven.artifact.ant">

  <import file="common-build.xml"/>

  <path id="classpath">
    <pathelement location="${common.dir}/build/core/classes/java"/>
  </path>

  <path id="demo.classpath">
    <path refid="classpath"/>
    <pathelement location="${build.dir}/classes/demo"/>
  </path>

  <patternset id="binary.build.dist.patterns"
              includes="docs/,contrib/*/*.jar,contrib/*/*.war, contrib/*/*/*.jar"
              excludes="*-src.jar"
  />
  <patternset id="binary.root.dist.patterns"
              includes="CHANGES.txt,LICENSE.txt,NOTICE.txt,README.txt,MIGRATE.txt,JRE_VERSION_MIGRATION.txt,contrib/**/README*,**/CHANGES.txt,contrib/**/*.sh contrib/**/docs/ contrib/xml-query-parser/*.dtd,lib/*.jar,lib/*LICENSE*.txt,lib/*NOTICE*.txt,contrib/*/lib/*.jar,contrib/*/lib/*LICENSE*.txt,contrib/*/lib/*NOTICE*.txt,test-framework/**/lib/*.jar,test-framework/**/lib/*NOTICE*.txt,test-framework/**/lib/*LICENSE*.txt"
  />


  <!-- ================================================================== -->
  <!-- Prepares the build directory                                       -->
  <!-- ================================================================== -->

  <target name="test-core" description="Runs unit tests for the core Lucene code">
    <ant dir="${common.dir}/core" target="test" inheritAll="false">
      <propertyset refid="uptodate.and.compiled.properties"/>
    </ant>
  </target>

  <target name="test" depends="test-core, test-contrib, test-backwards"
          description="Runs all unit tests (core, contrib and back-compat)"
  />

  <path id="backwards.test.compile.classpath">
    <path refid="junit-path"/>
    <path refid="ant-path"/>
    <fileset dir="${backwards.dir}/lib/"/>
  </path>
	
  <path id="backwards.junit.classpath">
    <path refid="junit-path"/>
    <path refid="classpath"/>
    <pathelement location="${build.dir.backwards}/classes/test"/>
    <pathelement path="${java.class.path}"/>
  </path>

  <!-- remove this -->
  <target name="test-tag" depends="test-backwards" description="deprecated"/>
  
  <target name="compile-backwards" depends="compile-core,resolve"
  	description="Runs tests of a previous Lucene version.">
    <sequential>
      <mkdir dir="${build.dir.backwards}"/>	  
      
      <!-- TODO: separate test-framework from core tests (because META-INF duplicates in trunk) -->
      
      <!-- compile branch tests against previous version JAR file -->	
      <compile-test-macro srcdir="${backwards.dir}/src/test-framework/java" destdir="${build.dir.backwards}/classes/test"
                  test.classpath="backwards.test.compile.classpath" javac.source="${javac.source.backwards}" javac.target="${javac.target.backwards}"/>
      <!-- Copy the resources folder (if existent) -->
      <copy todir="${build.dir.backwards}/classes/test">
        <fileset dir="${backwards.dir}/src/test-framework/resources" erroronmissingdir="no"/>
      </copy>
      <compile-test-macro srcdir="${backwards.dir}/src/test" destdir="${build.dir.backwards}/classes/test"
                  test.classpath="backwards.test.compile.classpath" javac.source="${javac.source.backwards}" javac.target="${javac.target.backwards}"/>
      

    </sequential>
  </target>	

  <target name="test-backwards" depends="compile-backwards, backwards-test-warning, junit-backwards-mkdir, junit-backwards-sequential, junit-backwards-parallel"/>

  <target name="junit-backwards-mkdir">
    <mkdir dir="${build.dir.backwards}/test"/>
  </target>

  <target name="check-backwards-params">
    <condition property="backwards.ignoring.params">
      <or>
        <istrue value="${tests.nightly}"/>
        <not><equals arg1="${tests.multiplier}" arg2="1"/></not>
      </or>
    </condition>
  </target>

  <target name="backwards-test-warning" depends="check-backwards-params" if="backwards.ignoring.params">
    <echo>
       Warning: Ignoring your multiplier and nightly settings for backwards tests.
       These tests are for API compatibility only!
    </echo>
  </target>

  <macrodef name="backwards-test-macro">
  	<attribute name="threadNum" default="1"/>
  	<attribute name="threadTotal" default="1"/>
  	<sequential>
  	  <!-- run branch tests against trunk jar:
          Note: we disable multiplier/nightly because the purpose is to find API breaks
          -->
      <test-macro 
    	dataDir="${backwards.dir}/src/test" 
    	tempDir="${build.dir.backwards}/test" 
    	junit.classpath="backwards.junit.classpath" 
    	junit.output.dir="${junit.output.dir.backwards}" 
        tests.nightly="false"
        tests.multiplier="1"
        threadNum="@{threadNum}" 
        threadTotal="@{threadTotal}"/>
  	</sequential>
  </macrodef>

  <target name="junit-backwards-sequential" if="tests.sequential">
    <backwards-test-macro/>
  </target>

  <target name="junit-backwards-parallel" unless="tests.sequential">
    <parallel threadsPerProcessor="${tests.threadspercpu}">
     <backwards-test-macro threadNum="1" threadTotal="4"/>
     <backwards-test-macro threadNum="2" threadTotal="4"/>
     <backwards-test-macro threadNum="3" threadTotal="4"/>
     <backwards-test-macro threadNum="4" threadTotal="4"/>
    </parallel>
  </target>

  <target name="compile-core" depends="compile-lucene-core"/>

  <!--
   Run after Junit tests.
   -->
  <target name="generate-clover-reports" depends="clover.check, clover">
    <mkdir dir="${clover.report.dir}"/>
    <!-- This extra path is needed, because from a top-level ant run, the contrib tests would be not visible (report generation is only done on top-level not via subants) -->
    <fileset dir="." id="clover.test.src.files">
      <include name="**/src/test/**/*.java"/>
      <include name="test-framework/src/java/**/*.java"/>
      <exclude name="lucene/backwards/**"/>
    </fileset>
    <fileset dir="build" id="clover.test.result.files">
      <include name="**/test/TEST-*.xml"/>
      <!-- do not include BW tests -->
      <exclude name="backwards/**"/>
    </fileset>
    <clover-report>
      <current outfile="${clover.report.dir}" title="${final.name}" numThreads="0">
        <format type="html" filter="assert"/>
        <testsources refid="clover.test.src.files"/>
        <testresults refid="clover.test.result.files"/>
      </current>
      <current outfile="${clover.report.dir}/clover.xml" title="${final.name}">
        <format type="xml" filter="assert"/>
        <testsources refid="clover.test.src.files"/>
        <testresults refid="clover.test.result.files"/>
      </current>
    </clover-report>
  </target>

  <!-- Validate once from top-level. -->
  <target name="validate" depends="compile-tools,resolve" description="Validate legal stuff.">
    <license-check-macro dir="${basedir}">
      <additional-excludes>
        <exclude name="backwards/lib/**/*.jar" />
      </additional-excludes>
      <additional-filters>
      </additional-filters>
    </license-check-macro>
  </target>

  <!-- ================================================================== -->
  <!-- D O C U M E N T A T I O N                                          -->
  <!-- ================================================================== -->
  <!--                                                                    -->
  <!-- ================================================================== -->
  <target name="docs">
  <!-- copies the docs over to the docs folder -->
    <copy todir="build/docs">
      <fileset dir="site/build/site"/> 
    </copy>
  </target>

  <target name="resolve">
    <sequential>
      <ant dir="test-framework" target="resolve" inheritall="false">
         <propertyset refid="uptodate.and.compiled.properties"/>
      </ant>
      <ant dir="backwards" target="resolve" inheritall="false">
         <propertyset refid="uptodate.and.compiled.properties"/>
      </ant>
      <contrib-crawl target="resolve" failonerror="true"/>
    </sequential>
  </target>

  <target name="javadoc" depends="javadocs"/>
  <target name="javadocs" description="Generate javadoc" 
          depends="javadocs-all, javadocs-core, javadocs-contrib, javadocs-test-framework">
    <echo file="${javadoc.dir}/index.html" append="false">
<![CDATA[<html><head><title>${Name} ${version} Javadoc Index</title></head>
<body>
<h1>${Name} ${version} Javadoc Index</h1>
<ul>
  <li><a href="all/index.html">All</a></li>
  <li><a href="core/index.html">Core</a></li>
  <li><a href="test-framework/index.html">Test Framework</a></li>
  <li>Contrib packages:</li>
  <ul>
]]></echo>
    <contrib-crawl target="javadocs-index.html" failonerror="false"/>
    <echo file="${javadoc.dir}/index.html" append="true"><![CDATA[
  </ul>
</ul></body>]]></echo>
  </target>
	
  <target name="javadocs-core" description="Generate javadoc for core classes">
    <ant dir="${common.dir}/core" target="javadocs" inheritAll="false">
      <propertyset refid="uptodate.and.compiled.properties"/>
    </ant>
  </target>

  <target name="javadocs-test-framework">
    <ant dir="${common.dir}/test-framework" target="javadocs" inheritAll="false">
      <propertyset refid="uptodate.and.compiled.properties"/>
    </ant>
  </target>

  <target name="javadocs-contrib" description="Generate javadoc for contrib classes">
    <contrib-crawl target="javadocs"
                   failonerror="false"/>
  </target>

  <!-- call resolve to force dependencies to be in lib/ for javadocs -->
  <target name="javadocs-all" depends="resolve" 
          description="Generate javadoc for core and contrib classes">
  	<sequential>
      <mkdir dir="${javadoc.dir}/all"/>

      <path id="javadoc.classpath">
        <path refid="classpath"/>
        <pathelement location="${ant.home}/lib/ant.jar"/>
        <fileset dir="." includes="test-framework/lib/,contrib/analyzers/phonetic/lib/,contrib/benchmark/lib/,contrib/icu/lib/,contrib/queries/lib/" excludes="**/lib/*.txt"/>
      </path>

      <invoke-javadoc overview="${common.dir}/core/src/java/overview.html"
                      destdir="${javadoc.dir}/all">
        <sources>
          <!-- TODO: find a dynamic way to do include multiple source roots -->
          <packageset dir="core/src/java"/>
          <packageset dir="test-framework/src/java"/>

          <!-- please keep this list up to date, and in alpha order...   -->

          <!-- ie: `find contrib/* -path \*src/java | sort` -->

          <!-- if you make changes to the list of package sets, also -->
          <!-- make sure the group list below is updated.            -->
          <!-- Also remember to keep site.xml in sync.            -->

          <packageset dir="contrib/analyzers/common/src/java"/>
          <packageset dir="contrib/analyzers/kuromoji/src/java"/>
          <packageset dir="contrib/analyzers/phonetic/src/java"/>
          <packageset dir="contrib/analyzers/smartcn/src/java"/>
          <packageset dir="contrib/analyzers/stempel/src/java"/>
          <packageset dir="contrib/benchmark/src/java"/>
          <packageset dir="contrib/demo/src/java"/>
          <packageset dir="contrib/facet/src/java"/>
          <packageset dir="contrib/grouping/src/java"/>
          <packageset dir="contrib/icu/src/java"/>
          <packageset dir="contrib/highlighter/src/java"/>
          <packageset dir="contrib/instantiated/src/java"/>
          <packageset dir="contrib/join/src/java"/>
          <packageset dir="contrib/memory/src/java"/>
          <packageset dir="contrib/misc/src/java"/>
          <packageset dir="contrib/pruning/src/java"/>
          <packageset dir="contrib/queries/src/java"/>
          <packageset dir="contrib/remote/src/java"/>
          <packageset dir="contrib/spatial/src/java"/>
          <packageset dir="contrib/spellchecker/src/java"/>
          <packageset dir="contrib/xml-query-parser/src/java"/>
          <packageset dir="contrib/queryparser/src/java"/>
          <!-- end alpha sort -->

          <!-- If the main javadoc Group listing includes an "Other   -->
          <!-- Packages" group after the ones listed here, then those -->
          <!-- packages are not being matched by any of these rules   -->

          <group title="Core" packages="org.apache.*:org.apache.lucene.analysis:org.apache.lucene.analysis.standard*:org.apache.lucene.analysis.tokenattributes*"/>

          <group title="contrib: Analysis" packages="org.apache.lucene.analysis.*:org.tartarus.snowball*:org.egothor.stemmer*"/>
          <group title="contrib: Benchmark" packages="org.apache.lucene.benchmark*"/>
          <group title="contrib: ICU" packages="org.apache.lucene.collation*"/>
          <group title="contrib: Demo" packages="org.apache.lucene.demo*"/>
          <group title="contrib: Facet" packages="org.apache.lucene.facet*"/>
          <group title="contrib: Grouping" packages="org.apache.lucene.search.grouping*"/>
          <group title="contrib: Highlighter" packages="org.apache.lucene.search.highlight*:org.apache.lucene.search.vectorhighlight*"/>
          <group title="contrib: Instantiated" packages="org.apache.lucene.store.instantiated*"/>
          <group title="contrib: Join" packages="org.apache.lucene.search.join*"/>
          <group title="contrib: Memory" packages="org.apache.lucene.index.memory*"/>
          <group title="contrib: Misc " packages="org.apache.lucene.misc*"/>
          <group title="contrib: Pruning" packages="org.apache.lucene.index.pruning*"/>
          <group title="contrib: Queries" packages="org.apache.lucene.search.similar*:org.apache.lucene.search.regex*:org.apache.regexp*"/>
          <group title="contrib: Query Parser" packages="org.apache.lucene.queryParser.*"/>
          <group title="contrib: Spatial" packages="org.apache.lucene.spatial*"/>
          <group title="contrib: SpellChecker" packages="org.apache.lucene.search.spell*:org.apache.lucene.search.suggest*"/>
          <group title="contrib: XML Query Parser" packages="org.apache.lucene.xmlparser*"/>

        </sources>
      </invoke-javadoc>
  	</sequential>
  </target>

  <target name="rat-sources">
    <sequential>
       <ant dir="core" target="rat-sources" inheritall="false"/>
       <ant dir="test-framework" target="rat-sources" inheritall="false"/>
       <ant dir="tools" target="rat-sources" inheritall="false"/>
       <contrib-crawl target="rat-sources" failonerror="true"/>
    </sequential>
  </target>

  <!-- ================================================================== -->
  <!-- D I S T R I B U T I O N                                            -->
  <!-- ================================================================== -->
  <!--                                                                    -->
  <!-- ================================================================== -->
  <target name="package" depends="jar-lucene-core, jar-test-framework, docs, javadocs, build-contrib, init-dist, changes-to-html"/>

  <target name="nightly" depends="test, package-tgz">
  </target>

  <!-- ================================================================== -->
  <!-- Packages the distribution with zip                                 -->
  <!-- ================================================================== -->
  <!--                                                                    -->
  <!-- ================================================================== -->
  <target name="package-zip" depends="package"
    description="--> Generates the Lucene distribution as .zip">

    <delete file="${dist.dir}/lucene-${version}.zip"/>
    <zip destfile="${dist.dir}/lucene-${version}.zip">
      <zipfileset prefix="lucene-${version}" dir=".">
        <patternset refid="binary.root.dist.patterns"/>
      </zipfileset>
      <zipfileset dir="${build.dir}" includes="build-demo.xml" fullpath="lucene-${version}/build.xml"/>
      <zipfileset prefix="lucene-${version}" dir="${build.dir}/core">
        <patternset includes="lucene-core*.jar" excludes="*-src.jar"/>
      </zipfileset>
      <zipfileset prefix="lucene-${version}" dir="${build.dir}/test-framework">
        <patternset includes="lucene-test-framework*.jar" excludes="*-src.jar"/>
      </zipfileset>
      <zipfileset prefix="lucene-${version}" dir="${build.dir}">
        <patternset refid="binary.build.dist.patterns"/>
      </zipfileset>
    </zip>
	<make-checksums file="${dist.dir}/lucene-${version}.zip"/>
  </target>

  <!-- ================================================================== -->
  <!-- packages the distribution with tar-gzip                            -->
  <!-- ================================================================== -->
  <!--                                                                    -->
  <!-- ================================================================== -->
  <target name="package-tgz" depends="package"
    description="--> Generates the lucene distribution as .tgz">

    <delete file="${build.dir}/lucene-${version}.tar"/>
    <delete file="${dist.dir}/lucene-${version}.tgz"/>
    <tar tarfile="${build.dir}/lucene-${version}.tar" longfile="gnu">
      <tarfileset prefix="lucene-${version}" dir="${build.dir}/core">
        <patternset includes="lucene-core*.jar" excludes="*-src.jar"/>
      </tarfileset>
      <tarfileset prefix="lucene-${version}" dir="${build.dir}/test-framework">
        <patternset includes="lucene-test-framework*.jar" excludes="*-src.jar"/>
      </tarfileset>
      <tarfileset prefix="lucene-${version}" dir=".">
        <patternset refid="binary.root.dist.patterns"/>
      </tarfileset>
      <tarfileset prefix="lucene-${version}" dir="${build.dir}">
        <patternset refid="binary.build.dist.patterns"/>
      </tarfileset>
    </tar>

    <gzip zipfile="${dist.dir}/lucene-${version}.tgz"
      src="${build.dir}/lucene-${version}.tar"
      />
	  <make-checksums file="${dist.dir}/lucene-${version}.tgz"/>
  </target>

  <!-- ================================================================== -->
  <!-- packages the distribution with zip and tar-gzip                    -->
  <!-- ================================================================== -->
  <!--                                                                    -->
  <!-- ================================================================== -->
  <target name="package-all-binary" depends="package-zip, package-tgz"
    description="--> Generates the .tgz and .zip distributions"/>

  <!-- ================================================================== -->
  <!-- same as package-all. it is just here for compatibility.            -->
  <!-- ================================================================== -->
  <!--                                                                    -->
  <!-- ================================================================== -->
  <target name="dist" depends="package-all-binary"/>

  <!-- ================================================================== -->
  <!-- S O U R C E  D I S T R I B U T I O N                               -->
  <!-- ================================================================== -->
    <target name="init-dist" >

        <!-- Package is not called first if packaging src standalone, so the dist.dir may not exist -->
        <mkdir dir="${build.dir}"/>
        <mkdir dir="${dist.dir}"/>
        <mkdir dir="${maven.dist.dir}"/>
    </target>

  <!-- ================================================================== -->
  <!-- Packages the sources from "svn export" with tar-gzip               -->
  <!-- ================================================================== -->
  <target name="package-tgz-src" depends="init-dist"
          description="--> Generates the Lucene source distribution from 'svn export' as .tgz">
    <property name="source.package.file"
              value="${dist.dir}/lucene-${version}-src.tgz"/>
    <delete file="${source.package.file}"/>
    <svn-export-source source.dir="."/>

    <!-- Exclude javadoc package-list files under licenses incompatible with the ASL -->
    <delete dir="${svn.export.dir}/tools/javadoc/java5"/>

    <build-changes changes.src.dir="${svn.export.dir}/site/changes"
                   changes.target.dir="${svn.export.dir}/docs/changes"/>
    <tar tarfile="${source.package.file}" compression="gzip" longfile="gnu">
      <tarfileset prefix="lucene-${version}" dir="${svn.export.dir}"/>
    </tar>
    <make-checksums file="${source.package.file}"/>
  </target>

  <!-- ================================================================== -->
  <!-- Packages the sources from local working copy with tar-gzip     -->
  <!-- ================================================================== -->
  <target name="package-local-src-tgz" depends="init-dist"
    description="--> Packages the Lucene source from the local working copy">
    <mkdir dir="${common.dir}/build"/>
    <property name="source.package.file"
              value="${common.dir}/build/lucene-${version}-src.tgz"/>
    <delete file="${source.package.file}"/>
    <tar tarfile="${source.package.file}" compression="gzip" longfile="gnu">
      <tarfileset prefix="lucene-${version}" dir=".">
        <patternset refid="lucene.local.src.package.patterns"/>
      </tarfileset>
    </tar>
  </target>

  <!-- ================================================================== -->
  <!-- same as package-tgz-src. it is just here for compatibility.        -->
  <!-- ================================================================== -->
  <target name="dist-src" depends="package-tgz-src"/>

  <target name="dist-all" depends="dist, dist-src"/>

  <target name="copy-to-stage">
    <copy-to-stage-macro artifacts.dir="${dist.dir}"/>
  </target>

  <target name="prepare-release" depends="clean, dist-all, generate-maven-artifacts, sign-artifacts"/>

  <target name="stage" depends="prepare-release, copy-to-stage"/>

  <target name="generate-maven-artifacts" depends="install-maven-tasks, package, javadocs">
    <sequential>
      
      <ant target="get-maven-poms" dir=".."/>

      <m2-deploy pom.xml="../pom.xml"/> <!-- Lucene/Solr grandparent POM -->
      <m2-deploy pom.xml="pom.xml"/>    <!-- Lucene parent POM -->
      
      <subant target="dist-maven" failonerror="true" inheritall="false">
        <propertyset refid="uptodate.and.compiled.properties"/>
        <fileset dir="${common.dir}/core" includes="build.xml"/>
        <fileset dir="${common.dir}/test-framework" includes="build.xml"/>
      </subant>
      
      <contrib-crawl target="dist-maven"/>
    </sequential>
  </target>
	
  <!-- ================================================================== -->
  <!-- support for signing the artifacts using gpg                        -->
  <!-- ================================================================== -->
  <target name="sign-artifacts">
    <sign-artifacts-macro artifacts.dir="${dist.dir}"/>
  </target>

  <!-- ================================================================== -->
  <!-- Build the JavaCC files into the source tree                        -->
  <!-- ================================================================== -->
  <target name="clean-javacc">
    <delete>
      <fileset dir="src/java/org/apache/lucene/queryParser" includes="*.java">
        <containsregexp expression="Generated.*By.*JavaCC"/>
      </fileset>
      <fileset dir="contrib/queryparser/src/java/org/apache/lucene/queryParser/surround/parser" includes="*.java">
        <containsregexp expression="Generated.*By.*JavaCC"/>
      </fileset>
      <fileset dir="contrib/queryparser/src/java/org/apache/lucene/queryParser/standard/parser" includes="*.java">
        <containsregexp expression="Generated.*By.*JavaCC"/>
      </fileset>
    </delete>
  </target>

  <target name="javacc" depends="javacc-check,clean-javacc,javacc-QueryParser,javacc-contrib-queryparser,javacc-contrib-demo"/>

  <target name="javacc-QueryParser" depends="javacc-check" if="javacc.present">
    <sequential>
      <invoke-javacc target="src/java/org/apache/lucene/queryParser/QueryParser.jj"
                     outputDir="src/java/org/apache/lucene/queryParser"/>

      <!-- Change the inccorrect public ctors for QueryParser to be protected instead -->
      <replaceregexp file="src/java/org/apache/lucene/queryParser/QueryParser.java"
		     byline="true"
		     match="public QueryParser\(CharStream "
		     replace="protected QueryParser(CharStream "/>
      <replaceregexp file="src/java/org/apache/lucene/queryParser/QueryParser.java"
		     byline="true"
		     match="public QueryParser\(QueryParserTokenManager "
		     replace="protected QueryParser(QueryParserTokenManager "/>

    </sequential>
  </target>	

  <target name="javacc-contrib-queryparser" depends="javacc-check" if="javacc.present">
    <ant target="javacc"
      dir="contrib/queryparser"
      antfile="build.xml" 
    />
  </target>

  <target name="javacc-contrib-demo" depends="javacc-check" if="javacc.present">
    <ant target="javacc"
      dir="contrib/demo"
      antfile="build.xml"
    />
  </target>

  <target name="build-contrib" depends="compile-test"
          description="Builds all contrib modules and their tests">
    <contrib-crawl target="build-artifacts-and-tests"/>
  </target>

   <target name="compile-test" depends="compile-lucene-core,compile-test-framework"
           description="Builds core, test-framework, and contrib tests">
     <ant dir="${common.dir}/core" target="compile-test" inheritAll="false">
       <propertyset refid="uptodate.and.compiled.properties"/>
     </ant>
     <contrib-crawl target="compile-test" failonerror="true"/>
   </target>

  <target name="test-contrib" depends="compile-test">
    <contrib-crawl target="test" failonerror="true"/>
  </target>

  <!--
   compile changes.txt into an html file
   -->
  <macrodef name="build-changes">
    <attribute name="changes.src.dir" default="${changes.src.dir}"/>
    <attribute name="changes.target.dir" default="${changes.target.dir}"/>
    <sequential>
      <mkdir dir="@{changes.target.dir}"/>
      <exec executable="perl" input="CHANGES.txt" output="@{changes.target.dir}/Changes.html"
            failonerror="true" logError="true">
        <arg value="@{changes.src.dir}/changes2html.pl"/>
      </exec>
      <exec executable="perl" input="contrib/CHANGES.txt" output="@{changes.target.dir}/Contrib-Changes.html"
            failonerror="true" logError="true">
        <arg value="@{changes.src.dir}/changes2html.pl"/>
      </exec>
      <copy todir="@{changes.target.dir}">
        <fileset dir="@{changes.src.dir}" includes="*.css"/>
      </copy>
    </sequential>
  </macrodef>

  <target name="changes-to-html">
    <build-changes changes.src.dir="${changes.src.dir}" changes.target.dir="${changes.target.dir}" />
  </target>

  <!--
   Committer helpers
   -->

  <property name="patch.file" value="${basedir}/../patches/${patch.name}"/>
  <!-- Apply a patch.  Assumes  patch can be applied in the basedir.
  -Dpatch.name assumes the patch is located in ${basedir}/../patches/${patch.name}
  -Dpatch.file means the patch can be located anywhere on the file system
  -->
  <target name="apply-patch" depends="clean" description="Apply a patch file.  Set -Dpatch.file, or -Dpatch.name when the patch is in the directory ../patches/">
    <patch patchfile="${patch.file}" strip="0"/>
  </target>

  <target name="jar-test-framework">
    <ant dir="${common.dir}/test-framework" target="jar-core" inheritAll="false">
      <propertyset refid="uptodate.and.compiled.properties"/>
    </ant>
  </target>

  <!-- Override common-build.xml definition to check for the jar already being up-to-date -->
  <target name="jar-core" depends="check-lucene-core-uptodate,compile-lucene-core" unless="lucene-core.uptodate">
    <ant dir="${common.dir}/core" target="jar-core" inheritAll="false">
      <propertyset refid="uptodate.and.compiled.properties"/>
    </ant>
    <property name="core.compiled" value="true"/>
    <property name="lucene-core.uptodate" value="true"/>
  </target>

  <!-- TODO: in the future, we don't need to actually put
       jars in the lib/ folders, but can just put in classpath.
       only packaging tasks really need that (and could do it
       under build/ directories) -->
  <target name="clean-jars" description="Clean local jars">
     <delete>
       <fileset dir="." includes="**/*.jar"/>
     </delete>
  </target>
</project>
