<?xml version="1.0"?>

<!--

  Ant build file for the entire biojava tree

  see:
  <a href="http://jakarta.apache.org/ant">Ant Project Homepage</a>
  <a href="http://home.wxs.nl/~ajkuiper/ant.html">Ant User Manual</a>
  <a href="http://jakarta.apache.org/builds/tomcat/nightly/ant.zip">Download</a>

  targets:

    compile
    compile-tests compiles JUnit tests
    package       builds the biojava.jar file (default)
    runtests      runs JUnit tests
    javadocs
    dist
    dist-zip     'binary' release (jar & documentation) in zip format
    dist-tgz     'binary' release (jar & documentation) in tar.gz format
    dist-both    both dist-zip & dist-tgz
    clean        cleans up the build & dist directories

  author:  Michael Heuer, modified by Keith James (JUnit support), modified
           Greg Cox (fixed documentation)
  version: $Id: build.xml,v 1.14 2001/08/02 10:26:25 kdj Exp $

  portions Copyright (c) 1999-2000 The Apache Software Foundation.

-->

<project default="package" basedir=".">

  <target name="init">
    <tstamp />
    <property name="name" value="biojava" />
    <property name="version" value="pre-1.2" />

    <property name="build.compiler" value="modern" />

    <property name="classpath" value="xerces.jar:jakarta-regexp.jar:bytecode.jar" />

    <!-- Save the current system classpath to pass to forked VMs -->
    <property name="env.classpath" value="${java.class.path}" />

    <!-- Check the current system classpath for JUnit -->
    <available classpath="${env.classpath}"
               classname="junit.framework.TestCase"
               property="junit.present" />

    <!-- Check the current system classpath for JUnit support in Ant (only in >= 1.3) -->
    <available classpath="${env.classpath}"
               classname="org.apache.tools.ant.taskdefs.optional.junit.JUnitTest"
               property="junit.support" />

    <property name="readme" value="./README" />
    <property name="license" value="./LICENSE" />
    <property name="src.dir" value="./src" />
    <property name="tests.dir" value="./tests" />
    <property name="reports.dir" value="./reports" />
    <property name="manifest.dir" value="./manifest" />
    <property name="manifest.file" value="defaultmanifest.txt" />
    <property name="resources.dir" value="./resources" />

    <property name="packages" value="org.*" />

    <property name="build.dir" value="./ant-build" />
    <!-- Subdirectories for main source and classes -->
    <property name="build.src.main" value="./ant-build/src/main" />
    <property name="build.dest.main" value="./ant-build/classes/main" />
    <!-- Subdirectories for tests source and classes -->
    <property name="build.src.tests" value="./ant-build/src/tests" />
    <property name="build.dest.tests" value="./ant-build/classes/tests" />
    <!-- Subdirectory for Javadocs -->
    <property name="build.javadocs" value="./ant-build/docs" />
    <!-- Subdirectory for test reports -->
    <property name="reports.tests" value="./reports/tests" />

    <property name="dist.root" value="./dist" />
    <property name="dist.dir" value="${dist.root}/${name}-${version}" />
  </target>

  <!-- Prepares the build directory -->
  <target name="prepare" depends="init">
    <mkdir dir="${build.dir}" />
  </target>

  <!-- Prepares the source code -->
  <target name="prepare-src" depends="init,prepare">

    <!-- Creates directories -->
    <mkdir dir="${build.src.main}" />
    <mkdir dir="${build.dest.main}" />
    <mkdir dir="${build.src.tests}" />
    <mkdir dir="${build.dest.tests}" />
    <mkdir dir="${reports.tests}" />

    <!-- Copies src files -->
    <!-- copydir src="${src.dir}" dest="${build.src}" excludes="CVS,cvs"/ -->
    <copy todir="${build.src.main}">
      <fileset dir="${src.dir}">
        <exclude name="**/CVS/**" />
      </fileset>
    </copy>

    <!-- Copies test src files -->
    <copy todir="${build.src.tests}">
      <fileset dir="${tests.dir}">
        <exclude name="**/CVS/**" />
      </fileset>
    </copy>

    <!-- Copies manifest -->
    <!-- copydir src="${manifest.dir}" dest="${build.src}" includes="${manifest.file}"/ -->
    <copy todir="${build.src.main}">
      <fileset dir="${manifest.dir}">
        <include name="${manifest.file}" />
      </fileset>
    </copy>

    <!-- Copies resources -->
    <!-- copydir src="${resources.dir}" dest="${build.src}" excludes="CVS,cvs"/ -->
    <copy todir="${build.dest.main}">
      <fileset dir="${resources.dir}">
        <exclude name="**/CVS/**" />
      </fileset>
    </copy>
  </target>

  <!-- Compiles the source directory -->
  <target name="compile" depends="init,prepare-src">
    <javac
      srcdir="${build.src.main}"
      destdir="${build.dest.main}"
      classpath="${classpath}"
      deprecation="false"
      depend="no"
      debug="true"
    />
  </target>

  <!-- Compiles the tests directory -->
  <target name="compile-tests" depends="init,prepare-src,compile">
    <javac
      srcdir="${build.src.tests}"
      destdir="${build.dest.tests}"
      deprecation="true"
      depend="yes">
      <classpath>
        <pathelement path="${classpath}" />
        <pathelement path="${build.dest.main}" />
      </classpath>
    </javac>
  </target>

  <!-- Creates the class package (tests are left in the parallel tree) -->
  <target name="package" depends="init,compile">
    <jar
      jarfile="${build.dir}/${name}.jar"
      basedir="${build.dest.main}"
      manifest="${build.src.main}/${manifest.file}"
      includes="org/**"
    />
  </target>

  <!-- Runs tests if the Ant optional JUnit support is available -->
  <target name="runtests" depends="init,compile-tests" if="junit.support">
    <junit printsummary="yes" haltonfailure="no" dir="${build.dest.tests}">
      <formatter type="plain" usefile="true" />
      <classpath>
        <!-- classes specified in this file -->
        <pathelement path="${classpath}" />
        <!-- classes specified in system classpath -->
        <pathelement path="${env.classpath}" />
        <!-- main classes from build -->
        <pathelement path="${build.dest.main}" />
        <!-- test classes from build -->
        <pathelement path="${build.dest.tests}" />
        <!-- test data from build -->
        <pathelement path="${build.src.tests}" />
      </classpath>
      <!-- The junit task doesn't support 'if' so we test for JUnit here -->
      <batchtest fork="yes" todir="${reports.tests}" if="junit.present">
        <fileset dir="${build.dest.tests}">
          <include name="**/*Test*" />
        </fileset>
      </batchtest>
    </junit>
  </target>

  <!-- Creates the API documentation -->
  <target name="javadocs" depends="init,prepare-src">
    <mkdir dir="${build.javadocs}" />
    <javadoc
      packagenames="${packages}"
      sourcepath="${build.src.main}"
      classpath="${classpath}"
      destdir="${build.javadocs}"
      author="true"
      version="true"
      use="true"
      windowtitle="${name} API"
      doctitle="${name}"
      maxmemory="64m"
    >
       <group title="Core Packages"
              packages="org.biojava.bio:org.biojava.bio.dist:org.biojava.bio.search:org.biojava.bio.seq:org.biojava.bio.seq.db:org.biojava.bio.seq.genomic:org.biojava.bio.seq.io:org.biojava.bio.symbol"
/>
       <group title="Experimental/New Packages"
              packages="org.biojava.bio.proteomics:org.biojava.stats.svm:org.biojava.stats.svm.tools:org.biojava.bio.seq.homol:org.biojava.bio.seq.ragbag:org.biojava.bio.seq.db.emblcd"
/>
       <group title="User Interface Components"
              packages="org.biojava.bio.gui:org.biojava.bio.gui.sequence" />
       <group title="Developers' Packages"
              packages="org.biojava.bio.seq.impl:org.biojava.utils:org.biojava.utils.cache:org.biojava.utils.contract:org.biojava.utils.xml:org.biojava.utils.query:org.biojava.utils.stax"
/>
       <group title="External Tools"
              packages="org.biojava.bio.program:org.biojava.bio.program.das:org.biojava.bio.program.gff:org.biojava.bio.program.sax:org.biojava.bio.program.seach:org.biojava.bio.program.xml:org.biojava.bio.seq.io.game:org.biojava.bio.program.search:org.biojava.bio.program.xff:org.biojava.bio.program.ssbind"
/>
       <group title="Dynamic Programming Packages"
              packages="org.biojava.bio.dp:org.biojava.bio.dp.onehead:org.biojava.bio.dp.twohead"
/>
    </javadoc>
  </target>

  <!-- Creates the distribution -->
  <target name="dist" depends="init,package,runtests,javadocs">
    <mkdir dir="${dist.root}" />
    <mkdir dir="${dist.dir}" />
    <mkdir dir="${dist.dir}/lib" />
    <mkdir dir="${dist.dir}/docs" />

    <copyfile src="${readme}" dest="${dist.dir}" />
    <copyfile src="${license}" dest="${dist.dir}" />

    <copyfile src="${build.dir}/${name}.jar" dest="${dist.dir}/lib/${name}.jar" />
    <copydir src="${build.javadocs}" dest="${dist.dir}/docs" />
  </target>

  <!-- zips the dist -->
  <target name="dist-zip" depends="init,dist">
    <zip zipfile="${name}-${version}.zip" basedir="${dist.dir}" includes="**" />
  </target>

  <!-- tgzs the dist -->
  <target name="dist-tgz" depends="init,dist">
    <tar tarfile="${name}-${version}.tar" basedir="${dist.root}" includes="**" />
    <gzip zipfile="${name}-${version}.tar.gz" src="${name}-${version}.tar" />
  </target>

  <!-- zip & tgz -->
  <target name="dist-both" depends="init,dist-zip,dist-tgz" />

  <!-- Cleans everything -->
  <target name="clean" depends="init">
    <deltree dir="${build.dir}" />
    <deltree dir="${dist.root}" />
    <delete file="${name}-${version}.tar.gz" />
    <delete file="${name}-${version}.tar" />
    <delete file="${name}-${version}.zip" />
  </target>

  <target name="sync">
    <cvs command="update" />
    <AntCall target="package"/>
    <cvs command="commit" />
  </target>

</project>
