<?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="contrib-build" xmlns:artifact="antlib:org.apache.maven.artifact.ant">
  <echo>Building ${ant.project.name}...</echo>

  <!-- TODO: adjust build.dir/dist.dir appropriately when a contrib project is run individually -->
  <property name="build.dir" location="../../build/contrib/${ant.project.name}"/>
  <property name="dist.dir" location="../../dist/contrib/${ant.project.name}"/>
  <property name="maven.dist.dir" location="../../dist/maven"/>
  	
  <import file="../common-build.xml"/>

  <available property="contrib.has.tests" type="dir" file="src/test" />
  
  <!-- if you extend the classpath refid in one contrib's build.xml (add JARs), use this as basis: -->
  <path id="base.classpath">
   <pathelement location="${common.dir}/build/core/classes/java"/>
   <pathelement path="${project.classpath}"/>
  </path>
  
  <!-- default classpath refid, can be overridden by contrib's build.xml (use the above base.classpath as basis): -->
  <path id="classpath" refid="base.classpath"/>
  
  <path id="test.base.classpath">
    <path refid="classpath"/>
    <pathelement location="${common.dir}/build/test-framework/classes/java"/>
    <path refid="junit-path"/>
    <pathelement location="${build.dir}/classes/java"/>
  </path>

  <path id="test.classpath" refid="test.base.classpath"/>

  <path id="junit.classpath">
    <path refid="test.classpath"/>
    <pathelement location="${build.dir}/classes/test"/>
    <pathelement path="${java.class.path}"/>
  </path>

  <target name="init" depends="common.init,compile-lucene-core"/>
  <target name="compile-test" depends="init" if="contrib.has.tests">
    <antcall target="common.compile-test" inheritRefs="true" />
  </target>
  <target name="test" depends="init" if="contrib.has.tests">
    <antcall target="common.test" inheritRefs="true" />
  </target>
  <target name="build-artifacts-and-tests" depends="jar, compile-test" />

  <target name="javadocs" depends="compile-core">
   	<sequential>
       <mkdir dir="${javadoc.dir}/contrib-${name}"/>
       <invoke-javadoc
         destdir="${javadoc.dir}/contrib-${name}"
       	title="${Name} ${version} contrib-${name} API">
         <sources>
           <link href=""/>
           <packageset dir="${src.dir}"/>
        </sources>
      </invoke-javadoc>
      <jarify basedir="${javadoc.dir}/contrib-${name}" destfile="${build.dir}/${final.name}-javadoc.jar"/>
    </sequential>
  </target>	

  <target name="javadocs-index.html" description="Generate line for index.html of JavaDocs">
    <echo file="${javadoc.dir}/index.html" append="true">
<![CDATA[
  <li><a href="contrib-${name}/index.html">${name}</a></li>
]]></echo>
  </target>
  
  <macrodef name="contrib-uptodate">
    <attribute name="name"/>
    <attribute name="property"/>
    <attribute name="jarfile"/>
    <attribute name="contrib-src-name" default="@{name}"/>
    <sequential>
      <uptodate property="@{property}" targetfile="@{jarfile}">
        <srcfiles dir="${common.dir}/contrib/@{contrib-src-name}/src/java" includes="**/*.java"/>
      </uptodate>
    </sequential>
  </macrodef>

  <property name="analyzers-common.jar" value="${common.dir}/build/contrib/analyzers/common/lucene-analyzers-${version}.jar"/>
  <target name="check-analyzers-common-uptodate" unless="analyzers-common.uptodate">
    <contrib-uptodate name="analyzers/common" jarfile="${analyzers-common.jar}" property="analyzers-common.uptodate"/>
  </target>
  <target name="jar-analyzers-common" unless="analyzers-common.uptodate" depends="check-analyzers-common-uptodate">
    <ant dir="${common.dir}/contrib/analyzers/common" target="jar-core" inheritall="false">
      <propertyset refid="uptodate.and.compiled.properties"/>
    </ant>
    <property name="analyzers-common.uptodate" value="true"/>
  </target>

  <property name="analyzers-phonetic.jar" value="${common.dir}/build/contrib/analyzers/phonetic/lucene-phonetic-${version}.jar"/>
  <target name="check-analyzers-phonetic-uptodate" unless="analyzers-phonetic.uptodate">
    <contrib-uptodate name="analyzers/phonetic" jarfile="${analyzers-phonetic.jar}" property="analyzers-phonetic.uptodate"/>
  </target>
  <target name="jar-analyzers-phonetic" unless="analyzers-phonetic.uptodate" depends="check-analyzers-phonetic-uptodate">
    <ant dir="${common.dir}/contrib/analyzers/phonetic" target="jar-core" inheritall="false">
      <propertyset refid="uptodate.and.compiled.properties"/>
    </ant>
    <property name="analyzers-phonetic.uptodate" value="true"/>
  </target>

  <property name="facet.jar" value="${common.dir}/build/contrib/facet/lucene-facet-${version}.jar"/>
  <target name="check-facet-uptodate" unless="facet.uptodate">
    <contrib-uptodate name="facet" jarfile="${facet.jar}" property="facet.uptodate"/>
  </target>
  <target name="jar-facet" unless="facet.uptodate" depends="check-facet-uptodate">
    <ant dir="${common.dir}/contrib/facet" target="jar-core" inheritall="false">
      <propertyset refid="uptodate.and.compiled.properties"/>
    </ant>
    <property name="facet.uptodate" value="true"/>
  </target>

  <property name="analyzers-smartcn.jar" value="${common.dir}/build/contrib/analyzers/smartcn/lucene-smartcn-${version}.jar"/>
  <target name="check-analyzers-smartcn-uptodate" unless="analyzers-smartcn.uptodate">
    <contrib-uptodate name="analyzers/smartcn" jarfile="${analyzers-smartcn.jar}" property="analyzers-smartcn.uptodate"/>
  </target>
  <target name="jar-analyzers-smartcn" unless="analyzers-smartcn.uptodate" depends="check-analyzers-smartcn-uptodate">
  	<ant dir="${common.dir}/contrib/analyzers/smartcn" target="jar-core" inheritAll="false">
      <propertyset refid="uptodate.and.compiled.properties"/>
    </ant>
    <property name="analyzers-smartcn.uptodate" value="true"/>
  </target>

  <property name="analyzers-stempel.jar" value="${common.dir}/build/contrib/analyzers/stempel/lucene-stempel-${version}.jar"/>
  <target name="check-analyzers-stempel-uptodate" unless="analyzers-stempel.uptodate">
    <contrib-uptodate name="analyzers/stempel" jarfile="${analyzers-stempel.jar}" property="analyzers-stempel.uptodate"/>
  </target>
  <target name="jar-analyzers-stempel" unless="analyzers-stempel.uptodate" depends="check-analyzers-stempel-uptodate">
  	<ant dir="${common.dir}/contrib/analyzers/stempel" target="jar-core" inheritAll="false">
      <propertyset refid="uptodate.and.compiled.properties"/>
    </ant>
    <property name="analyzers-stempel.uptodate" value="true"/>
  </target>

  <property name="analyzers-kuromoji.jar" value="${common.dir}/build/contrib/analyzers/kuromoji/lucene-kuromoji-${version}.jar"/>
  <target name="check-analyzers-kuromoji-uptodate" unless="analyzers-kuromoji.uptodate">
    <contrib-uptodate name="analyzers/kuromoji" jarfile="${analyzers-kuromoji.jar}" property="analyzers-kuromoji.uptodate"/>
  </target>
  <target name="jar-analyzers-kuromoji" unless="analyzers-kuromoji.uptodate" depends="check-analyzers-kuromoji-uptodate">
  	<ant dir="${common.dir}/contrib/analyzers/kuromoji" target="jar-core" inheritAll="false">
      <propertyset refid="uptodate.and.compiled.properties"/>
    </ant>
    <property name="analyzers-kuromoji.uptodate" value="true"/>
  </target>

  <property name="grouping.jar" value="${common.dir}/build/contrib/grouping/lucene-grouping-${version}.jar"/>
  <target name="check-grouping-uptodate" unless="grouping.uptodate">
    <contrib-uptodate name="grouping" jarfile="${grouping.jar}" property="grouping.uptodate"/>
  </target>
  <target name="jar-grouping" unless="grouping.uptodate" depends="check-grouping-uptodate">
  	<ant dir="${common.dir}/contrib/grouping" target="jar-core" inheritAll="false">
      <propertyset refid="uptodate.and.compiled.properties"/>
    </ant>
    <property name="grouping.uptodate" value="true"/>
  </target>

  <property name="highlighter.jar" value="${common.dir}/build/contrib/highlighter/lucene-highlighter-${version}.jar"/>
  <target name="check-highlighter-uptodate" unless="highlighter.uptodate">
    <contrib-uptodate name="highlighter" jarfile="${highlighter.jar}" property="highlighter.uptodate"/>
  </target>
  <target name="jar-highlighter" unless="highlighter.uptodate" depends="check-highlighter-uptodate">
    <ant dir="${common.dir}/contrib/highlighter" target="jar-core" inheritall="false">
      <propertyset refid="uptodate.and.compiled.properties"/>
    </ant>
    <property name="highlighter.uptodate" value="true"/>
  </target>

  <property name="icu.jar" value="${common.dir}/build/contrib/icu/lucene-icu-${version}.jar"/>
  <target name="check-icu-uptodate" unless="icu.uptodate">
    <contrib-uptodate name="icu" jarfile="${icu.jar}" property="icu.uptodate"/>
  </target>
  <target name="jar-icu" unless="icu.uptodate" depends="check-icu-uptodate">
  	<ant dir="${common.dir}/contrib/icu" target="jar-core" inheritAll="false">
      <propertyset refid="uptodate.and.compiled.properties"/>
    </ant>
    <property name="icu.uptodate" value="true"/>
  </target>

  <property name="memory.jar" value="${common.dir}/build/contrib/memory/lucene-memory-${version}.jar"/>
  <target name="check-memory-uptodate" unless="memory.uptodate">
    <contrib-uptodate name="memory" jarfile="${memory.jar}" property="memory.uptodate"/>
  </target>
  <target name="jar-memory" unless="memory.uptodate" depends="check-memory-uptodate">
    <ant dir="${common.dir}/contrib/memory" target="jar-core" inheritall="false">
      <propertyset refid="uptodate.and.compiled.properties"/>
    </ant>
    <property name="memory.uptodate" value="true"/>
  </target>

  <property name="misc.jar" value="${common.dir}/build/contrib/misc/lucene-misc-${version}.jar"/>
  <target name="check-misc-uptodate" unless="misc.uptodate">
    <contrib-uptodate name="misc" jarfile="${misc.jar}" property="misc.uptodate"/>
  </target>
  <target name="jar-misc" unless="misc.uptodate" depends="check-misc-uptodate">
  	<ant dir="${common.dir}/contrib/misc" target="jar-core" inheritAll="false">
      <propertyset refid="uptodate.and.compiled.properties"/>
    </ant>
    <property name="misc.uptodate" value="true"/>
  </target>

  <property name="queries.jar" value="${common.dir}/build/contrib/queries/lucene-queries-${version}.jar"/>
  <target name="check-queries-uptodate" unless="queries.uptodate">
    <contrib-uptodate name="queries" jarfile="${queries.jar}" property="queries.uptodate"/>
  </target>
  <target name="jar-queries" unless="queries.uptodate" depends="check-queries-uptodate">
    <ant dir="${common.dir}/contrib/queries" target="jar-core" inheritall="false">
      <propertyset refid="uptodate.and.compiled.properties"/>
    </ant>
    <property name="queries.uptodate" value="true"/>
  </target>

  <property name="queryparser.jar" value="${common.dir}/build/contrib/queryparser/lucene-queryparser-${version}.jar"/>
  <target name="check-queryparser-uptodate" unless="queryparser.uptodate">
    <contrib-uptodate name="queryparser" jarfile="${queryparser.jar}" property="queryparser.uptodate"/>
  </target>
  <target name="jar-queryparser" unless="queryparser.uptodate" depends="check-queryparser-uptodate">
    <ant dir="${common.dir}/contrib/queryparser" target="jar-core" inheritall="false">
      <propertyset refid="uptodate.and.compiled.properties"/>
    </ant>
    <property name="queryparser.uptodate" value="true"/>
  </target>

  <property name="spatial.jar" value="${common.dir}/build/contrib/spatial/lucene-spatial-${version}.jar"/>
  <target name="check-spatial-uptodate" unless="spatial.uptodate">
    <contrib-uptodate name="spatial" jarfile="${spatial.jar}" property="spatial.uptodate"/>
  </target>
  <target name="jar-spatial" unless="spatial.uptodate" depends="check-spatial-uptodate">
  	<ant dir="${common.dir}/contrib/spatial" target="jar-core" inheritAll="false">
      <propertyset refid="uptodate.and.compiled.properties"/>
    </ant>
    <property name="spatial.uptodate" value="true"/>
  </target>

  <property name="spellchecker.jar" value="${common.dir}/build/contrib/spellchecker/lucene-spellchecker-${version}.jar"/>
  <target name="check-spellchecker-uptodate" unless="spellchecker.uptodate">
    <contrib-uptodate name="spellchecker" jarfile="${spellchecker.jar}" property="spellchecker.uptodate"/>
  </target>
  <target name="jar-spellchecker" unless="spellchecker.uptodate" depends="check-spellchecker-uptodate">
  	<ant dir="${common.dir}/contrib/spellchecker" target="jar-core" inheritAll="false">
      <propertyset refid="uptodate.and.compiled.properties"/>
    </ant>
    <property name="spellchecker.uptodate" value="true"/>
  </target>
</project>
