<!-- =================== Build for Castor using Ant 1.6 =================== -->

<!-- $Id: build.xml 6361 2006-10-24 03:43:52Z ekuns $ -->

<project name="Castor" default="compile" basedir="..">

    <!-- ================================================================== -->
    <!--                            Properties                              -->
    <!-- ================================================================== -->

    <!--
    Optionally read a properties file from the user's home dir to override
    properties in this build descriptor.
    -->
    <property file="${user.home}/castor-build.properties"/>

    <property environment="env" />
    <property name="build.sh.class.path"  value="${env.CLASSPATH}" />
    <property name="name"                 value="Castor"/>
    <property name="source"               value="${basedir}/src"/>
    <property name="java"                 value="${source}/main/java"/>
    <property name="main.resources"       value="${source}/main/resources" />
    <property name="test-resources"       value="${source}/test/resources" />
    <property name="etc"                  value="${source}/etc"/>
    <property name="check"                value="check"/>
    <property name="build"                value="${basedir}/build"/>
    <property name="build-doc"            value="build/doc"/>
    <property name="build-howto"          value="build/doc/howto"/>
    <property name="classes"              value="${build}/classes"/>
    <property name="dist"                 value="dist"/>
    <property name="lib"                  value="lib"/>
    <property name="doc"                  value="${source}/doc"/>
    <property name="howto"                value="${source}/howto"/>
    <property name="xml-howto"            value="${source}/xml-howto"/>
    <property name="schema"               value="${build}/schema"/>
    <property name="tests"                value="${build}/tests"/>
    <property name="gen.src"              value="${build}/gen-src"/>
    <property name="project.eclipse"      value="${source}/tools/ide/eclipse" />
    <property file="${etc}/VERSION"/>
    <property name="verbose"              value="off" />
    <property name="deprecation"          value="false"/>
    <property name="main.opt.debug"       value="true"/>
    <property name="archive.name"         value="${project}-${version}${release}"/>
    <property name="srcgen.ant.task.name" value="${project}-${version}${release}-srcgen-ant-task"/>
    <property name="exampleexcludes"      value="SourceGenerator/*,**/dax/**"/>
    <property name="excludes"             value="**/package.html,**/dax/**,**/dax/engine/**"/>
    <property name="testexcludes"         value="**/package.html, **/MasterTestSuite/**, **/RegressionTestSuite/**" />
    <property name="apipackagenames"      value="
        org.exolab.castor.types,
        org.exolab.castor.jdo,
        org.exolab.castor.jdo.util,
        org.exolab.castor.xml,
        org.exolab.castor.dsml,
        org.exolab.castor.mapping,
        org.exolab.castor.util,
        org.exolab.castor.builder"
    />
    <!--    org.exolab.castor.dax, -->
    <property name="allpackagenames"      value="org.*"/>

    <path id="build.classpath">
        <pathelement location="${classes}"/>
        <pathelement location="tests"/>
        <pathelement location="${tests}" />
        <fileset dir="${lib}">
            <include name="*.jar"/>
        </fileset>
        <fileset dir="${lib}/tests">
            <include name="*.jar"/>
        </fileset>
    </path>

    <path id="javadoc.classpath">
        <fileset dir="${lib}">
            <include name="*.jar"/>
        </fileset>
    </path>

    <!-- ================================================================== -->
    <!--            The pattern for the support files that need             -->
    <!--                to be copied when compiling classes                 -->
    <!-- ================================================================== -->
    <patternset id="support.files">
        <include name="**/*.xsd" />
        <include name="**/*.xml" />
        <include name="**/*.xsl" />
        <include name="**/*.properties" />
        <include name="**/*.dtd" />
        <include name="**/*.gif" />
        <exclude name="**/MasterTestSuite/**" />
        <exclude name="**/RegressionTestSuite/**" />
    </patternset>

    <property name="castor.commons.files"
          value="org/castor/cache/**/*.java,
                 org/castor/transactionmanager/**/*.java,
                 org/castor/util/*.java,
                 org/castor/mapping/*.java"/>

    <property name="castor.xml.files"
          value="**/org/exolab/castor/*,
                 org/exolab/castor/builder/**/*.java,
                 org/exolab/castor/mapping/**/*.java,
                 org/exolab/castor/net/**/*.java,
                 org/exolab/castor/tools/**/*.java,
                 org/exolab/castor/types/**/*.java,
                 org/exolab/castor/util/**/*.java,
                 org/exolab/castor/xml/**/*.java,
                 org/exolab/javasource/**/*.java"/>

    <property name="castor.jdo.files"
          value="**/org/exolab/castor/dsml/**/*.java,
                 org/exolab/castor/dtx/**/*.java,
                 org/exolab/castor/gui/**/*.java,
                 org/exolab/castor/jdo/**/*.java,
                 org/exolab/castor/persist/**/*.java,
                 org/exolab/castor/types/**/*.java,
                 org/castor/jdo/**/*.java,
                 org/castor/persist/**/*.java" />

    <target name="targets" description="Prints static list of available targets">
        <echo>
        -----------------------------------------------------------
        ANT build for ${name} ${version}
        -----------------------------------------------------------

        The following targets are available:

            targets          Lists the build targets
            clean            Cleans the build and distribution directories
            all              Cleans and builds all the packages and examples
            release          Cleans and builds all the release packages
                             (JAR, source, doc, tarball) in the dist directory
            main             Builds the main packages (including debugging info)
            tests            (shorthand for compile.tests)
            compile.commons  Compile the Castor COMONS packages
            compile.xml      Compile the Castor XML packages
            compile.jdo      Compile the Castor JDO packages
            compile.examples Builds the example packages (including debugging info)
            compile.tests    Builds the test packages (including debugging info)
            jdo.tests        Executes the JUnit tests for Castor JDO (CTF-JDO)
            jar              Builds the binary JAR in the dist directory
            CTFjar           Builds the JAR of the Castor Testing Framework in the dist directory
            doc              Builds the documentation
            api              Builds the API JavaDocs
            javadoc          Builds the full JavaDocs
            source           Builds the source tarball in the dist directory
            tarball          Builds the binary distribution in the dist directory

            gen.jdo.conf     Use the Source Generator to create the Java classes for jdo-conf.xsd
            gen.mapping      Use the Source Generator to create the Java classes for mapping.xsd
            gen.pvd          Use the Source Generator to create the Java classes for the pvd.xsd
        -----------------------------------------------------------
        </echo>
    </target>

    <!-- Prepare target directories -->
    <target name="prepare" unless="prepare.executed">
        <mkdir dir="${build}"/>
        <mkdir dir="${classes}"/>
        <mkdir dir="${dist}"/>
        <!-- Copy the DTD and schema to the schema directory -->
        <delete dir="${schema}"/>
        <mkdir dir="${schema}"/>
        <copy todir="${schema}">
            <fileset dir="${java}/org/exolab/castor/mapping">
                <patternset refid="support.files" />
            </fileset>
            <fileset dir="${main.resources}/org/exolab/castor/mapping">
                <patternset refid="support.files" />
            </fileset>
        </copy>
        <copy todir="${schema}">
            <fileset dir="${java}/org/castor/jdo/conf">
                <patternset refid="support.files" />
            </fileset>
            <fileset dir="${main.resources}/org/castor/jdo/conf">
                <patternset refid="support.files" />
            </fileset>
        </copy>
        <copy todir="${schema}">
            <fileset dir="${java}/org/exolab/castor/dsml/schema">
                <patternset refid="support.files" />
            </fileset>
            <fileset dir="${main.resources}/org/exolab/castor/dsml/schema">
                <patternset refid="support.files" />
            </fileset>
        </copy>
        <available property="castor-build.present" file="${user.home}/castor-build.properties" />
        <antcall target="-castor-build.check" />
        <property name="prepare.executed" value="true" />
    </target>

    <target name="-castor-build.check"
            description="An internal target to echo a message if a castor-build.properties exists in the user's home dir"
            if="castor-build.present">
        <echo message="Using ${user.home}/castor-build.properties" />
    </target>

    <target name="clean" description="Removes the build, check, dist and schema dirs">
        <delete dir="${build}"/>
        <delete dir="${check}"/>
        <delete dir="${dist}"/>
        <delete dir="${schema}"/>
        <delete dir="${gen.src}"/>
    </target>

    <target name="clean.tests" description="Removes the build artefacts related to test">
        <delete dir="${build}/tests" />
    </target>

    <target name="compile"
            description="The default target for compilation; includes debug and deprecation info">
        <antcall target="compile.jdo" />
    </target>

    <target name="compile.commons" depends="prepare"
            description="Compile the Castor COMMONS packages">
        <javac srcdir="${java}" destdir="${classes}" excludes="${excludes}"
               debug="on" encoding="ISO-8859-1" deprecation="${deprecation}"
               includes="${castor.commons.files}">
            <classpath refid="build.classpath"/>
        </javac>
    </target>

    <target name="compile.xml" depends="prepare,compile.commons"
            description="Compile the Castor XML packages">
        <javac srcdir="${java}" destdir="${classes}" excludes="${excludes}"
               debug="on" encoding="ISO-8859-1" deprecation="${deprecation}"
               includes="${castor.xml.files}">
            <classpath refid="build.classpath"/>
        </javac>
        <copy todir="${classes}">
            <fileset dir="${java}">
                <patternset refid="support.files" />
            </fileset>
            <fileset dir="${main.resources}">
                <patternset refid="support.files" />
            </fileset>
        </copy>
    </target>

    <target name="compile.jdo" depends="prepare,compile.commons,compile.xml"
            description="Compile the Castor JDO packages">
        <javac srcdir="${java}" destdir="${classes}" excludes="${excludes}"
               debug="on" encoding="ISO-8859-1" deprecation="${deprecation}"
               includes="${castor.jdo.files}">
            <classpath refid="build.classpath"/>
        </javac>
        <copy todir="${classes}">
            <fileset dir="${java}">
                <patternset refid="support.files" />
            </fileset>
            <fileset dir="${main.resources}">
                <patternset refid="support.files" />
            </fileset>
        </copy>
        <replace dir="${classes}" token="$$VERSION$$" value="${version}">
            <include name="**/*.xsd" />
            <include name="**/*.xml" />
            <include name="**/*.properties" />
            <include name="**/*.dtd" />
        </replace>
        <replace dir="${classes}" token="$$RELEASE$$" value="${release}">
            <include name="**/*.xsd" />
            <include name="**/*.xml" />
            <include name="**/*.properties" />
            <include name="**/*.dtd" />
        </replace>
    </target>

    <target name="all" depends="clean,compile,compile.examples,compile.tests"
            description="Same as the default target, but also calls clean, compile, compile.examples and compile.tests targets"/>

    <target name="main.opt" depends="prepare"
            description="Same as the default target, but with optimization, no debug and no deprecation">
        <javac srcdir="${java}" destdir="${classes}" excludes="${excludes}"
               debug="${main.opt.debug}" encoding="ISO-8859-1" deprecation="off"
               optimize="on">
            <classpath refid="build.classpath"/>
        </javac>
        <copy todir="${classes}">
            <fileset dir="${java}">
                <patternset refid="support.files" />
            </fileset>
            <fileset dir="${main.resources}">
                <patternset refid="support.files" />
            </fileset>
        </copy>
    </target>

    <target name="compile.examples" depends="prepare, compile"
            description="Builds the example packages (including debugging info) and creates the webapp war file for the servlet example">
        <mkdir dir="${build}/examples"/>
        <mkdir dir="${build}/examples/META-INF"/>
        <javac srcdir="${source}/examples" destdir="${build}/examples"
               debug="on" encoding="ISO-8859-1" deprecation="${deprecation}"
               excludes="${exampleexcludes}">
            <classpath refid="build.classpath"/>
        </javac>

        <!-- copy manifest file to expected location -->
        <copy file="${source}/etc/MANIFEST.EXAMPLES.MF" tofile="${build}/examples/META-INF/MANIFEST.MF"/>
        <replace file="${build}/examples/META-INF/MANIFEST.MF" token="$$VERSION$$" value="${version}"/>
        <replace file="${build}/examples/META-INF/MANIFEST.MF" token="$$RELEASE$$" value="${release}"/>

        <copy todir="${build}/examples">
            <fileset dir="${source}/examples">
                <patternset refid="support.files" />
            </fileset>
        </copy>

        <!-- Make a webapp out of the servlet example -->
        <available property="project_jar.present" file="${dist}/${archive.name}.jar" />
        <mkdir dir="${build}/examples/webapp"/>
        <copy todir="${build}/examples/webapp/WEB-INF/classes">
            <fileset dir="${build}/examples">
                <include name="servlet/*.*"/>
                <include name="myapp/*.*"/>
            </fileset>
            <fileset dir="${classes}">
                <exclude name="**" if="project_jar.present"/>
            </fileset>
        </copy>

        <copy todir="${build}/examples/webapp/WEB-INF/lib">
            <fileset dir="${lib}">
                <include name="*.jar"/>
                <exclude name="ant*.jar"/>
                <exclude name="optional*.jar"/>
                <exclude name="junit*.jar"/>
                <exclude name="servlet*.jar"/>
            </fileset>
            <fileset dir="${dist}">
                <include name="${archive.name}.jar" if="project_jar.present"/>
            </fileset>
        </copy>

        <jar jarfile="${build}/examples/webapp-example-${project}.war"
             basedir="${build}/examples/webapp" includes="**"/>
    </target>

    <target name="compile.tests" depends="prepare,compile"
            description="Build the tests packages">

        <!-- create directory for tests in ${build} directory -->
        <mkdir dir="${build}/tests"/>

        <!-- compile tests to ${build}/tests -->
        <javac srcdir="${source}/tests"
               destdir="${build}/tests"
               excludes="${testexcludes}"
               debug="on"
               encoding="ISO-8859-1"
               deprecation="${deprecation}">
            <classpath refid="build.classpath"/>
        </javac>

        <!-- copy resource files to ${build}/tests -->
        <copy todir="${build}/tests" verbose="${verbose}">
            <fileset dir="${source}/tests">
                <patternset refid="support.files" />
            </fileset>
            <!-- Maven 2: copy resources from src/test/resources -->
            <fileset dir="${test-resources}">
                <patternset refid="support.files" />
            </fileset>
        </copy>
    </target>

    <target name="compile.bugs" depends="prepare,compile" description="Build the tests packages">
        <mkdir dir="${build}/bugs"/>
        <javac srcdir="${source}/bugs" destdir="${build}/bugs"
               debug="on" encoding="ISO-8859-1" deprecation="${deprecation}">
            <classpath refid="build.classpath"/>
        </javac>

        <copy todir="${build}/bugs">
            <fileset dir="${source}/bugs">
                <patternset refid="support.files" />
            </fileset>
        </copy>
    </target>

    <target name="tests" depends="compile.bugs,compile.tests" description="Build the tests packages"/>

    <target name="-test.category.test"
            description="An internal target to test if the test.category property is set">
        <condition property="test.category.present">
            <isset property="test.category" />
        </condition>
    </target>

    <target name="-test.category.isset" depends="-test.category.test" if="test.category.present"
            description="An internal target to check the state of the test.category.present property">
        <echo>Executing test category: ${test.category}</echo>
    </target>

    <target name="-test.category.isnotset" depends="-test.category.test" unless="test.category.present"
            description="An internal target to check the state of the test.category.present property">
        <fail>
        -
        +-------------------------------------------------------------------------------
        | FAILURE CAUSE: Please set the test.category property to the test(s) to execute.
        |                (examples: -Dtest.category=castor.mysql
        |                        or -Dtest.category=castor.mysql.TC01)
        +-------------------------------------------------------------------------------
        </fail>
    </target>

    <target name="jdo.tests" depends="compile.tests, -test.category.isset, -test.category.isnotset"
            description="Executes the JUnit tests for Castor JDO">
        <java classname="MainApp" classpathref="build.classpath" fork="true">
            <arg line="-verbose ${test.category}" />
        </java>
    </target>

    <target name="jar.all" depends="release,srcgen.anttask.jar,jar.jdotests"
            description="An alias to call the release and jar.jdotests targets"/>

    <target name="jar.jdotests" depends="compile.tests" description="Creates a JAR file of the JDO tests">
        <delete file="${dist}/${archive.name}-tests.jar"/>

        <copy todir="${build}/tests">
            <fileset dir="${source}/etc" includes="MANIFEST.MF" />
        </copy>

        <jar jarfile="${dist}/${archive.name}-tests.jar" basedir="${build}/tests"
             manifest="${build}/tests/MANIFEST.MF"
             includes="LICENSE,README,jdo/**,harness/**,*"
             excludes="xml" />
    </target>

    <target name="jar.examples" depends="compile.examples"
            description="Creates a JAR file for the JDO examples.">
        <delete file="${dist}/${archive.name}-examples.jar" />
        <delete file="${dist}/${archive.name}-examples-sources.jar" />

        <!-- Create JAR for Castor examples (excl. web application) -->
        <jar jarfile="${dist}/${archive.name}-examples.jar" manifest="${build}/examples/META-INF/MANIFEST.MF">
             <fileset dir="${build}/examples">
                <exclude name="webapp/**" />
                <exclude name="**/*.war"/>
                <exclude name="servlet/**" />
             </fileset>
        </jar>
        <!-- Create JAR for the sources of the Castor examples -->
        <jar jarfile="${dist}/${archive.name}-examples-sources.jar">
            <fileset dir="${basedir}" includes="${source}/examples/**" />
        </jar>
    </target>

    <target name="zip.examples" depends="jar.examples">
      <delete dir="target" />
      <mkdir dir="target" />
      <mkdir dir="target/lib" />
      <copy todir="target">
          <fileset dir="${dist}">
              <include name="${archive.name}-examples.jar" />
          </fileset>
      </copy>
      <copy todir="target/lib">
          <fileset dir="${dist}">
              <include name="${archive.name}.jar" />
          </fileset>
      </copy>
      <copy todir="target/lib">
          <fileset dir="${lib}">
              <include name="commons-logging.jar" />
              <include name="log4j-1.2.8.jar" />
              <include name="xerces-J_1.4.0.jar" />
              <include name="jta1.0.1.jar" />
              <include name="derby-10.1.2.1.jar" />
          </fileset>
      </copy>
      <zip zipfile="${dist}/${archive.name}-examples.zip" basedir="target" includes="**"/>
    </target>

  <!--
    <target name="jar.example.webapp" depends="compile.examples"
            description="Creates a WAR file for JDO example webapp.">
        <delete file="${dist}/${archive.name}-example-webapp.war" />
        <war warfile="${dist}/${archive.name}-example-webapp.war"
             basedir="${build}/examples/webapp"
             webxml="${build}/examples/webapp/WEB-INF/web.xml"
             includes="**"/>
    </target>
    -->

    <target name="srcgen.anttask.jar" depends="compile" description="Build the castor-srcgen-ant-task.jar files">
        <jar jarfile="${dist}/${srcgen.ant.task.name}.jar" basedir="${classes}"
             includes="org/exolab/castor/tools/ant/taskdefs/*,
                       org/exolab/castor/util/Version.class" />
    </target>

    <target name="jar" depends="compile"
        description="Build the castor.jar and castor-xml.jar files">
        <delete file="${dist}/${archive.name}.jar"/>
        <delete file="${dist}/${archive.name}-xml.jar"/>
        <delete file="${dist}/${archive.name}-commons.jar"/>
        <!-- <delete file="${dist}/${archive.name}-sourceGen.jar"/> -->

        <!-- copy and filter MANIFEST file for Castor JDO -->
        <delete file="${classes}/MANIFEST.MF"/>
        <copy file="${source}/etc/MANIFEST.JDO.MF" tofile="${classes}/MANIFEST.MF"/>
        <replace file="${classes}/MANIFEST.MF" token="$$VERSION$$" value="${version}"/>
        <replace file="${classes}/MANIFEST.MF" token="$$RELEASE$$" value="${release}"/>

        <!-- need to find a similar mechanism for filtering Maven 2 for MANIFEST.MF -->

        <!-- create CASTOR JDO JAR -->
        <jar jarfile="${dist}/${archive.name}.jar" basedir="${classes}"
             manifest="${classes}/MANIFEST.MF"
             includes="LICENSE,LICENSE.APACHE2,README,
                       org/**"/>

        <!-- copy and filter MANIFEST file for Castor XML -->
        <delete file="${classes}/MANIFEST.MF" />
        <copy file="${source}/etc/MANIFEST.XML.MF" tofile="${classes}/MANIFEST.MF"/>
        <replace file="${classes}/MANIFEST.MF" token="$$VERSION$$" value="${version}"/>
        <replace file="${classes}/MANIFEST.MF" token="$$RELEASE$$" value="${release}"/>

        <!-- create Castor XML Only Jar -->
        <jar jarfile="${dist}/${archive.name}-xml.jar" basedir="${classes}"
             manifest="${classes}/MANIFEST.MF"
             includes="LICENSE,LICENSE.APACHE2,README,
                       org/castor/messages.properties,
                       org/castor/mapping/**,
                       org/castor/util/**,
                       org/exolab/castor/*,
                       org/exolab/castor/builder/**,
                       org/exolab/castor/core/**,
                       org/exolab/castor/mapping/**,
                       org/exolab/castor/net/**,
                       org/exolab/castor/tools/**,
                       org/exolab/castor/types/**,
                       org/exolab/castor/util/**,
                       org/exolab/castor/xml/**,
                       org/exolab/javasource/**"/>

        <!-- copy and filter MANIFEST file for Castor COMMONS -->
        <delete file="${classes}/MANIFEST.MF" />
        <copy file="${source}/etc/MANIFEST.COMMONS.MF" tofile="${classes}/MANIFEST.MF"/>
        <replace file="${classes}/MANIFEST.MF" token="$$VERSION$$" value="${version}"/>
        <replace file="${classes}/MANIFEST.MF" token="$$RELEASE$$" value="${release}"/>

        <!-- create Castor COMMONS Only Jar -->
        <jar jarfile="${dist}/${archive.name}-commons.jar" basedir="${classes}"
             manifest="${classes}/MANIFEST.MF"
             includes="LICENSE.APACHE2,README,
                       org/castor/cache/**,
                       org/castor/transactionmanager/**,
                       org/castor/messages.properties,
                       org/castor/util/**"/>

        <!-- copy and filter MANIFEST file for Source generator -->
<!--
        <delete   file="${classes}/MANIFEST.MF" />
        <copyfile src="${source}/etc/MANIFEST.SG.MF" dest="${classes}/MANIFEST.MF" />
        <replace  file="${classes}/MANIFEST.MF" token="$$VERSION$$" value="${version}" />
        <replace file="${classes}/MANIFEST.MF" token="$$RELEASE$$" value="${release}"/>
-->
        <!-- create JAR for source generator -->
<!--
        <jar jarfile="${dist}/${archive-name}-sourceGen.jar" basedir="${classes}"
             manifest="${classes}/MANIFEST.MF"
             includes="LICENSE,README"/>
-->
    </target>

    <target name="CTFjar" depends="compile.tests" description="Build the CTF.jar file">
        <delete file="${dist}/CTF-${version}.jar"/>
        <copy todir="${classes}">
            <fileset dir="${source}/etc" includes="MANIFEST.MF" />
        </copy>
        <replace file="${classes}/MANIFEST.MF" token="$$VERSION$$" value="${version}"/>
        <replace file="${classes}/MANIFEST.MF" token="$$RELEASE$$" value="${release}"/>
        <copy todir="${classes}">
            <fileset dir="${source}/etc" includes="LICENSE,README" />
        </copy>
        <jar jarfile="${dist}/CTF-${version}.jar" basedir="${build}/tests"
             manifest="${classes}/MANIFEST.MF" includes="LICENCE,README,org/**"/>
     </target>

    <target name="rss" depends="prepare" description="Copy the RSS feeds">
        <delete dir="${build}/doc/rss" />
        <mkdir dir="${build}/doc/rss" />
        <copy todir="${build}/doc/rss">
           <fileset dir="${source}/rss" includes="*.xml"/>
        </copy>
    </target>

    <target name="doc" depends="prepare" description="Build the HTML docs">
        <delete dir="${build}/doc"/>
        <mkdir dir="${build}/doc"/>

        <style basedir="${doc}" destdir="${build}/doc" style="${doc}/style/exolab.xsl"
               includes="**.xml" excludes="style/**,project.xml" />

        <style basedir="${howto}" destdir="${build}/doc" style="${doc}/style/exolab.xsl"
               includes="**.xml" excludes="style/**,project.xml" />

        <style basedir="${xml-howto}" destdir="${build}/doc" style="${doc}/style/exolab.xsl"
               includes="**.xml" excludes="style/**,project.xml" />

        <copy todir="${build}/doc">
           <fileset dir="${doc}" includes="license.txt,document.dtd,*.pdf"/>
        </copy>
        <copy todir="${build}/doc">
           <fileset dir="${java}/org/exolab/castor/mapping" includes="mapping.dtd,mapping.xsd"/>
        </copy>
        <copy todir="${build}/doc">
           <fileset dir="${java}/org/exolab/castor/builder/binding" includes="binding.xsd"/>
        </copy>
        <copy todir="${build}/doc/images">
           <fileset dir="${doc}/images" />
        </copy>
        <copy todir="${build}/doc/images">
           <fileset dir="${doc}/style/images" includes="*.gif"/>
        </copy>
        <copy todir="${build}/doc/">
           <fileset dir="${doc}/style" includes="*.css"/>
        </copy>

        <replace dir="${build-doc}" token="$$VERSION$$" value="${version}">
           <include name="index.html"/>
           <include name="download.html" />
        </replace>
        <replace dir="${build-doc}" token="$$RELEASE$$" value="${release}">
           <include name="index.html"/>
           <include name="download.html" />
        </replace>
        <replace dir="${build-doc}" token="$$RELEASE_DATE$$" value="${release_date}">
           <include name="index.html"/>
           <include name="download.html" />
        </replace>
        <replace dir="${build-doc}" token="$$STABLE_VERSION$$" value="${stable_version}">
           <include name="index.html"/>
           <include name="download.html" />
        </replace>
        <replace dir="${build-doc}" token="$$STABLE_RELEASE$$" value="${stable_release}">
           <include name="index.html"/>
           <include name="download.html" />
        </replace>
        <replace dir="${build-doc}" token="$$STABLE_RELEASE_DATE$$" value="${stable_release_date}">
           <include name="index.html"/>
           <include name="download.html" />
        </replace>
        <!-- SPRING XML -->
        <replace dir="${build-doc}" token="$$SPRING-XML-STABLE$$" value="${spring-xml-stable}">
           <include name="index.html"/>
           <include name="download.html" />
        </replace>
        <replace dir="${build-doc}" token="$$SPRING-XML-SNAPSHOT$$" value="${spring-xml-snapshot}">
           <include name="index.html"/>
           <include name="download.html" />
        </replace>
        <!-- SPRING JDO -->
        <replace dir="${build-doc}" token="$$SPRING-JDO-STABLE$$" value="${spring-jdo-stable}">
           <include name="index.html"/>
           <include name="download.html" />
        </replace>
        <replace dir="${build-doc}" token="$$SPRING-JDO-SNAPSHOT$$" value="${spring-jdo-snapshot}">
           <include name="index.html"/>
           <include name="download.html" />
        </replace>

        <replace dir="${build-doc}" token="$$RELEASE_DATE$$" value="${release_date}">
           <include name="index.html"/>
        </replace>

        <mkdir dir="${build}/doc/ora-mar-2k"/>

        <copy todir="${build}/doc/ora-mar-2k">
            <fileset dir="${doc}/ora-mar-2k" />
        </copy>
    </target>

    <target name="javadoc" depends="prepare" description="Build the full javadocs">
        <mkdir dir="${build}/doc"/>
        <mkdir dir="${build}/doc/javadoc"/>
        <javadoc sourcepath="${java}" destdir="${build}/doc/javadoc" doctitle="${name} JavaDoc"
                 windowtitle="${name} JavaDoc" bottom="${copyright}" package="true" author="true"
                 version="true" noindex="true" packagenames="${allpackagenames}"
                 classpathref="javadoc.classpath"/>
    </target>

    <target name="api" depends="prepare" description="Build the public API javadocs">
        <mkdir dir="${build}/doc"/>
        <mkdir dir="${build}/doc/api"/>
        <javadoc sourcepath="${java}" destdir="${build}/doc/api" doctitle="${name} API"
                 windowtitle="${name} API" bottom="${copyright}" public="true" author="true"
                 packagenames="${apipackagenames}" classpathref="javadoc.classpath"/>
    </target>

    <target name="docs" depends="doc,api,javadoc,rss" description="Build the HTML docs, full and API javadocs">
        <zip zipfile="${dist}/${archive.name}-doc.zip" basedir="${build}" includes="doc/**"/>
        <tar tarfile="${dist}/${archive.name}-doc.tar" basedir="${build}" includes="doc/**"/>
        <gzip src="${dist}/${archive.name}-doc.tar" zipfile="${dist}/${archive.name}-doc.tgz"/>
        <delete file="${dist}/${archive.name}-doc.tar"/>
    </target>

    <target name="source" depends="prepare" description="Build the source distributions (tarball and zip archive.names)">
        <delete file="${dist}/${archive.name}-src.tgz"/>
        <delete file="${dist}/${archive.name}-src.zip"/>
        <delete dir="${build}/${archive.name}"/>

        <mkdir dir="${build}/${archive.name}"/>
        <mkdir dir="${build}/${archive.name}/src"/>
        <mkdir dir="${build}/${archive.name}/lib"/>
        <mkdir dir="${build}/${archive.name}/bin"/>

        <!-- <copydir src="${source}" dest="${build}/${archive.name}/src" defaultexcludes="true"/> -->
        <copy todir="${build}/${archive.name}/src">
          <fileset dir="${source}" />
        </copy>
        <copy todir="${build}/${archive.name}/lib">
          <fileset dir="${lib}" excludes="jconn2.jar"/>
        </copy>
        <copy todir="${build}/${archive.name}/bin">
          <fileset dir="./bin" includes="*.sh,*.bat"/>
        </copy>

        <tar includes="${archive.name}/**" basedir="${build}" tarfile="${dist}/${archive.name}-src.tar"/>
        <gzip src="${dist}/${archive.name}-src.tar" zipfile="${dist}/${archive.name}-src.tgz"/>
        <delete file="${dist}/${archive.name}-src.tar"/>
        <zip zipfile="${dist}/${archive.name}-src.zip" basedir="${build}" includes="${archive.name}/**"/>
    </target>

    <target name="release" depends="clean,jar,jar.examples,srcgen.anttask.jar,source,docs,tarball,zip.examples"
            description="An alias to call the clean, jar, source, docs and tarball targets"/>

    <target name="tarball" depends="prepare,doc,jar,srcgen.anttask.jar"
            description="Build the binary distrutions (tarball and zip archive.names)">
        <delete file="${dist}/${archive.name}.tgz"/>
        <delete file="${dist}/${archive.name}.zip"/>
        <delete dir="${build}/${archive.name}"/>
        <mkdir dir="${build}/${archive.name}"/>
        <copy todir="${build}/${archive.name}">
            <fileset dir="${etc}" includes="README,LICENSE,CHANGELOG,sourceGen*"/>
        </copy>
        <copy todir="${build}/${archive.name}">
            <fileset dir="${dist}" includes="${archive.name}.jar,${archive.name}-xml.jar,${srcgen.ant.task.name}.jar"/>
        </copy>
        <copy todir="${build}/${archive.name}">
            <fileset dir="${lib}" includes="jdbc-se2.0.jar,jndi.jar,jta1.0.1.jar,xerces.jar,ldapjdk.jar,xslp.jar"/>
        </copy>
        <copy todir="${build}/${archive.name}/schema">
            <fileset dir="${schema}" />
        </copy>
        <copy todir="${build}/${archive.name}/doc">
            <fileset dir="${build}/doc" />
        </copy>

        <delete dir="${build}/${archive.name}/doc/javadoc"/>
        <tar tarfile="${build}/${archive.name}/examples.tar" basedir="${source}"
             includes="examples/**" defaultexcludes="true"/>
        <gzip src="${build}/${archive.name}/examples.tar" zipfile="${build}/${archive.name}/examples.tgz"/>
        <tar tarfile="${dist}/${archive.name}.tar" basedir="${build}" includes="${archive.name}/**"
             excludes="${archive.name}/*.tar,${archive.name}/*.zip"/>
        <gzip src="${dist}/${archive.name}.tar" zipfile="${dist}/${archive.name}.tgz"/>
        <delete file="${dist}/${archive.name}.tar"/>
        <zip zipfile="${build}/${archive.name}/examples.zip" basedir="${source}"
             includes="examples/**" defaultexcludes="true"/>
        <zip zipfile="${dist}/${archive.name}.zip" basedir="${build}" includes="${archive.name}/**"
             excludes="${archive.name}/*.tar,${archive.name}/*.tgz"/>
    </target>

    <target name="oes" depends="prepare,compile" description="Call the XSDCompiler (org.exolab.castor.tools.XSDCompiler)">
        <ant antfile="${source}/xsdcomp.xml" target="xsdcomp">
            <property name="schema" value="${source}/examples/oes/imports.xsd"/>
            <property name="package" value="oes.imports"/>
            <property name="dest" value="${build}/examples/oes"/>
        </ant>
    </target>

    <target name="automated_build" depends="jar,compile.tests">
        <!-- this mimics the CTFRun.sh script -->
        <delete includeEmptyDirs="true">
            <fileset dir="build/tests" includes="output/**"/>
        </delete>
        <java classname="org.exolab.castor.tests.framework.CastorTestSuiteRunner"
              failonerror="true" fork="yes">
            <arg line="-verbose -printStack -text src/tests/MasterTestSuite"/>
            <classpath>
                <fileset dir="lib">
                    <include name="**/*.jar"/>
                </fileset>
                <pathelement path="build/classes"/>
                <pathelement path="build/tests"/>
            </classpath>
        </java>
    </target>

    <target name="gen.jdo.conf" depends="jar,srcgen.anttask.jar"
        description="Use the Source Generator to create the Java classes for jdo-conf.xsd">
        <delete dir="${gen.src}/jdo-conf"/>
        <mkdir dir="${gen.src}/jdo-conf"/>
        <taskdef name="castor-srcgen" classname="org.exolab.castor.tools.ant.taskdefs.CastorSourceGenTask"
                 classpathref="build.classpath"/>
        <castor-srcgen file="${main.resources}/org/castor/jdo/conf/jdo-conf.xsd"
                       todir="../${gen.src}/jdo-conf"
                       package="org.castor.jdo.conf"
                       lineseparator="unix"
                       types="j2"
                       warnings="false"/>
        <javac destdir="${classes}" excludes="${excludes}"
               debug="${main.opt.debug}" encoding="ISO-8859-1" deprecation="off"
               optimize="on">
            <src path="${gen.src}" />
            <classpath refid="build.classpath"/>
        </javac>
    </target>

    <target name="gen.mapping" depends="jar,srcgen.anttask.jar"
            description="Use the Source Generator to create the Java classes for mapping.xsd">
        <delete dir="${gen.src}/mapping"/>
        <mkdir dir="${gen.src}/mapping"/>
        <taskdef name="castor-srcgen" classname="org.exolab.castor.tools.ant.taskdefs.CastorSourceGenTask"
                 classpathref="build.classpath"/>
        <castor-srcgen file="${main.resources}/org/exolab/castor/mapping/mapping.xsd"
                       todir="${gen.src}/mapping"
                       package="org.exolab.castor.mapping.xml"
                       lineseparator="unix"
                       bindingfile="${main.resources}/org/exolab/castor/mapping/mapping-binding.xml"
                       types="j2"
                       warnings="true"/>
        <javac destdir="${classes}" excludes="${excludes}"
               debug="${main.opt.debug}" encoding="ISO-8859-1" deprecation="off"
               optimize="on">
            <src path="${gen.src}" />
            <classpath refid="build.classpath"/>
        </javac>
    </target>

    <target name="gen.testdescriptor" depends="jar,srcgen.anttask.jar"
            description="Use the Source Generator to create the Java classes for TestDescriptor.xsd">
        <delete dir="${gen.src}/testdescriptor"/>
        <mkdir dir="${gen.src}/testdescriptor"/>
        <taskdef name="castor-srcgen" classname="org.exolab.castor.tools.ant.taskdefs.CastorSourceGenTask"
                 classpathref="build.classpath"/>
        <castor-srcgen file="${source}/tests/main/org/exolab/castor/tests/framework/TestDescriptor.xsd"
                       todir="${gen.src}/testdescriptor"
                       package="org.exolab.castor.tests.framework.testDescriptor"
                       lineseparator="unix"
                       warnings="true"/>
        <javac destdir="${classes}" excludes="${excludes}"
               debug="${main.opt.debug}" encoding="ISO-8859-1" deprecation="off"
               optimize="on">
            <src path="${gen.src}" />
            <classpath refid="build.classpath"/>
        </javac>
    </target>

</project>
