<?xml version="1.0"?>
<project name="ADQLlib" default="cleanInstall" basedir=".">
    <property environment="env"/>
    <property name="lib" value="./lib"/>
    <property name="classes" value="./classes"/>
    <property name="bin" value="./bin"/>
    <property name="dist" value="./dist"/>
    <property name="tmp" value="./tmp"/>
    <property name="adqljar" value="${lib}/adql.jar"/>

    <target name="init">
       <mkdir dir="${classes}"/>
       <mkdir dir="${bin}"/>
       <mkdir dir="${tmp}"/>
    </target>

    <target name="distclean">
       <delete includeEmptyDirs="true">
          <fileset dir="${classes}" />
          <fileset dir="${dist}" />
          <fileset dir="${lib}" >
             <filename name="ivoaregistry.jar" />
          </fileset>
          <fileset dir="${tmp}" />
          <fileset dir="./doc/api" />
          <fileset dir="${bin}" />
       </delete>
    </target>

    <target name="clean">
       <delete includeEmptyDirs="true">
          <fileset dir="${classes}">
             <include name="**" />
             <exclude name="test/**" />
          </fileset>
       </delete>
    </target>

    <target name="cleanInstall" depends="install,clean" />

    <target name="compile" depends="init">
       <javac destdir="${classes}" srcdir="src/java" debug="true"
              includeAntruntime="false">
          <classpath>
            <pathelement path="${java.class.path}"/>
            <pathelement location="${classes}" />
            <pathelement location="${adqljar}" />
            <pathelement location="${lib}/saaj.jar" />
            <pathelement location="${lib}/axis.jar" />
          </classpath>
       </javac>
       <copy todir="${classes}/net/ivoa/registry/search/test">
          <fileset dir="src/java/net/ivoa/registry/search/test">
             <filename name="registry.xml"/>
          </fileset>
          <fileset dir="src/java/net/ivoa/registry/search/test">
             <filename name="GetIdentity.txt"/>
          </fileset>
       </copy>
    </target>

    <target name="jarlib" depends="compile">
       <jar destfile="${lib}/ivoaregistry.jar" basedir="${classes}"/>
    </target>

    <target name="test" depends="jarlib">
       <java classname="net.ivoa.registry.search.test.TestRegistryClient"
             fork="yes">
          <classpath>
            <pathelement path="${java.class.path}"/>
            <pathelement location="${lib}/ivoaregistry.jar" />
            <pathelement location="${adqljar}" />
            <pathelement location="${lib}/saaj.jar" />
            <pathelement location="${lib}/axis.jar" />
            <pathelement location="${lib}/jaxrpc.jar" />
            <pathelement location="${lib}/commons-logging-1.0.4.jar" />
            <pathelement location="${lib}/commons-discovery-0.2.jar" />
            <pathelement location="${lib}/log4j-1.2.8.jar" />
            <pathelement location="${lib}" />
          </classpath>
          <sysproperty key="ivoaregistry.tmpdir" value="${tmp}"/>
       </java>
    </target>

    <target name="apidoc" depends="">
       <javadoc destdir="doc/api" windowtitle="ADQL Library" 
                sourcepath="src/java"
                packagenames="net.*,nvo_coords.*,nvo_regions.*,ncsa.*,test.*" />
    </target>

    <target name="install" depends="jarlib,apidoc">
       <filter token="IVOAREG_HOME" value="${env.PWD}" />
       <copy file="src/scripts/regsearch" todir="${bin}" filtering="true"/>
       <copy file="src/scripts/regsearch.cmd" todir="${bin}" filtering="true"/>
       <chmod perm="a+rx">
          <fileset dir="${bin}" includes="regsearch"/>
       </chmod>
    </target>

</project>
