<?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.
  -
  - $Id$
  -->

<!--
  - Xindice Addressbook and Guide Ant build file
  -->
<project name="xindice-examples" default="release" basedir=".">

    <!-- =================================================================== -->
    <!-- Build definitions                                                   -->
    <!-- =================================================================== -->

    <!-- source directories -->
    <property name="root.dir" value="../.."/>
    <property name="jar.dir" value="${root.dir}/lib"/>

    <!-- destination directories -->
    <property name="build.dir" value="${root.dir}/build"/>
    <property name="dist.dir" value="${root.dir}"/>

    <!-- classpath to use within project -->
    <path id="project.class.path">
        <!-- all jars in jar and dist directory -->
        <fileset dir="${jar.dir}/endorsed">
           <include name="*.jar"/>
        </fileset>
        <fileset dir="${jar.dir}">
           <include name="*.jar"/>
        </fileset>
        <fileset dir="${root.dir}">
           <include name="*.jar"/>
        </fileset>
    </path>

    <target name="init"
            description="Initializes the build">
        <property file="${root.dir}/local.build.properties"/>
        <property file="${root.dir}/build.properties"/>

        <tstamp/>
        <mkdir dir="${build.dir}"/>
    </target>

    <!-- =================================================================== -->
    <!-- Definition of the main targets                                      -->
    <!-- =================================================================== -->

    <target name="build" depends="addressbook-build, guide-build"/>

    <target name="release" depends="addressbook-release, guide-release"/>

    <target name="clean" depends="addressbook-clean, guide-clean"/>

    <!-- =================================================================== -->
    <!-- Addressbook example                                                 -->
    <!-- =================================================================== -->

    <target name="addressbook-init" depends="init">
        <!-- Addressbook property definitions -->
        <property name="addressbook.src.dir" value="addressbook/src/java"/>
        <property name="addressbook.jsp.dir" value="addressbook/src/jsp"/>
        <property name="addressbook.build.dir" value="${build.dir}/addressbook-classes"/>
        <property name="addressbook.war" value="${build.dir}/xindice-${project.version}-addressbook.war"/>
        <property name="addressbook.config.dir" value="config"/>
    </target>

    <target name="addressbook-build"
            depends="addressbook-init">
       <mkdir dir="${addressbook.build.dir}"/>

       <javac srcdir="${addressbook.src.dir}"
             destdir="${addressbook.build.dir}"
             debug="${compile.debug}"
             optimize="${compile.optimize}"
             nowarn="${compile.nowarn}"
             deprecation="${compile.deprecation}"
             verbose="${compile.verbose}">
          <classpath>
             <path refid="project.class.path"/>
          </classpath>
       </javac>
    </target>

    <target name="addressbook-release"
            depends="addressbook-build">
       <war destfile="${addressbook.war}"
            update="false"
            webxml="addressbook/config/web.xml">
          <fileset dir="${addressbook.jsp.dir}"/>
          <classes dir="${addressbook.build.dir}"/>
          <lib dir="${jar.dir}/endorsed">
             <include name="xalan-*.jar"/>
             <include name="xercesImpl-*.jar"/>
             <include name="xml-apis-*.jar"/>
          </lib>
          <lib dir="${jar.dir}">
             <include name="commons-logging-*.jar" />
             <include name="xmldb-api-*.jar"/>
             <include name="xmldb-xupdate-*.jar"/>
             <include name="xmlrpc-*.jar"/>
             <include name="ws-commons-util-*.jar"/>
          </lib>
          <lib dir="${root.dir}">
             <include name="xindice-*.jar"/>
          </lib>
          <manifest>
             <attribute name="Built-By" value="${user.name}"/>
             <section name="org/apache/xindice">
                <attribute name="Sealed" value="false"/>
             </section>
          </manifest>
       </war>
    </target>

    <target name="addressbook-clean"
            depends="addressbook-init">
        <delete file="${addressbook.war}"/>
        <delete dir="${addressbook.build.dir}"/>
    </target>

    <!-- =================================================================== -->
    <!-- Guide examples                                                      -->
    <!-- =================================================================== -->

    <target name="guide-init" depends="init">
        <!-- Guide property definitions -->
        <property name="guide.jar.name"  value="${build.dir}/xindice-${project.version}-guide.jar"/>
        <property name="guide.build.dir" value="${build.dir}/guide-classes"/>
        <property name="guide.src.dir" value="guide/src"/>
    </target>

    <target name="guide-build"
            depends="guide-init">
       <mkdir dir="${guide.build.dir}"/>

       <javac srcdir="${guide.src.dir}"
             destdir="${guide.build.dir}"
             debug="${compile.debug}"
             optimize="${compile.optimize}"
             nowarn="${compile.nowarn}"
             deprecation="${compile.deprecation}"
             verbose="${compile.verbose}">
          <classpath>
             <path refid="project.class.path"/>
          </classpath>
       </javac>
    </target>

    <target name="guide-release"
            depends="guide-build">
       <jar jarfile="${guide.jar.name}"
            basedir="${guide.build.dir}">
          <manifest>
             <attribute name="Built-By" value="${user.name}"/>
             <section name="org/apache/xindice">
                <attribute name="Sealed" value="false"/>
             </section>
          </manifest>
       </jar>
    </target>

    <target name="guide-clean"
            depends="guide-init">
        <delete file="${guide.jar.name}"/>
        <delete dir="${guide.build.dir}"/>
    </target>

</project>
