<?xml version="1.0" encoding="UTF-8"?>

<!-- =====================================================================

 Build file for CsvJdbc. Built using Ant 1.6.1

 Authors: Jonathan Ackerman, Michael Maraya

 CsvJdbc - a JDBC driver for CSV files
 Copyright (C) 2001  Jonathan Ackerman

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

 This library 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
 Lesser General Public License for more details.

 You should have received a copy of the GNU Lesser General Public
 License along with this library; if not, write to the Free Software
 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA

====================================================================== -->

<project name="CsvJdbc" default="main">

  <description>
    Jakarta-Ant build file for CSVJDBC
  </description>

  <!-- =================================================================== -->
  <!-- Project-wide properties and paths                                   -->
  <!-- =================================================================== -->
  <property name="TALK" value="false" />
  <property name="name" value="csvjdbc"/>
  <property name="rel" value="1.0-36"/>
  <property name="rel.name" value="${name}-${rel}"/>
  <property name="build.dir" value="../build"/>
  <property name="src.dir" value="../src"/>
  <property name="java.dir" value="${src.dir}/main/java"/>
  <property name="javacc.dir" value="${src.dir}/main/javacc"/>
  <property name="javacc.home" value="/opt/javacc"/>
  <property name="resources.dir" value="${src.dir}/main/resources"/>
  <property name="test.java.dir" value="${src.dir}/test/java"/>
  <property name="doc.dir" value="${src.dir}/doc"/>
  <property name="lib.dir" value="../lib"/>
  <property name="class.dir" value="../target/classes"/>
  <property name="test.class.dir" value="../target/test-classes"/>
  <property name="javadoc.dir" value="../javadoc"/>
  <property name="rel.dir" value="../target"/>
  <property name="junit.dir" value="/usr/share/java"/>
  <property name="jar.file" value="${rel.dir}/${rel.name}.jar"/>
  <property name="test.reports" value="../reports" /> 
  <path id="classpath">
    <pathelement path="."/>
    <pathelement path="${class.dir}"/>
    <fileset dir="${lib.dir}">
      <include name="**/*.jar"/>
    </fileset>
  </path>
  <path id="test.classpath">
    <path refid="classpath"/>
    <fileset dir="${junit.dir}" erroronmissingdir="false">
      <include name="junit*.jar"/>
    </fileset>
    <pathelement path="${class.dir}"/>
    <pathelement path="${test.class.dir}"/>
  </path>

  <!-- =================================================================== -->
  <!-- Initialization target                                               -->
  <!-- =================================================================== -->
  <target name="init">
    <mkdir dir="${test.class.dir}"/>
    <mkdir dir="${class.dir}"/>
    <mkdir dir="${javadoc.dir}"/>
    <mkdir dir="${rel.dir}"/>
  </target>

  <!-- =================================================================== -->
  <!-- Main target                                                         -->
  <!-- =================================================================== -->
  <target name="main" depends="init">
    <echo message="Build File for ${name} Release ${rel}"/>
    <echo message=""/>
    <echo message="Targets are:"/>
    <echo message=""/>
    <echo message="  clean    - Cleans project for fresh build"/>
    <echo message="  compile  - Compiles all code"/>
    <echo message="  jar      - Creates the jar file for the system"/>
    <echo message="  javadoc  - Builds the javadoc for the system"/>
    <echo message="  release  - Builds a release of the system"/>
    <echo message="  test     - Creates and runs the test programs. See lib\readme.txt"/>
  </target>

  <!-- =================================================================== -->
  <!-- Compile target                                                      -->
  <!-- =================================================================== -->
  <target name="compile" depends="init" description="Compiles all code">
    <javacc target="${javacc.dir}/org/relique/jdbc/csv/where.jj" javacchome="${javacc.home}"/>
    <javac srcdir="${java.dir}${path.separator}${javacc.dir}" destdir="${class.dir}">
      <classpath refid="classpath"/>
      <include name="org/**/*.java"/>
    </javac>
    <copy todir="${class.dir}">
      <fileset dir="${resources.dir}" includes="org/**/*.properties"/>
    </copy>
  </target>

  <!-- =================================================================== -->
  <!-- Jar target                                                          -->
  <!-- =================================================================== -->
  <target name="jar" depends="compile"
          description="Creates the jar file for the system">
    <manifest file="manifest">
      <!-- For running CsvJdbc as a utility program -->
      <attribute name="Main-Class" value="org.relique.jdbc.csv.CsvMain"/>
    </manifest>
    <jar jarfile="${jar.file}" manifest="manifest">
      <fileset dir="${class.dir}" includes="org/**/*.class"/>
      <!-- For java.sql.DriverManager Service Provider mechanism -->
      <service type="java.sql.Driver" provider="org.relique.jdbc.csv.CsvDriver"/>
      <fileset dir="${resources.dir}" includes="org/**/*.properties"/>
    </jar>
  </target>

  <!-- =================================================================== -->
  <!-- Javadoc target                                                      -->
  <!-- =================================================================== -->
  <target name="javadoc" depends="init"
          description="Builds the javadoc for the system">
    <javadoc packagenames="org.*"
             sourcepath="${java.dir}"
             destdir="${javadoc.dir}"
             author="true"
             version="true"
             private="true"
             doctitle="${name} java documentation (release ${rel})"
             windowtitle="${name} java documentation (release ${rel})"
             bottom="Check out &lt;a href=&quot;http://csvjdbc.sourceforge.net&quot;&gt;http://csvjdbc.sourceforge.net&lt;/a&gt; for more info.">
      <classpath refid="classpath"/>
    </javadoc>
  </target>

  <!-- =================================================================== -->
  <!-- Clean target                                                        -->
  <!-- =================================================================== -->
  <target name="clean" description="Cleans project for fresh build">
    <delete dir="${test.class.dir}"/>
    <delete dir="${class.dir}"/>
    <delete dir="${javadoc.dir}"/>
    <delete dir="${rel.dir}"/>
    <delete dir="${javacc.dir}" includes="org/**/*.java"/>
    <delete file="manifest"/>
  </target>

  <!-- =================================================================== -->
  <!-- Test target                                                         -->
  <!-- =================================================================== -->
  <target name="test" depends="compile"
          description="Creates and runs the test programs. See lib\readme.txt">
    <mkdir dir="${test.reports}"/>
    <javac srcdir="${test.java.dir}" destdir="${test.class.dir}">
      <classpath refid="test.classpath" />
      <include name="**/*.java" />
    </javac>
    <junit fork="yes" printsummary="no" haltonfailure="no">
      <formatter type="xml" />
      <classpath refid="test.classpath" />
      <batchtest fork="yes" todir="${test.reports}" >
        <fileset dir="${test.class.dir}">
          <include name="**/Test*.class" />
        </fileset>
      </batchtest>
    </junit>
  </target>

  <!-- =================================================================== -->
  <!-- Release target                                                      -->
  <!-- =================================================================== -->
  <target name="release" depends="clean,test,jar,javadoc"
          description="Builds a release of the system">
    <zip zipfile="${rel.dir}/${rel.name}.zip">
      <zipfileset dir="${javadoc.dir}" includes="**/*"
                  prefix="${rel.name}/javadoc"/>
      <zipfileset dir="${src.dir}" includes="**/*"
                  prefix="${rel.name}/src/src"/>
      <zipfileset dir="${build.dir}" includes="build.xml"
                  prefix="${rel.name}/src/build"/>
      <zipfileset dir="${lib.dir}" includes="readme.txt"
                  prefix="${rel.name}/src/lib"/>
      <zipfileset dir="${rel.dir}" includes="*.jar" prefix="${rel.name}"/>
      <zipfileset dir="${doc.dir}" includes="**" excludes="*.gif" prefix="${rel.name}"/>
    </zip>
  </target>

</project>
