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

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

  <path id="libs">
    <fileset dir="lib" includes="*.jar"/>
  </path>

  <target name="init">
    <tstamp/>

    <property name="build" value="build"/>

    <property name="build.compiler" value="modern"/>
    <property name="javac.debug" value="on"/>
    <property name="javac.optimize" value="on"/>

    <property name="src" value="src"/>
    <property name="dist" value="dist"/>
    <property name="test" value="test"/>

    <property name="version" value="1.2.5"/>
  </target>

  <target name="clean" depends="init">
    <delete dir="${build}"/>
    <delete dir="${dist}"/>
  </target>

  <target name="prepare" depends="init">
    <mkdir dir="${build}"/>
    <mkdir dir="${build}/classes"/>
    <mkdir dir="${build}/src"/>

  	 <copy todir="${build}/src">
      <fileset dir="${src}/main" includes="**/*.java"/>
  	 	<filterchain>
  	 	   <!-- cut off JDBC 4 stuff -->
  	 		<replaceregex byline="off" flags="s" pattern=" *//* JDBC4.*" replace="}"/>
  	   </filterchain>
    </copy>
    <copy todir="${build}/src">
      <fileset dir="${src}/test" includes="**/*.java"/>
    </copy>
    <copy todir="${build}/classes">
      <fileset dir="${src}/main" includes="**/*.properties"/>
    </copy>
  </target>

  <target name="compile" depends="init,prepare">
    <javac destdir="${build}/classes" srcdir="${build}/src" classpathref="libs" debug="${javac.debug}" optimize="${javac.optimize}" source="1.3" target="1.3" encoding="latin1"/>
  </target>

  <target name="javadoc" depends="prepare">
    <mkdir dir="${build}/doc"/>
    <javadoc sourcepath="${build}/src" destdir="${build}/doc" packagenames="net.sourceforge.jtds.*" Author="true"
             Doctitle="jTDS API Documentation" Use="true" Version="true" bottom="Generated on ${TODAY}"
             Windowtitle="jTDS API" Private="true" classpathref="libs" encoding="latin1">
      <tag name="todo" description="To do:"/>
      <tag name="created" description="Created:"/>
    </javadoc>
  </target>

  <target name="test" depends="compile">
    <taskdef name="junit" classname="org.apache.tools.ant.taskdefs.optional.junit.JUnitTask"/>

    <junit fork="no" haltonfailure="no" printsummary="yes">
      <classpath>
        <pathelement location="build/classes"/>
        <path refid="libs"/>
      </classpath>
      <formatter type="plain"/>
      <batchtest>
        <fileset dir="${build}/src">
          <include name="**/*Test.java"/>
          <exclude name="**/AllTests.java"/>
        </fileset>
      </batchtest>
    </junit>
  </target>

  <target name="dist" depends="clean,compile,javadoc">
    <mkdir dir="${dist}"/>
    <!-- Runtime jar -->
    <jar basedir="${build}/classes"
         excludes="net/sourceforge/jtds/test/*.class"
         includes="**/*"
         jarfile="${build}/${ant.project.name}-${version}.jar">
        <manifest>
            <attribute name="Implementation-Title" value="jTDS JDBC Driver"/>
            <attribute name="Implementation-Version" value="${version}"/>
            <attribute name="Implementation-URL" value="http://jtds.sourceforge.net"/>
            <attribute name="Specification-Title" value="JDBC"/>
            <attribute name="Specification-Version" value="3.0"/>
            <attribute name="Class-Path" value="jcifs.jar"/>
            <attribute name="Main-Class" value="net.sourceforge.jtds.jdbc.Driver"/>
        </manifest>
    </jar>

    <!-- Source package -->
    <copy todir="${dist}/tmp/doc">
      <fileset dir="${build}/doc" includes="**/*"/>
    </copy>
    <mkdir dir="${dist}/tmp"/>
    <copy todir="${dist}/tmp">
      <fileset dir="." includes="README,README.SSL,README.XA,README.SSO,CHANGELOG,LICENSE,*.bat,*.sh,*.xml,src/**/*,lib/**/*,html/**/*,conf/**/*.xml,conf/**/*.tmpl"/>
    </copy>
    <zip basedir="${dist}/tmp" includes="**/*" zipfile="${dist}/${ant.project.name}-${version}-src.zip"/>
    <delete dir="${dist}/tmp"/>

    <!-- Binary package -->
    <mkdir dir="${dist}/tmp"/>
    <copy todir="${dist}/tmp">
      <fileset dir="." includes="README,README.SSL,README.XA,README.SSO,CHANGELOG,LICENSE,conf/**/*.xml,conf/**/*.tmpl,html/**/*"/>
      <fileset dir="${build}" includes="*.jar"/>
    </copy>

    <mkdir dir="${dist}/tmp/x86/XA"/>
    <copy todir="${dist}/tmp/x86/XA">
      <fileset dir="lib/x86/XA" includes="JtdsXA.dll"/>
      <fileset dir="src/XA" includes="*.sql"/>
    </copy>
    <mkdir dir="${dist}/tmp/x86/SSO"/>
    <copy todir="${dist}/tmp/x86/SSO">
      <fileset dir="lib/x86/SSO" includes="ntlmauth.dll"/>
    </copy>

    <mkdir dir="${dist}/tmp/x64/SSO"/>
    <copy todir="${dist}/tmp/x64/SSO">
      <fileset dir="lib/x64/SSO" includes="ntlmauth.dll"/>
    </copy>

    <mkdir dir="${dist}/tmp/IA64/SSO"/>
    <copy todir="${dist}/tmp/IA64/SSO">
      <fileset dir="lib/IA64/SSO" includes="ntlmauth.dll"/>
    </copy>

    <zip basedir="${dist}/tmp" includes="**/*" zipfile="${dist}/${ant.project.name}-${version}-dist.zip"/>
    <delete dir="${dist}/tmp"/>
  </target>

</project>
