<?xml version="1.0"?>

<!--

  Ant build file for Artemis

-->

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

  <target name="init">
    <tstamp />
    <property name="name" value="artemis" />
    <property name="version" value="live" />
    <property name="build.compiler" value="modern" />
    <property name="classpath" value="" />
    <property name="src.dir" value="" />
    <property name="docs.dir" value="docs" />

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

    <property name="build.dir" value="./ant-build" />
    <!-- Subdirectories for main source and classes -->
    <property name="build.src.main" value="${build.dir}/src/main" />
    <property name="build.dest.main" value="${build.dir}/classes/main" />

    <!-- Subdirectories for tests source and classes -->
    <property name="build.src.tests" value="${build.dir}/src/tests" />
    <property name="build.dest.tests" value="${build.dir}/classes/tests" />

    <!-- Subdirectories for docs -->
    <property name="build.src.docs" value="${build.dir}/src/docs" />
    <property name="build.dest.docs" value="${build.dir}/docs" />
    <property name="build.dest.javadocs" value="${build.dest.docs}/api" />

    <!-- Subdirectory for libraries used during build -->
    <property name="build.src.main.lib" value="${build.src.main}/lib" />

    <property name="dist.root" value="./dist" />
    <property name="dist.dir" value="${dist.root}/${name}-${version}" />
  	
    <!-- Compile classpath -->
    <path id="compile.classpath">
        <!-- Main classes from build -->
        <pathelement path="${build.src.main}" />
        <!-- Dependency classes -->
        <fileset dir="${build.src.main}/lib">
        	 <include name="**.jar" />
        </fileset>
        <fileset dir="${build.src.main}/lib">
        	 <include name="**/*.jar" />
             <exclude name="j2ssh/j2ssh-artemis-plugin.jar"/>
        </fileset>
    </path>
  </target>

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

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

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

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

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

    <!-- Copies jars -->
    <copy todir="${build.dir}">
      <fileset dir=".">
        <include name="*.jar" />
        <exclude name="${docbook.tools.file}" />
      </fileset>
    </copy>
  </target>

  <target name="prepare-src" depends="init,prepare-core" />

	<!-- Compile IDL stub classes into the build directory (jar preparation) -->
  <target name="compile-idl" depends="init,prepare-core">
  	<exec executable="idlj" dir="${build.src.main}">
  		   <arg line="-Icorba corba/types.idl" />
  		 </exec>
  	<exec executable="idlj" dir="${build.src.main}">
  		   <arg line="-Icorba corba/nsdb.idl" />
  		 </exec>
  	<exec executable="idlj" dir="${build.src.main}">
  		   <arg line="-Icorba corba/nsdb_write.idl" />
  		 </exec> 
  	<exec executable="idlj" dir="${build.src.main}">
  		   <arg line="-Icorba corba/seqdb.idl" />
  		 </exec>
  </target>
	
  <!-- Compiles the source directory -->
  <target name="compile" depends="init,compile-idl,prepare-src">
    <javac
      fork="true"
      memoryinitialsize="256m"
      memorymaximumsize="256m"
      srcdir="${build.src.main}"
      destdir="${build.dest.main}"
      excludes="nsdb/**,seqdb/**,type/**,lib/**,src/**,uk/ac/sanger/artemis/components/MacHandler.java,uk/ac/sanger/artemis/components/filetree/FileTree.java,uk/ac/sanger/artemis/components/filetree/SshFileTree.java,uk/ac/sanger/artemis/ExternalProgramUtils.java"
      deprecation="false"
      depend="no"
      debug="true">
    	  <classpath refid="compile.classpath"/>
    </javac>
  </target>

  <!-- Creates the chado class package -->
  <target name="chado-access" depends="init,compile">
    <jar
      jarfile="${build.dir}/chado-access.jar"
      basedir="${build.dest.main}"
      manifest="META-INF/MANIFEST.MF"
      includes="uk/ac/sanger/artemis/chado/**,uk/ac/sanger/artemis/util/ByteBuffer*"
    />
  	<jar
  	  jarfile="${build.dir}/chado-access.jar"
      update="yes"
  	  basedir="${build.src.main}"
  	  includes="artemis_sqlmap/**,uk/ac/sanger/artemis/chado/**,uk/ac/sanger/artemis/util/ByteBuffer*"
  	/>
  </target>

  <!-- Creates the class package -->
  <target name="package" depends="init,compile">
    <jar
      jarfile="${build.dir}/${name}.jar"
      basedir="${build.dest.main}"
      manifest="META-INF/MANIFEST.MF"
      includes="**"
    />
  </target>
  

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