<?xml version="1.0"?>

<!-- 
  =======================================================================
  Commons xmlio build file
  ======================================================================= 
-->
<project name="commons-xmlio" default="all" basedir=".">

  <!-- 
  ===================================================================
  Set build properties
  =================================================================== 
  -->

  <property file="${basedir}/build.properties"/>

  <property name="compile.debug" value="true" />
  <property name="compile.deprecation" value="true" />
  <property name="compile.optimize" value="true" />

  <property name="version" value="0.1pre"/>
  <property name="name" value="commons-xmlio" />
  <property name="final.name" value="${name}-${version}"/>

  <!-- 
  ===================================================================
  Set the properties related to the source tree
  =================================================================== 
  -->

  <property name="src.dir" value="${basedir}/src"/>
  <property name="java.dir" value="${src.dir}/java"/>
  <property name="test.dir" value="${src.dir}/test"/>
  <property name="lib.dir" value="${basedir}/lib"/>
  <property name="docs.dir" value="${basedir}/doc"/>
  <property name="conf.dir" value="${src.dir}/conf"/>
  <property name="example.dir" value="${basedir}/example"/>

  <!-- 
  ===================================================================
  Set the properties for the build area
  =================================================================== 
  -->
  <property name="build.dir" value="${basedir}/build"/>
  <property name="build.classes" value="${build.dir}/classes"/>
  <property name="build.lib" value="${build.dir}/lib"/>
  <property name="build.javadocs" value="${build.dir}/javadoc"/>

  <property name="dist.dir" value="${basedir}/dist"/>
  <property name="dist.lib" value="${dist.dir}/lib"/>

  <path id="classpath">
    <pathelement location="${build.classes}" />
    <fileset dir="${lib.dir}"/>
  </path>

  <!-- 
  ===================================================================
  Prepare the build              
  =================================================================== 
  -->

  <target name="prepare">
    <tstamp />
    <mkdir dir="${build.dir}"/>
    <mkdir dir="${build.classes}"/>
    <mkdir dir="${build.lib}"/>
  </target>

  <!-- 
  ===================================================================
  Prepare distributions
  =================================================================== 
  -->

  <target name="prepare-dist">
    <tstamp />
    <mkdir dir="${dist.dir}"/>
    <mkdir dir="${dist.lib}"/>
  </target>

  <!-- 
  ===================================================================
  Build the code           
  =================================================================== 
  -->

  <target name="build" depends="prepare">
    <javac destdir="${build.classes}"
      debug="${compile.debug}"
      deprecation="${compile.deprecation}"
      optimize="${compile.optimize}" >
      <src path="${java.dir}"/>
      <classpath refid="classpath" />
    </javac>
  </target>
  
  <target name="build-test" depends="build">
    <javac destdir="${build.classes}"
      debug="${compile.debug}"
      deprecation="${compile.deprecation}"
      optimize="${compile.optimize}" >
      <src path="${test.dir}"/>
      <classpath refid="classpath" />
    </javac>
  </target>
  
  <!-- 
  =================================================================== 
  Create the jar
  =================================================================== 
  -->
  <target name="jar" depends="build">

    <jar jarfile="${build.lib}/${final.name}.jar" basedir="${build.classes}" >
      <include name="org/apache/**" />
      <exclude name="**/*Test*" />
    </jar>

    <copy todir="${dist.lib}">
          <fileset dir="${build.lib}"/>
    </copy>

  </target>

  <!--
  ===================================================================
  Cleans up build directories
  ===================================================================
  -->
  <target name="clean">
    <delete dir="${build.dir}" />
  </target> 

  <target name="clean-javadocs">
    <delete dir="${build.javadocs}"/>
  </target> 

  <target name="scrub" depends="clean, clean-javadocs">
    <delete dir="${dist.lib}"/>
  </target> 

  <!-- 
  ===================================================================
  Creates the API documentation                             
  =================================================================== 
  -->
  
  <target name="javadocs" depends="build, clean-javadocs" description="Creates the API documentation">
    <mkdir dir="${build.javadocs}"/>
    <mkdir dir="${build.javadocs}"/>
    <javadoc sourcepath="${java.dir}"
      packagenames="org.apache.*"
      destdir="${build.javadocs}"
      author="true"
      windowtitle="Commons XMLio API"
      doctitle="Commons XMLio"
      bottom="Copyright &#169; 2004 The Apache Software Foundation. All Rights Reserved."
      classpathref="classpath">
      <link href="http://java.sun.com/j2ee/sdk_1.3/techdocs/api/"/>
      <link href="http://java.sun.com/j2se/1.4.2/docs/api/"/>
    </javadoc>
  </target>
  
  <target name="all" depends="jar, javadocs"/>

  <!-- 
  ===================================================================
  Do JUnit tests
  =================================================================== 
  -->
  
  <target name="test" depends="build-test" description="Exectutes JUnit tests">
    <junit printsummary="yes" haltonfailure="yes">
      <classpath refid="classpath" />
      <formatter type="plain" />
      <test name="org.apache.commons.xmlio.out.XMLWriterTest" haltonfailure="yes" />
      <test name="org.apache.commons.xmlio.in.SimpleImportTest" haltonfailure="yes" />
    </junit>
  </target>

</project>