<?xml version="1.0"?>
<!--
       '$RCSfile: build.xml,v $'
       Copyright: 1997-2002 Regents of the University of California,
                            University of New Mexico, and
                            Arizona State University
        Sponsors: National Center for Ecological Analysis and Synthesis and
                  Partnership for Interdisciplinary Studies of Coastal Oceans,
                     University of California Santa Barbara
                  Long-Term Ecological Research Network Office,
                     University of New Mexico
                  Center for Environmental Studies, Arizona State University
   Other funding: National Science Foundation (see README for details)
                  The David and Lucile Packard Foundation
     For Details: http://knb.ecoinformatics.org/

        '$Author: obrien $'
          '$Date: 2009-02-26 00:16:16 $'
      '$Revision: 1.112 $'

    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 2 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program; if not, write to the Free Software
    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
-->
<project name="eml" default="docs" basedir=".">

    <!-- Allow integration with Git projects -->
    <macrodef name = "git">
        <attribute name = "command" />
        <attribute name = "dir" default = "" />
        <element name = "args" optional = "true" />
        <sequential>
            <echo message = "git @{command}" />
            <exec executable = "git" dir = "@{dir}">
                <arg value = "@{command}" />
                <args/>
            </exec>
        </sequential>
    </macrodef>
    <macrodef name = "git-clone-pull">
        <attribute name = "repository" />
        <attribute name = "dest" />
        <attribute name = "refname" />
        <sequential>
            <git command = "clone">
                <args>
                    <arg value = "@{repository}" />
                    <arg value = "@{dest}" />
                </args>
            </git>
            <git command = "checkout" dir = "@{dest}">
                <args>
                    <arg value = "@{refname}" />
                </args>
            </git>
            <git command = "pull" dir = "@{dest}" >
                <args>
                    <arg value = "@{repository}" />
                    <arg value = "@{refname}" />
                </args>
            </git>
        </sequential>
    </macrodef>

    <macrodef name = "checkout-and-copy">
        <attribute name = "dest" />
        <attribute name = "refname" />
        <attribute name = "target" />
        <attribute name = "xsd" default = "" />

        <sequential>
            <echo>Getting EML from source: @{refname}</echo>
            <git command = "checkout" dir = "@{dest}">
                <args>
                    <arg value = "@{refname}" />
                </args>
            </git>
            <mkdir dir="@{target}" />
            <copy todir="@{target}" filtering="yes">
                <fileset dir="@{dest}/@{xsd}">
                    <include name="*.xsd"/>
                </fileset>
            </copy>
        </sequential>
    </macrodef>

    <target name="config">
        <property file="build.properties"/>
        <!-- User specified properties -->
        <!-- These are properties you'll need to change to install the parser
      servlet on your system. -->
        <!-- where to install the servlet -->
        <!--<property name="servlet.install.dir" value="/var/www/org.ecoinformatics.knb/emlparser"/>-->
        <!--<property name="servlet.install.dir" value="/var/lib/tomcat6/webapps/emlparser"/>-->
        <property name="servlet.install.dir" value="build/emlparser"/>
        <!-- the server the servlet will run on -->
        <property name="server" value="https://knb.ecoinformatics.org"/>
        <!--the servlet context directory-->
        <property name="servletdir" value="emlparser"/>
        <!-- the path to the servlet from the servletdir -->
        <property name="servletpath" value="/emlparser"/>
        <property name="version" value="2.2.0"/>
        <!-- namespaces that the servlet should auto resolve -->

    <!-- LOCAL TEST VALUES -->
    <property name="namespaces"
              value="eml://ecoinformatics.org/eml-2.0.0 ${server}/${servletdir}/schema/eml-2.0.0/eml.xsd
                eml://ecoinformatics.org/eml-2.0.1  ${server}/${servletdir}/schema/eml-2.0.1/eml.xsd
                eml://ecoinformatics.org/eml-2.1.0 ${server}/${servletdir}/schema/eml-2.1.0/eml.xsd
                eml://ecoinformatics.org/literature-2.1.0 ${server}/${servletdir}/schema/eml-2.1.0/eml-literature.xsd
                eml://ecoinformatics.org/project-2.1.0 ${server}/${servletdir}/schema/eml-2.1.0/eml-project.xsd
                eml://ecoinformatics.org/eml-2.1.1 ${server}/${servletdir}/schema/eml-2.1.1/eml.xsd
                eml://ecoinformatics.org/literature-2.1.1 ${server}/${servletdir}/schema/eml-2.1.1/eml-literature.xsd
                eml://ecoinformatics.org/project-2.1.1 ${server}/${servletdir}/schema/eml-2.1.1/eml-project.xsd
                https://eml.ecoinformatics.org/eml-2.2.0 ${server}/${servletdir}/schema/eml-2.2.0/eml.xsd
                http://www.xml-cml.org/schema/stmml-1.1 ${server}/${servletdir}/schema/eml-2.1.0/stmml.xsd
                http://www.xml-cml.org/schema/stmml ${server}/${servletdir}/schema/eml-2.0.1/stmml.xsd" />

        <!-- the path from the tomcat/bin directory to the config.xml file -->
        <property name="servletconfigfile" value="${servlet.install.dir}/lib/config.xml"/>
        <property name="servlettempdir" value="build/emlparser"/>
        <filter token="tempdir" value="${servlettempdir}"/>
        <property environment="env"/>
        <property name="eml.git.repository.url" value="https://github.com/NCEAS/eml.git" />
        <property name="eml-module" value="eml"/>
        <property name="eml2_0_0-tag" value="RELEASE_EML_2_0_0_UPDATE_1"/>
        <property name="eml2_0_1-tag" value="RELEASE_EML_2_0_1"/>
        <property name="eml2_1_0-tag" value="RELEASE_EML_2_1_0"/>
        <property name="eml2_1_1-tag" value="RELEASE_EML_2_1_1"/>
        <property name="eml2_2_0-tag" value="BRANCH_EML_2_2"/>
    </target>

    <target name="init" depends="config">
        <property name="name" value="eml"/>
        <property name="eml-version" value="eml-${version}"/>
        <property name="testdir" value="./src/test/java" />
        <property name="test.resources.dir" value="./src/test/resources" />
        <property name="srcdir" value="./src/main/java" />
        <property name="src.resources.dir" value="./src/main/resources" />
        <property name="invalid.dir" value="${test.resources.dir}/invalidEML"/>
        <property name="build.dir" value="build"/>
        <property name="build.tests" value="${build.dir}/tests"/>
        <property name="build.src" value="${build.dir}/src"/>
        <property name="build.dest" value="${build.dir}/classes"/>
        <property name="build.docs" value="${build.dir}/docs"/>
        <property name="build.javadocs" value="${build.dir}/javadocs"/>
        <property name="build.stripped" value="stripped"/>
        <property name="build.emlgit" value="${build.dir}/emlgit"/>
        <property name="style.dir" value="./style"/>
        <property name="config.file" value="${src.resources.dir}/config.xml"/>

        <property name="xmlp" value="lib/xercesImpl-2.12.0.jar"/>
        <property name="xml-apis" value="lib/xml-apis-1.4.01.jar"/>

        <property name="serializer" value="lib/serializer-2.7.2.jar"/>
        <property name="xalan" value="lib/xalan-2.7.2.jar"/>
        
        <property name="itext" value="lib/iText-2.0.8.jar"/>
        <property name="renderer" value="lib/core-renderer.jar"/>
        <property name="renderer-min" value="lib/core-renderer-minimal.jar"/>
        <property name="jtidy" value="lib/jtidy-r938.jar"/>
        <property name="io" value="lib/commons-io-2.0.jar"/>
        <property name="jdom" value="lib/jdom.jar"/>
        <property name="cos" value="lib/cos.jar"/>
        <property name="servlet" value="lib/apache/servlet.jar"/>

        <property name="junit" value="lib/junit.jar"/>
        <property name="utilities" value="lib/utilities.jar"/>


        <property name="htmldocbook-style"
        value="style/docbook-xsl-1.50.0/html/docbook.xsl"/>
        <filter token="server" value="https://knb.ecoinformatics.org"/>
        <filter token="docrooturl" value=""/>
        <filter token="version" value="${version}"/>
        <filter token="eml-version" value="${eml-version}"/>
        <filter token="testdir" value="${test.resources.dir}" />
        <filter token="srcdir" value="${srcdir}" />
        <filter token="invalid.dir" value="${invalid.dir}" />
        <filter token="config.file" value="${config.file}" />
        <filter token="namespaces" value="${namespaces}"/>
        <filter token="servletconfigfile" value="${servletconfigfile}"/>
        <filter token="server" value="${server}"/>
        <filter token="servletdir" value="${servletdir}"/>
        <filter token="servletpath" value="${servletpath}"/>

        <property name="release.dir" value="./release"/>
        <property name="ver.dir" value="${release.dir}/eml-${version}"/>
        <property name="ver.lib" value="${ver.dir}/lib"/>
        <property name="ver.docs" value="${ver.dir}/docs"/>
        <property name="ver.src" value="${ver.dir}/src"/>
        <property name="ver.tst" value="${ver.dir}/test"/>
        <property name="package.home" value="org/ecoinformatics" />
        <property name="cpath" value="${utilities}:${servlet}:${cos}:${xalan}:${xml-apis}:${io}:${xmlp}:${serializer}:${jtidy}:${itext}:${renderer}:${renderer-min}:${jdom}:${junit}:${build.dir}/${name}.jar"/>

        <!-- These two Data Manager Library properties need to be declared here
         so that the Data Manager Library can be excluded from the default eml
         distribution. Other Data Manager properties are declared in
         the init-datamanager-lib target below. -->
        <property name="datamanager.dir" value="org/ecoinformatics/datamanager"/>
        <property name="datamanager.name" value="datamanager"/>

        <mkdir dir="${build.docs}/eml-${version}"/>

    </target>


    <target name="dist" depends="init">
        <mkdir dir="${release.dir}"/>
        <delete dir="${ver.dir}"/>
        <mkdir dir="${ver.dir}"/>
        <mkdir dir="${ver.lib}"/>
        <mkdir dir="${ver.src}"/>
        <mkdir dir="${ver.tst}"/>
<!--        <mkdir dir="${ver.dir}/style"/> -->
        <copy file="./build.xml" todir="${ver.dir}"/>
        <copy file="./LICENSE" todir="${ver.dir}"/>
        <copy file="./README.md" todir="${ver.dir}"/>
        <copy todir="${ver.dir}" filtering="no">
            <fileset dir=".">
                <include name="*.xsd"/>
                <include name="xsd/*.xsd"/>
                <include name="eml-unitDictionary.xml"/>
                <include name="eml-spatialReferenceDictionary.xml"/>
            </fileset>
        </copy>
        <copy todir="${ver.lib}" filtering="no">
            <fileset dir="./lib">
                <exclude name="${datamanager.name}/**"/>
            </fileset>
        </copy>
        <copy todir="${ver.src}" filtering="yes">
            <fileset dir="${srcdir}">
                <exclude name="emlconversions/**"/>
                <exclude name="${datamanager.dir}/**"/>
            </fileset>
        </copy>
        <copy todir="${ver.tst}" filtering="yes">
            <fileset dir="./test">
                <exclude name="${datamanager.dir}/**"/>
            </fileset>
        </copy>

        <delete file="${release.dir}/eml-${version}.zip"/>
        <zip zipfile="${release.dir}/eml-${version}.zip" basedir="${release.dir}"/>
        <delete file="${release.dir}/eml-${version}.tar.gz"/>
        <tar tarfile="${release.dir}/eml-${version}.tar" basedir="${release.dir}"/>
        <gzip zipfile="${release.dir}/eml-${version}.tar.gz" src="${release.dir}/eml-${version}.tar"/>
        <delete file="${release.dir}/eml-${version}.tar"/>
    </target>

    <target name="buildenumerations" depends="init">
        <style basedir="." style="getunits.xsl"
           in="eml-unitDictionary.xml"
           out="${build.docs}/eml-${version}/enumerations.xml"
           classpath="${cpath}" processor="trax"/>
        <echo>
      ************************************************
                    enumerations created.
                  see docs/eml-${version}/enumerations.xml
      ************************************************
    </echo>
    </target>

    <target name="compile" depends="init">
        <mkdir dir="${build.tests}"/>
        <mkdir dir="${build.dest}"/>
        <copy todir="${build.tests}" filtering="yes">
            <fileset dir="${testdir}">
                <exclude name="**/CVS*"/>
                <exclude name="**/.#*"/>
                <exclude name="${datamanager.dir}/**"/>
                <exclude name="emlconversions/**"/>
            </fileset>
        </copy>

        <echo>
      ************************************************
                    copied some stuff to ${build.tests}
      ************************************************
    </echo>
        <copy todir="${build.tests}" filtering="yes">
            <fileset dir="${srcdir}">
                <exclude name="**/CVS*"/>
                <exclude name="**/.#*"/>
                <exclude name="${datamanager.dir}/**"/>
                <exclude name="emlconversions/**"/>
            </fileset>
        </copy>
        <copy file ="${config.file}" todir="${build.dest}" filtering="yes"/>
        <javac srcdir="${build.tests}"
            destdir="${build.dest}"
            classpath="${cpath}"
            debug="on"/>
    </target>

    <target name="jar" depends="compile">
        <jar jarfile="${build.dir}/${name}.jar"
         basedir="${build.dest}"
         includes="${package.home}/** config.xml"
         excludes="${datamanager.dir}/**" />
        <copy file="${build.dir}/${name}.jar" tofile="lib/${name}.jar"/>
    </target>



    <target name="compile-test" depends="jar">
        <!-- copy and compile the tests into a jar file -->
        <mkdir dir="${build.tests}"/>
        <mkdir dir="${build.dest}"/>
        <copy todir="${build.tests}" filtering="yes">
            <fileset dir="${testdir}">
                <exclude name="**/CVS*"/>
                <exclude name="**/.#*"/>
                <exclude name="${datamanager.dir}/**"/>
                <exclude name="emlconversions/**"/>
            </fileset>
        </copy>
        <javac srcdir="${build.tests}"
            destdir="${build.dest}"
            classpath="${cpath}"
            debug="on"/>

        <jar jarfile="${build.dir}/${name}-test.jar" basedir="${build.dest}"
          includes="${package.home}/${name}test/**" />

    </target>

    <!-- use the ant "junit" task to run JUnit tests. -->
    <target name="test" depends="compile-test">
        <!--copy the unit dictionary so it will get validated-->
        <copy file="eml-unitDictionary.xml" tofile="test/eml-unitDictionary.xml"/>
    <echo>
         ************************************************
            copied the unitDictionary
      ************************************************
    </echo>

        <!-- use the ant "junit" task to run JUnit tests. -->
        <junit printsummary="yes" haltonfailure="no" fork="no" haltonerror="no" failureproperty="test.failed">
            <classpath>
                <pathelement path="${cpath}:${build.dir}/${name}-test.jar:${build.dir}/${name}.jar" />
            </classpath>

            <formatter type="plain" usefile="false"/>
            <env key="EML_VERSION" value="${version}"/>

            <batchtest fork="yes" todir="${build.dir}">
                <fileset dir="${build.tests}">
                    <include name="**/*Test.java" />
                    <exclude name="${datamanager.dir}/**" />
                </fileset>
            </batchtest>
        </junit>
        <fail message="Test failure detected, check test results." if="test.failed" />
    </target>

    <target name="emlparsertest" depends="jar">
        <junit printsummary="yes" haltonfailure="no" fork="no"
            haltonerror="no">
            <classpath>
                <pathelement path="${cpath}:${build.dir}/${name}-test.jar:${build.dir}/${name}.jar" />
            </classpath>

            <formatter type="plain" />

            <batchtest fork="yes" todir="${build.dir}">
                <fileset dir="${build.tests}">
                    <include name="**/EMLParserTest.java" />
                </fileset>
            </batchtest>
        </junit>
    </target>

    <target name="runonetest" depends="jar">
        <!-- Prompt user for the test name. -->
            <input
             message="Please enter name of test to run: "
             addproperty="testtorun"
             defaultvalue="HtmlToPdfTest"
          />
        <junit printsummary="yes" haltonfailure="no" fork="no"
            haltonerror="no">
            <classpath>
                <pathelement path="${cpath}:${build.dir}/${name}-test.jar:${build.dir}/${name}.jar" />
            </classpath>

            <formatter type="plain" />

            <batchtest fork="yes" todir="${build.dir}">
                <fileset dir="${build.tests}">
                    <include name="**/${testtorun}.java" />
                </fileset>
            </batchtest>
        </junit>
    </target>

    <target name="-check-clone" unless="clone.exists">
        <available property="clone.exists" file="${build.emlgit}"/>
    </target>

    <target name="clone-eml" depends="-check-clone" unless="clone.exists">
        <git-clone-pull repository="${eml.git.repository.url}" dest="${build.emlgit}" refname="${eml2_0_0-tag}" />
        <available property="clone.exists" file="${build.emlgit}"/>
    </target>

    <target name="servletinstall" depends="jar, clone-eml" if="${clone.exists}">
        <copy file="lib/emlparser.html" tofile="${servlet.install.dir}/index.html"/>
        <copy file="src/test/resources/eml-sample.xml"
          tofile="${servlet.install.dir}/eml-sample.xml"/>
        <copy file="${config.file}" tofile="${servlet.install.dir}/lib/config.xml" filtering="yes"/>
        <copy file="lib/web.xml" tofile="${servlet.install.dir}/WEB-INF/web.xml"/>
        <copy file="${cos}" tofile="${servlet.install.dir}/WEB-INF/lib/cos.jar"/>
        <copy file="lib/eml.jar"
          tofile="${servlet.install.dir}/WEB-INF/lib/eml.jar"/>
        <copy file="${xalan}"
          tofile="${servlet.install.dir}/WEB-INF/lib/xalan.jar"/>
        <copy file="${xml-apis}"
          tofile="${servlet.install.dir}/WEB-INF/lib/xml-apis.jar"/>
        <copy file="${xmlp}"
          tofile="${servlet.install.dir}/WEB-INF/lib/xercesImpl.jar"/>
        <copy file="${utilities}"
          tofile="${servlet.install.dir}/WEB-INF/lib/utilities.jar"/>

        <!-- Copy eml-2.0.0 schema. Add code here for copying any other schemas. -->
        <checkout-and-copy dest = "${build.emlgit}" refname = "${eml2_0_0-tag}" target = "${servlet.install.dir}/schema/eml-2.0.0" />

        <!-- Copy eml-2.0.1 schema. Add code here for copying any other schemas. -->
        <checkout-and-copy dest = "${build.emlgit}" refname = "${eml2_0_1-tag}" target = "${servlet.install.dir}/schema/eml-2.0.1" />

        <!-- Copy eml-2.1.0 schema. Add code here for copying any other schemas. -->
        <checkout-and-copy dest = "${build.emlgit}" refname = "${eml2_1_0-tag}" target = "${servlet.install.dir}/schema/eml-2.1.0" />

        <!-- Copy eml-2.1.1 schema. Add code here for copying any other schemas. -->
        <checkout-and-copy dest = "${build.emlgit}" refname = "${eml2_1_1-tag}" target = "${servlet.install.dir}/schema/eml-2.1.1" />

        <!-- Copy eml-2.2.0 schema. Add code here for copying any other schemas. -->
        <checkout-and-copy dest = "${build.emlgit}" refname = "${eml2_2_0-tag}" target = "${servlet.install.dir}/schema/eml-2.2.0" xsd="xsd" />

    </target>

    <target name="emlparser_war" depends="servletinstall">
        <mkdir dir="${release.dir}" />
        <war destfile="${release.dir}/${servletdir}.war"
            webxml="${servlet.install.dir}/WEB-INF/web.xml">
            <fileset dir="${servlet.install.dir}" />
            <lib dir="${servlet.install.dir}/WEB-INF/lib" />
            <webinf dir="${servlet.install.dir}/WEB-INF" />
        </war>

    </target>

    <target name="clean" depends="init">
        <delete dir="./build"/>
        <delete file="${eml-version}.zip"/>
        <delete file="${eml-version}.tar.gz"/>
        <delete file="${datamanager.name}.zip"/>
        <delete file="${datamanager.name}.tar.gz"/>
        <delete file="${servlet.install.dir}/WEB-INF/lib/eml.jar"/>
    </target>

    <!--
        The following set of targets support the Data Manager library:

        init-datamanager-lib
        compile-datamanager-lib
        jar-datamanager-lib
        dist-datamanager-lib
        run-datamanager-one
        test-datamanager-init (used internally only)
        test-datamanager-all
        test-datamanager-one
        javadoc-datamanager-lib

        Applications can use this library's API to manage EML data (as well as
        other types of data). The library is currently housed under the 'eml'
        module in SVN. At some point in the future, it may be broken out into its
        own module.
    -->

    <target name="init-datamanager-lib" depends="init">
        <property name="datamanager.lib" value="lib/datamanager"/>
        <property name="version.datamanager" value="1.0.0"/>
        <property name="datamanager-version" value="${datamanager.name}-${version.datamanager}"/>
        <property name="ver.dir.datamanager" value="${release.dir}/${datamanager-version}"/>
        <property name="ver.docs.datamanager" value="${ver.dir.datamanager}/docs"/>
        <property name="ver.lib.datamanager" value="${ver.dir.datamanager}/${datamanager.lib}"/>
        <property name="ver.src.datamanager" value="${ver.dir.datamanager}/src"/>

        <!-- Used by 'test-datamanager-one' target. User is prompted for the name
             of the test to run. If user enters no value, runs this test by
             default. -->
        <property name="default-datamanager-test" value="DataManagerTest" />
        <property name="default-datamanager-run" value="org.ecoinformatics.datamanager.util.TableGenerator" />

        <property name="axis" value="${datamanager.lib}/axis.jar"/>
        <property name="discover" value="${datamanager.lib}/commons-discovery.jar"/>
        <property name="ftp" value="${datamanager.lib}/commons-net-3.3.jar"/>
        <property name="hsql" value="${datamanager.lib}/hsqldb.jar"/>
        <property name="log" value="${datamanager.lib}/commons-logging.jar"/>
        <property name="log4j" value="${datamanager.lib}/log4j-1.2.8.jar"/>
        <property name="queryservice" value="${datamanager.lib}/org.ecoinformatics.ecogrid.QueryService-stub.jar"/>
        <property name="authenticatedqueryservice" value="${datamanager.lib}/org.ecoinformatics.ecogrid.AuthenticatedQueryService-stub.jar"/>
        <property name="authenticationservice" value="${datamanager.lib}/org.ecoinformatics.ecogrid.AuthenticationService-stub.jar"/>
        <property name="putservice" value="${datamanager.lib}/org.ecoinformatics.ecogrid.PutService-stub.jar"/>
        <!-- <property name="postgresql-driver" value="${datamanager.lib}/postgresql-8.0-312.jdbc3.jar"/> -->
        <property name="postgresql-driver" value="${datamanager.lib}/postgresql-8.3-606.jdbc3.jar"/>
        <property name="rpc" value="${datamanager.lib}/jaxrpc.jar"/>
        <property name="saaj" value="${datamanager.lib}/saaj.jar"/>
        <property name="soap" value="${datamanager.lib}/soap.jar"/>
        <property name="tar" value="${datamanager.lib}/tar.jar"/>
        <property name="wsdl" value="${datamanager.lib}/wsdl4j.jar"/>

        <property name="cpath.datamanager"
            value="${junit}:${axis}:${discover}:${ftp}:${hsql}:${log}:${log4j}:${postgresql-driver}:${queryservice}:${authenticatedqueryservice}:${authenticationservice}:${putservice}:${rpc}:${saaj}:${soap}:${tar}:${utilities}:${wsdl}:${io}:${xalan}:${xml-apis}"/>
    </target>

    <target name="compile-datamanager-lib" depends="init-datamanager-lib,compile">
        <mkdir dir="${build.dest}"/>
        <mkdir dir="${build.src}"/>
        <copy todir="${build.src}" filtering="yes">
            <fileset dir="${srcdir}">
                <include name="${datamanager.dir}/**"/>
                <exclude name="emlconversions/**"/>
                <exclude name="org/ecoinformatics/eml/**"/>
                <exclude name="**/CVS*"/>
                <exclude name="**/.#*"/>
            </fileset>
        </copy>
        <copy file="${src.resources.dir}/datamanager.properties" todir="${build.dest}" />
        <copy file="${src.resources.dir}/endpoint.properties" todir="${build.dest}" />
        <echo>"cpath.datamanager = ${cpath.datamanager}"</echo>
        <javac srcdir="${build.src}"
                  destdir="${build.dest}"
                  classpath="${cpath.datamanager}"
                  debug="on"/>
    </target>

    <target name="jar-datamanager-lib" depends="clean,compile-datamanager-lib">
        <jar jarfile="${build.dir}/${datamanager.name}.jar"
               basedir="${build.dest}"
               excludes="org/ecoinformatics/**/**Test.class"
          />
    </target>

    <target name="dist-datamanager-lib"
            depends="jar-datamanager-lib,javadoc-datamanager-lib">
        <mkdir dir="${release.dir}"/>
        <delete dir="${ver.dir}"/>
        <delete dir="${ver.dir.datamanager}"/>
        <mkdir dir="${ver.dir.datamanager}"/>
        <mkdir dir="${ver.dir.datamanager}/lib/apache"/>
        <mkdir dir="${ver.dir.datamanager}/lib/sample"/>
        <mkdir dir="${ver.lib.datamanager}"/>
        <mkdir dir="${ver.docs.datamanager}"/>
        <mkdir dir="${ver.src.datamanager}/${datamanager.dir}"/>
        <copy file="./build.properties" todir="${ver.dir.datamanager}"/>
        <copy file="./build.xml" todir="${ver.dir.datamanager}"/>
        <!--
        <copy file="./docs/datamanager/LICENSE" todir="${ver.dir.datamanager}"/>
        <copy file="./docs/datamanager/README" todir="${ver.dir.datamanager}"/>
        -->

        <!-- Copy datamanager jar file to the top-level
             distribution directory -->
        <copy file="${build.dir}/${datamanager.name}.jar"  filtering="no"
                todir="${ver.dir.datamanager}"/>

        <!-- Copy datamanager documents, excluding project management, to
             the distribution documents directory -->
        <copy todir="${ver.docs.datamanager}" filtering="no">
            <fileset dir="docs/${datamanager.name}">
                <exclude name="projectManagement/**"/>
            </fileset>
        </copy>

        <!-- Copy datamanager javadocs to the distribution documents directory -->
        <mkdir dir="${ver.docs.datamanager}/javadocs" />
        <copy todir="${ver.docs.datamanager}/javadocs" filtering="no">
            <fileset dir="${build.javadocs}">
            </fileset>
        </copy>

        <!-- Copy datamanager jar files and properties file to
             the distribution lib directory -->
        <copy todir="${ver.lib.datamanager}" filtering="no">
            <fileset dir="${datamanager.lib}">
                <exclude name="*.jar"/>
                <include name="datamanager.properties"/>
            </fileset>
        </copy>

        <copy todir="${ver.dir.datamanager}/lib/sample" filtering="no">
            <fileset dir="lib/sample">
                <include name="eml-sample.xml"/>
            </fileset>
        </copy>

        <!-- Copy datamanager source code to the distribution source directory -->
        <copy todir="${ver.src.datamanager}/${datamanager.dir}" filtering="yes">
            <fileset dir="${srcdir}/${datamanager.dir}"/>
        </copy>

        <!-- zip and tar/gzip the datamanager distribution -->
        <delete file="./${datamanager-version}.zip"/>
        <zip zipfile="./${datamanager-version}.zip" basedir="${ver.dir.datamanager}"/>
        <delete file="./${datamanager-version}.tar.gz"/>
        <tar tarfile="./${datamanager-version}.tar" basedir="${ver.dir.datamanager}"/>
        <gzip zipfile="./${datamanager-version}.tar.gz" src="./${datamanager-version}.tar"/>
        <delete file="./${datamanager-version}.tar"/>
    </target>

    <target name="run-datamanager-one" depends="jar-datamanager-lib">
            <!-- Run one class in the data manager library. -->

            <!-- Prompt user for the classname.
               If user enters a null value, use the default-datamanager-test -->
            <input
             message="Please enter name of class to run: "
             addproperty="class-to-run"
             defaultvalue="${default-datamanager-run}"
          />
            <input
                 message="Please enter arguments for the class: "
                 addproperty="class-to-run-args"
                 defaultvalue="tao.1.1 http://knb.ecoinformatics.org/knb/metacat sessionid"
              />

            <!-- run the class -->
            <java classname="${class-to-run}">
                <arg line="${class-to-run-args}"/>
                <classpath>
                    <pathelement path="${cpath.datamanager}:${build.dest}:${srcdir}" />
                </classpath>

            </java>
        </target>

    <target name="test-datamanager-init" depends="compile-datamanager-lib">
        <!-- copy and compile the data manager tests prior to running "junit" -->
        <copy todir="${build.src}" filtering="yes">
            <fileset dir="${testdir}">
                <include name="${datamanager.dir}/**"/>
                <exclude name="emlconversions/**"/>
                <exclude name="org/ecoinformatics/eml/**"/>
                <exclude name="**/CVS*"/>
                <exclude name="**/.#*"/>
            </fileset>
        </copy>
        <javac srcdir="${build.src}"
             destdir="${build.dest}"
             classpath="${cpath.datamanager}"
             debug="on"/>
    </target>

    <target name="test-datamanager-all" depends="test-datamanager-init">
        <!-- use the ant "junit" task to run JUnit tests for data manager lib. -->
        <junit printsummary="yes" haltonfailure="no" fork="yes"
             haltonerror="no">
            <classpath>
                <pathelement path="${cpath.datamanager}:${build.dest}" />
            </classpath>
            <formatter type="plain" />
            <batchtest fork="yes" todir="${build.dir}">
                <fileset dir="${build.src}">
                    <include name="**/*Test.java" />
                </fileset>
            </batchtest>
        </junit>
    </target>

    <target name="test-datamanager-one" depends="test-datamanager-init">
        <!-- Run only one test in the data manager library. -->

        <!-- Prompt user for the test name.
           If user enters a null value, use the default-datamanager-test -->
        <input
         message="Please enter name of test to run: [${default-datamanager-test}]"
         addproperty="test-to-run"
         defaultvalue="${default-datamanager-test}"
      />

        <!-- use the ant "junit" task to run a single test in data manager lib. -->
        <junit printsummary="yes" haltonfailure="no" fork="yes"
             haltonerror="no" showoutput="true" >
            <classpath>
                <pathelement path="${cpath.datamanager}:${build.dest}" />
            </classpath>
            <formatter type="plain" />
            <batchtest fork="yes" todir="${build.dir}">
                <fileset dir="${build.src}">
                    <include name="**/${test-to-run}.java" />
                </fileset>
            </batchtest>
        </junit>
    </target>

    <target name="javadoc-datamanager-lib" depends="compile-datamanager-lib"
                description="Generates javadoc documentation">
        <mkdir dir="${build.javadocs}"/>
        <javadoc packagenames="org.ecoinformatics.datamanager.*"
               sourcepath="${build.src}"
               destdir="${build.javadocs}"
               author="true"
               version="true"
               use="true"
               windowtitle="DataManager API"
               doctitle="&lt;h1&gt;DataManager&lt;/h1&gt;"
               bottom="&lt;i&gt;Copyright &#169; 2007 Regents of the University of California. All Rights Reserved.&lt;/i&gt;">
            <classpath path="${cpath.datamanager}"/>
        </javadoc>
    </target>

    <!-- End of targets for Data Manager library -->

    <target name="kepler-style-jar" depends="init" description="Generates a kepler-styles.jar for Kepler">
       <mkdir dir="${build.dir}/kepler/style/eml-2.1.0"/>
       <mkdir dir="${build.dir}/kepler/style/kepler"/>
       <copy todir="${build.dir}/kepler/style/eml-2.1.0" filtering="yes">
           <fileset dir="style/eml">
                    <include name="*.xsl" />
           </fileset>
       </copy>
        <copy todir="${build.dir}/kepler/style/kepler" filtering="yes">
           <fileset dir="../kepler/core/resources/style">
                    <include name="kepler.css" />
           </fileset>
       </copy>
       <jar jarfile="${build.dir}/kepler/kepler-styles.jar"
         basedir="${build.dir}/kepler"/>
    </target>

</project>