<project name="Sting" default="dist" basedir="." xmlns:ivy="antlib:org.apache.ivy.ant">
    <description>Compile and distribute the Sting toolkit</description>
    <property name="build.sysclasspath" value="first" />

    <property name="build.dir" value="build" />
    <property name="dist.dir" value="dist" />
    <property name="java.source.dir" value="java/src" />
    <property name="java.classes" value="${build.dir}/java/classes" />
    <property name="resource.file" value="StingText.properties" />
    <property name="resource.path" value="${java.classes}/StingText.properties" />

    <property name="queue.source.dir" value="scala/src" />
    <property name="queue.classes" value="${build.dir}/scala/classes" />

    <property name="queue-extensions.source.dir" value="${build.dir}/queue-extensions/src" />
    <property name="queue-extensions.classes" value="${build.dir}/queue-extensions/classes" />
    
    <!-- where to find the tribble distro -->
    <property name="tribble.dir" value="tribble" />

    <!-- where to find 'findbugs', which you must set if you plan to use 'ant findbugs' -->
    <property name="findbugs.home" value="./findbugs"/>

    <!-- do we want to halt on failure of a junit test? default to yes (Bamboo uses 'no') -->
    <property name="halt" value="yes" />
    
    <!-- should our junit test output go to a file or the screen?
    false means it goes to the screen (default) true to file -->
    <property name="usefile" value="false" />

    <!-- If running the 'package' task, this property controls the name of the xml file to package -->
    <property name="executable" value="GenomeAnalysisTK" />

    <property environment="env"/>

    <dirset id="java.source.files" dir="${java.source.dir}">
      <patternset>
	<include name="org/broadinstitute/sting/**"/>
	<exclude name="**/playground/**" unless="include.playground" />
	<exclude name="**/oneoffprojects/**" unless="include.oneoffs" />
      </patternset>
    </dirset>

    <!-- the path for resources that need to go into the GATK jar;
         any additional resources should go into this set. -->
    <path id="gatk.resources">
        <fileset dir="${java.source.dir}">
            <include name="**/**/templates/*" />
        </fileset>
    </path>

    <patternset id="dependency.mask" includes="*.jar">
      <exclude name="junit*.jar" />
      <exclude name="bcel*.jar" />
    </patternset>
    
    <path id="external.dependencies">
      <fileset dir="lib">
        <patternset refid="dependency.mask" />
      </fileset>
    </path>

    <path id="build.results">
      <fileset dir="dist">
        <patternset refid="dependency.mask" />
      </fileset>
    </path>

    <!-- Path to queue dependencies. -->
    <path id="queue.dependencies">
        <path refid="external.dependencies" />
        <pathelement location="${java.classes}" />
    </path>

    <!-- Path to queue-extendsions dependencies. -->
    <path id="queue-extensions.dependencies">
        <path refid="external.dependencies" />
        <pathelement location="${java.classes}" />
        <pathelement location="${queue.classes}" />
        <!-- Need the resources as we will be running a command line program which needs the help text. -->
        <pathelement location="${resource.path}" />
    </path>

    <target name="init.resolve" unless="init.resolve.done">
        <!-- ivy properties -->
        <property name="ivy.install.version" value="2.2.0-rc1"/>
        <property name="ivy.home" value="${user.home}/.ant"/>
        <property name="ivy.jar.dir" value="${ivy.home}/lib"/>
        <property name="ivy.jar.file" value="ivy-${ivy.install.version}.jar"/>
        <property name="ivy.settings.dir" value="settings"/>
        <property file="${ivy.settings.dir}/ivysettings.properties"/>
  
      <mkdir dir="${ivy.jar.dir}"/>
      <!-- Remove old versions of ivy. -->
      <delete file="${ivy.jar.dir}/ivy-2.0.0.jar"/>
      <get src="http://repo1.maven.org/maven2/org/apache/ivy/ivy/${ivy.install.version}/${ivy.jar.file}"
           dest="${ivy.jar.dir}/${ivy.jar.file}"
           usetimestamp="true"/>
      <taskdef resource="org/apache/ivy/ant/antlib.xml"
               uri="antlib:org.apache.ivy.ant"
               classpath="${ivy.jar.dir}/${ivy.jar.file}"/>
      <ivy:settings file="${ivy.settings.dir}/ivysettings.xml"/>
        <property name="init.resolve.done" value="true"/>
    </target>

    <target name="resolve" depends="init.resolve,init"
            description="locate and download library dependencies">
        <property name="gatk.ivy.conf" value="default" />
        <property name="scala.ivy.conf" value="default" />
        <condition property="queue.ivy.conf" value="queue" else="default">
            <isset property="queue.include" />
        </condition>
        <property name="ivy.conf" value="default, ${gatk.ivy.conf}, ${scala.ivy.conf}, ${queue.ivy.conf}"/>
      <ivy:retrieve file="ivy.xml" conf="${ivy.conf}" />
    </target>

    <target name="init.buildall">
        <!-- Set the properties needed to build Queue -->
        <property name="gatk.target" value="oneoffs"/>
        <property name="queue.target" value="core"/>
    </target>

    <!-- define some key locations that might change based on how the build is run -->
    <target name="init">
      <!-- define build version and timestamp -->
      <exec executable="svnversion" outputproperty="build.version" failonerror="true">
        <arg value="--no-newline"/>
      </exec>
      <tstamp>
        <format property="build.timestamp" pattern="yyyy/MM/dd HH:mm:ss"/>
      </tstamp>

        <!-- Set target based on STING_BUILD_TYPE environment variable -->
        <condition property="sting.target" value="core" else="${env.STING_BUILD_TYPE}">
            <equals arg1="${env.STING_BUILD_TYPE}" arg2="$${env.STING_BUILD_TYPE}" />
        </condition>

        <!-- Get the gatk build target.  Default to the STING_BUILD_TYPE.  -->
        <condition property="gatk.target" value="${sting.target}" else="${env.GATK_BUILD_TYPE}">
            <equals arg1="${env.GATK_BUILD_TYPE}" arg2="$${env.GATK_BUILD_TYPE}" />
        </condition>

        <!-- Get the queue build target.  Default to none.  -->
        <condition property="queue.target" value="none" else="${env.QUEUE_BUILD_TYPE}">
            <equals arg1="${env.QUEUE_BUILD_TYPE}" arg2="$${env.QUEUE_BUILD_TYPE}" />
        </condition>

        <!-- If the queue target is set, or if the queue-extensions needs to be built, then include all queue tasks. -->
        <condition property="queue.include">
            <or>
                <not><equals arg1="${queue.target}" arg2="none" /></not>
            </or>
        </condition>

        <!-- If queue is being built, then include scala tasks (init.scalatasks) -->
        <condition property="scala.include">
            <or>
                <isset property="queue.include" />
            </or>
        </condition>
        
        <echo message="GATK build      : ${gatk.target}"/>
        <echo message="Queue build     : ${queue.target}"/>
      <echo message="source revision : ${build.version}"/>
      <echo message="build time      : ${build.timestamp}" />
      
      <condition property="include.oneoffs">
        <equals arg1="${gatk.target}" arg2="oneoffs" casesensitive="false" />
      </condition>
      
      <condition property="include.playground">
        <or>
          <equals arg1="${gatk.target}" arg2="playground" casesensitive="false"/>
          <equals arg1="${gatk.target}" arg2="oneoffs" casesensitive="false" />
        </or>
      </condition>

      <!-- Create the build directory structure used by compile -->
      <mkdir dir="${build.dir}"/>
      <mkdir dir="${java.classes}"/>
    </target>

    <target name="init.scalatasks" depends="resolve" if="scala.include"
            description="Initializes the scala ant tasks from scala-compiler.jar">
        <path id="scala.classpath">
            <fileset dir="lib">
                <include name="scala-compiler-*.jar"/>
                <include name="scala-library-*.jar"/>
            </fileset>
        </path>
        <taskdef resource="scala/tools/ant/antlib.xml">
            <classpath refid="scala.classpath"/>
        </taskdef>
    </target>

    <target name="gatk.compile" depends="tribble,init,resolve"
            description="compile the source">
      <!-- Compile the java code from ${src} into build -->
      <javac srcdir="${java.source.dir}" destdir="${java.classes}" debug="true" debuglevel="lines,vars,source" classpathref="external.dependencies">
          <exclude name="**/examples/**" />
        <exclude name="**/playground/**" unless="include.playground"/>
        <exclude name="**/oneoffprojects/**" unless="include.oneoffs"/>
      </javac>
    </target>

    <!-- Queue depends on the gatk since it contains the StingUtils (including CommandLine) -->
    <target name="queue.compile" depends="init,resolve,gatk.compile,init.scalatasks" if="queue.include" description="build Queue">
        <mkdir dir="${queue.classes}"/>
        <echo>Building Queue...</echo>
        <scalac srcdir="${queue.source.dir}" destdir="${queue.classes}" classpathref="queue.dependencies" deprecation="yes" unchecked="yes">
            <include name="org/broadinstitute/sting/queue/**/*.scala"/>
        </scalac>
    </target>

    <!-- NOTE: Extracting help first to avoid "Unable to load help text.  Help output will be sparse." warning message. -->
    <target name="queue-extensions.generate" depends="gatk.compile, queue.compile, extracthelp" if="queue.include" description="generate GATK modules for Queue">
        <mkdir dir="${queue-extensions.source.dir}"/>
        <echo>Generating Queue GATK extensions...</echo>
        <java fork="true" failonerror="true" classname="org.broadinstitute.sting.queue.extensions.gatk.GATKExtensionsGenerator" classpathref="queue-extensions.dependencies">
            <arg value="-outDir" />
            <arg path="${queue-extensions.source.dir}" />
            <arg value="-l" />
            <arg value="WARN" />
        </java>
    </target>

    <target name="queue-extensions.compile" depends="queue-extensions.generate" if="queue.include" description="compile extensions for Queue">
        <mkdir dir="${queue-extensions.classes}"/>
        <echo>Building Queue GATK extensions...</echo>
        <scalac srcdir="${queue-extensions.source.dir}" destdir="${queue-extensions.classes}" classpathref="queue-extensions.dependencies" deprecation="yes" unchecked="yes">
            <include name="**/*.scala"/>
        </scalac>
    </target>

    <target name="extracthelp" depends="init,gatk.compile"
	    description="Extract help key/value pair file from the JavaDoc tags."
	    unless="disable.help">
        <path id="doclet.classpath">
          <path refid="external.dependencies" />
          <pathelement location="${java.classes}" />
        </path>
      <javadoc doclet="org.broadinstitute.sting.utils.help.ResourceBundleExtractorDoclet"
	       docletpathref="doclet.classpath"
	       classpathref="external.dependencies"
	       additionalparam="-build-timestamp &quot;${build.timestamp}&quot; -version-suffix .${build.version} -out ${basedir}/${resource.path}">
	<packageset refid="java.source.files"/>
      </javadoc>
    </target>

    <target name="sting.compile" depends="gatk.compile, queue.compile, queue-extensions.compile" />

    <target name="init.jar" depends="sting.compile,extracthelp">
        <mkdir dir="${dist.dir}"/>
        <copy todir="${dist.dir}">
            <fileset dir="lib" includes="*.jar"/>
        </copy>
    </target>

    <target name="sting-utils.jar" depends="gatk.compile, init.jar">
        <jar jarfile="${dist.dir}/StingUtils.jar">
            <fileset dir="${java.classes}" includes="**/utils/**/*.class"/>
            <fileset dir="${java.classes}" includes="**/commandline/**/*.class"/>
            <fileset dir="${java.classes}" includes="**/sting/datasources/**/*.class"/>
            <fileset dir="${java.classes}" includes="net/sf/picard/**/*.class"/>
            <manifest>
                <attribute name="Premain-Class" value="org.broadinstitute.sting.utils.instrumentation.Sizeof" />
            </manifest>
        </jar>
    </target>

    <target name="gatk.jar" depends="gatk.compile, init.jar"
            description="generate the GATK distribution">
        <jar jarfile="${dist.dir}/GenomeAnalysisTK.jar">
            <path refid="gatk.resources"/>
            <fileset dir="${java.classes}">
	          <include name="${resource.file}" />
              <include name="**/gatk/**/*.class" />
              <include name="**/alignment/**/*.class"/>
              <include name="**/oneoffprojects/**/*.class" />
              <include name="**/playground/**/*.class" />
            </fileset>
            <manifest>
                <attribute name="Main-Class" value="org.broadinstitute.sting.gatk.CommandLineGATK" />
            </manifest>
        </jar>

	<jar jarfile="${dist.dir}/Aligner.jar">
	  <fileset dir="${java.classes}" includes="**/alignment/**/*.class" />
	</jar>

        <jar jarfile="${dist.dir}/AnalyzeCovariates.jar" whenmanifestonly="skip">
          <fileset dir="${java.classes}">
            <include name="**/analyzecovariates/**/*.class" />
            <include name="**/gatk/walkers/recalibration/*.class" />
          </fileset>
          <manifest>
            <attribute name="Main-Class" value="org.broadinstitute.sting.analyzecovariates.AnalyzeCovariates" />
          </manifest>
        </jar>

    </target>

    <target name="queue.jar" depends="queue.compile, queue-extensions.compile, init.jar" if="queue.include">
        <jar jarfile="${dist.dir}/Queue.jar">
            <fileset dir="${queue.classes}">
                <include name="org/broadinstitute/sting/queue/**/*.class"/>
            </fileset>
            <fileset dir="${java.classes}">
              <include name="org/broadinstitute/sting/queue/**/*.class" />
            </fileset>
            <fileset dir="${queue-extensions.classes}">
              <include name="**/*.class" />
            </fileset>
            <manifest>
                <attribute name="Main-Class" value="org.broadinstitute.sting.queue.QCommandLine" />
            </manifest>
        </jar>
    </target>

    <target name="sting.jar" depends="sting-utils.jar, gatk.jar, queue.jar" />

    <target name="init.manifests" depends="sting.jar">
        <pathconvert property="jar.classpath" pathsep=" ">
            <flattenmapper/>
            <fileset dir="${dist.dir}" includes="*.jar"/>
            <filelist files="GATKScala.jar"/>
        </pathconvert>
    </target>

    <target name="sting-utils.manifests" depends="sting-utils.jar, init.manifests">
        <jar jarfile="${dist.dir}/StingUtils.jar" update="true">
            <manifest>
                <attribute name="Class-Path" value="${jar.classpath}"/>
            </manifest>
        </jar>
    </target>

    <target name="gatk.manifests" depends="gatk.jar, init.manifests">

        <jar jarfile="${dist.dir}/GenomeAnalysisTK.jar" update="true">
            <manifest>
                <attribute name="Class-Path" value="${jar.classpath}"/>
            </manifest>
        </jar>

        <jar jarfile="${dist.dir}/AnalyzeCovariates.jar" update="true" whenmanifestonly="skip">
            <manifest>
                <attribute name="Class-Path" value="${jar.classpath}" />
            </manifest>
        </jar>

    </target>

    <target name="queue.manifests" depends="queue.jar, init.manifests" if="queue.include">
        <jar jarfile="${dist.dir}/Queue.jar" update="true" >
            <manifest>
                <attribute name="Class-Path" value="${jar.classpath}" />
            </manifest>
        </jar>
    </target>

    <target name="sting.manifests" depends="sting-utils.manifests, gatk.manifests, queue.manifests" />

    <target name="dist" depends="sting.manifests" />

    <target name="core" description="force a build of the Sting core code">
        <antcall target="dist" inheritAll="false">
            <param name="sting.target" value="core" />
        </antcall>
    </target>

    <target name="playground" description="force a build of the Sting experimental code">
      <antcall target="dist" inheritAll="false">
        <param name="sting.target" value="playground" />
	 </antcall>
    </target>

    <target name="oneoffs" description="force a build of the Sting experimental code and one-offs">
      <antcall target="dist" inheritAll="false">
        <param name="sting.target" value="oneoffs" />
      </antcall>
    </target>

    <target name="queue" description="force a build of Queue">
        <!--
        inheritAll is false so that 'ant queue' does not accidentally import
        params if the build was called with 'ant clean oneoffs queue'.
        Instead this task resets the parameters and is just like running
        a fresh 'ant dist -Dqueue.target=core'.
        -->
        <antcall target="dist" inheritAll="false">
            <param name="queue.target" value="core" />
        </antcall>
    </target>

    <target name="test.compile" depends="init.buildall,dist">
        <echo message="Sting: Compiling test cases!"/>
        <mkdir dir="${java.test.classes}"/>
        <javac destdir="${java.test.classes}" debug="true" optimize="on">
            <src path="${java.test.sources}"/>
            <classpath>
                <path refid="external.dependencies" />
                <pathelement location="${java.classes}"/>
                <pathelement location="lib/junit-4.4.jar"/>
            </classpath>
        </javac>

        <echo message="Queue: Compiling test cases!"/>
        <mkdir dir="${queue.test.classes}"/>
        <scalac srcdir="${queue.test.sources}" destdir="${queue.test.classes}" deprecation="yes" unchecked="yes">
            <include name="org/broadinstitute/sting/queue/**/*.scala"/>
            <classpath>
                <path refid="queue.dependencies"/>
                <pathelement location="${queue.classes}"/>
                <pathelement location="${java.test.classes}"/>
                <pathelement location="lib/junit-4.4.jar"/>
            </classpath>
        </scalac>
    </target>

    <!-- new scala target -->
    
    <target name="scala" description="build the scala directory">
      <antcall target="resolve">
        <param name="ivy.conf" value="scala"/>
      </antcall>
        <antcall target="dist"/>    
      <property name="scala.source.dir" value="scala/src" />
      <property name="scala.classes" value="build/scala" />
      
      <path id="scala.classpath">
	    <fileset dir="lib">
          <include name="scala-compiler-*.jar"/>
          <include name="scala-library-*.jar"/>
	    </fileset>
        <fileset dir="${dist.dir}">
          <patternset id="scalaStuff">
            <include name="*.jar"/>
        </patternset>
        </fileset>
      </path>
      <taskdef resource="scala/tools/ant/antlib.xml">
        <classpath refid="scala.classpath"/>
      </taskdef>
      <mkdir dir="${scala.classes}"/>
      <echo>Building Scala...</echo>
      <scalac srcdir="${scala.source.dir}" destdir="${scala.classes}" classpathref="scala.classpath" force="changed">
        <include name="*.scala"/>
      </scalac>
      
      <jar jarfile="${dist.dir}/GATKScala.jar">
        <fileset dir="${scala.classes}">
          <include name="*.class"/>
        </fileset>
      </jar>
    </target>
    
    <!-- ***************************************************************************** -->
    <!-- ***********               Tests and associated tasks                ********* -->
    <!-- ***************************************************************************** -->
    <!-- where to put reports and tests-->
    <property name="report" value="${build.dir}/report"/>
    <property name="java.test.classes" value="${java.classes}/testclasses"/>
    <property name="test.output" value="${dist.dir}/test"/>
    <property name="java.test.sources" value="java/test"/>
    <property name="queue.test.classes" value="${queue.classes}/testclasses"/>
    <property name="queue.test.sources" value="scala/test"/>
    <!-- provide a ceiling on the memory that unit/integration tests can consume. -->
    <property name="test.maxmemory" value="5g"/>

    <!-- TEST -->
    <macrodef name="run-test">
        <attribute name="testtype"/>
        <sequential>
            <mkdir dir="${report}"/>
            <echo message="Sting: Running @{testtype} test cases!"/>
            <junit printsummary="yes" showoutput="yes" maxmemory="${test.maxmemory}" clonevm="yes" haltonfailure="${halt}" failureProperty="test.failure">
                <formatter type="brief" usefile="false" />
                <formatter type="xml"/>
                <classpath>
                    <path refid="build.results"/>
                    <pathelement location="${java.test.classes}"/>
                    <pathelement location="${queue.test.classes}"/>
                    <pathelement location="lib/junit-4.4.jar"/>
                </classpath>

                <batchtest fork="yes" todir="${report}">
                    <fileset dir="${java.test.classes}">
                        <include name="**/@{testtype}.class"/>
                        <exclude name="**/BaseTest.class"/>
                    </fileset>
                    <fileset dir="${queue.test.classes}">
                        <include name="**/@{testtype}.class"/>
                        <exclude name="**/BaseTest.class"/>
                    </fileset>
                </batchtest>
            </junit>
            <fail message="test failed" if="test.failure" />
        </sequential>
    </macrodef>


    <!-- our three different test conditions: Test, IntegrationTest, PerformanceTest -->
    <target name="test" depends="test.compile,tribble.test" description="Run unit tests">
        <condition property="ttype" value="*UnitTest" else="${single}">
            <not><isset property="single"/></not>
        </condition>
        <run-test testtype="${ttype}"/>
    </target>
    <target name="integrationtest" depends="test.compile" description="Run integration tests">
        <condition property="itype" value="*IntegrationTest" else="${single}">
            <not><isset property="single"/></not>
        </condition>
        <run-test testtype="${itype}"/>
    </target>
    <target name="performancetest" depends="test.compile" description="Run performance tests">
       <condition property="ptype" value="*PerformanceTest" else="${single}">
            <not><isset property="single"/></not>
        </condition>
        <run-test testtype="${ptype}"/>
    </target>

    <!-- ***************************************************************************** -->
    <!-- ***********                     Tribble                             ********* -->
    <!-- ***************************************************************************** -->
    <!-- compile the library -->
    <target name="tribble.compile" description="compiles the tribble library">
        <echo message="Building the Tribble Library..."/>
        <ant antfile="build.xml" target="all" dir="${tribble.dir}" inheritAll="false"/>
    </target>

    <!-- build the jar -->
    <target name="tribble" description="Builds the tribble jar" depends="tribble.compile">
        <copy todir="lib">
                <fileset dir="${tribble.dir}/dist" includes="*.jar"/>
            </copy>
    </target>

    <!-- test tribble using the unit tests set in tribble -->
    <target name="tribble.test" description="runs the tribble tests" depends="tribble.compile">
        <echo message="Testing the Tribble Library..."/>
        <ant antfile="build.xml" target="test" dir="${tribble.dir}" inheritAll="false"/>
    </target>

    <!-- clean tribble -->
    <target name="tribble.clean" description="cleans the tribble library">
        <echo message="Cleaning the Tribble Library..."/>
        <ant antfile="build.xml" target="clean" dir="${tribble.dir}" inheritAll="false"/>
    </target>
    <!-- ***************************************************************************** -->

    <target name="clean.javadoc">
        <delete dir="javadoc"/>
    </target>

    <target name="javadoc" depends="init.buildall,resolve,queue-extensions.generate" description="generates javadoc">
      <mkdir dir="javadoc"/>
      <javadoc destdir="javadoc"
               classpathref="external.dependencies">
        <packageset refid="java.source.files"/>
      </javadoc>

        <mkdir dir="javadoc/queue"/>
        <scaladoc srcdir="" destdir="javadoc/queue" classpathref="queue-extensions.dependencies" deprecation="yes" unchecked="yes">
            <src path="${queue.source.dir}"/>
            <src path="${queue-extensions.source.dir}"/>
            <include name="org/broadinstitute/sting/queue/**/*.scala"/>
        </scaladoc>
    </target>

    <!-- Unzip all classes from their current locations and assemble them in a staging directory -->
    <target name="stage" description="stage files for distribution">
        <mkdir dir="staging"/>
        <unjar dest="staging" overwrite="false">
          <fileset dir="${dist.dir}">
            <patternset refid="dependency.mask" />
          </fileset>
        </unjar>
    </target>

    <!-- Build a package consisting of all supporting files -->
    <target name="package" depends="dist,stage" description="bundle up an executable for distribution">
      <mkdir dir="${dist.dir}/packages" />
      <xslt in="packages/${executable}.xml" out="${dist.dir}/packages/Build${executable}.xml" style="packages/CreatePackager.xsl" />
      <ant antfile="${dist.dir}/packages/Build${executable}.xml" target="package" />
    </target>

    <target name="release" depends="package" description="release a build, putting each file in a location specified by the package">
      <ant antfile="${dist.dir}/packages/Build${executable}.xml" target="release" />      
    </target>

    <!-- Build a subset of picard with only those classes we need by completely abusing the packaging system -->
    <!-- TODO: Reuse as much as possible of the 'stage' and 'package' targets -->
    <target name="build-picard-private" depends="resolve">
      <!-- Build out a classpath -->
      <pathconvert property="required.picard.jars" pathsep=":">
        <fileset dir="${basedir}">
	     <include name="staging" />
	     <include name="lib/picard-*.*.*.jar" />
	     <include name="lib/sam-*.jar" />
	   </fileset>
      </pathconvert>
      <echo message="required.picard.jars=${required.picard.jars}" />

      <!-- Stage picard-private -->
      <delete dir="staging" />
      <mkdir dir="staging" />
      <unjar src="${picard.dist.dir}/picard-private.jar" dest="staging" overwrite="true" />

      <!-- Use the packaging system to extract parts of picard-private we need -->
      <mkdir dir="${dist.dir}/packages" />
      <xslt in="packages/PicardPrivate.xml" out="${dist.dir}/packages/BuildPicardPrivate.xml" style="packages/CreatePackager.xsl" />
      <ant antfile="${dist.dir}/packages/BuildPicardPrivate.xml">
	<property name="additional.jars" value="${required.picard.jars}" />
      </ant>
    </target>

    <!-- ******************************************************************************** -->
    <!-- Find bug tasks                                                                   -->
    <!-- ******************************************************************************** -->
    <path id="findbugs.classpath">
            <fileset dir="lib" erroronmissingdir="true" includes="*.jar"/>
    </path>
    <target         name="findbugs" depends="dist">
        <antcall    target  ="resolve">
            <param  name    ="ivy.conf" value="findbugs"/>
        </antcall>
        <!-- setup the taskdef, telling ant where to find the defined task for ant -->
        <taskdef name="findbugs" classname="edu.umd.cs.findbugs.anttask.FindBugsTask" classpathref="findbugs.classpath"/>
        <!-- what should findbug look at: we want to aim it at the GATK.jar -->
        <findbugs       home="${findbugs.home}"
                        output="xml"
                        outputFile="${build.dir}/findbugs.xml"
                        classpathref="findbugs.classpath"
                        debug="false">
         <auxClasspath>
                <fileset dir="dist" includes="**/*.jar" excludes="**/GenomeAnalysisTK.jar"/>            
         </auxClasspath>
         <sourcePath    path="../java/src" />
         <class         location="dist/GenomeAnalysisTK.jar" />
       </findbugs>
     </target>



    <target name="clean" description="clean up" depends="tribble.clean,clean.javadoc">
        <delete dir="out"/>
        <delete dir="${build.dir}"/>
        <delete dir="lib"/>
        <delete dir="staging"/>
        <delete dir="${dist.dir}"/>
        <!-- When we clean, make sure to clean out tribble as well -->
        <ant antfile="tribble/build.xml" target="clean"/>

    </target>
</project>
