<!-- ===========================================================================


Introduction
============

See the build targets for the tasks this ant build file supports


Installing the build tools
==========================

For instructions on JDOM use of Ant see the build.xml find in the "core"
module (../core).

Build targets
=============

These are the meaningful targets for this build file:

 - package [default] -> creates ./build/jdom-test.jar
 - compile -> compiles the contributed source code
 - javadoc -> generates the API documentation in ./build/javadocs
 - clean -> restores the distribution to its original and clean state
 - test -> runs tests one test class at a time (all test cases starting with
   "Test")
 - testui -> runs JUnit gui and starts automatically with Alltests
 - testreport -> Calls the Ant/Junit task to build javadoc style test output
   after you have run the test task.  These aren't automatically done because
   it takes more time and that may not be desired when the tests normally
   succeed.

-->

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

  <!-- =================================================================== -->
  <!-- Initialization target                                               -->
  <!-- =================================================================== -->
  <target name="init">
    <tstamp/>

    <!--
      Give user a chance to override without editing this file
      (and without using -D arguments each time they build).
      The build properties a user is likely to override include:
        - jdom.dir           The directory where the JDOM distribution is
                             installed. Defaults to ../core
        - jdom.lib.dir       The directory where to look for the default JAR
                             files.  Defaults to ${jdom.dir}/lib
        - jdom-core.jar      The JAR containing the core JDOM API.
                             Defaults to ${jdom.lib}/build/jdom.jar
        - xml-apis.jar       The JAR containing the DOM, SAX and JAXP classes.
                             Defaults to ${jdom.lib.dir}/xml-apis.jar
        - parser.jar         The JAR containing the XML parser to use.
                             Defaults to ${jdom.lib.dir}/xerces.jar

      Note that any build.properties files located in the user home directory
      (${user.home}) and in the JDOM directory (${jdom.dir}) are also taken
      into account. Thus, JAR settings defined in these files do not need to
      be redefined in the local build.properties.
     -->
    <property file="${user.home}/jdom.build.properties" />
    <property file="${basedir}/build.properties" />

    <!-- JDOM home & libraries -->
    <property name="jdom.dir"           value="../core"/>
    <property name="jdom.lib.dir"       value="${jdom.dir}/lib"/>
    <property name="jdom.build.dir"     value="${jdom.dir}/build"/>

    <!-- Load custom build configuration from JDOM home too. -->
    <property file="${jdom.dir}/build.properties" />

    <property name="Name" value="JDOM Test"/>
    <property name="version" value="1.1.2-snap"/>
    <property name="name" value="jdom-test-${version}"/>
    <property name="year" value="2007"/>

    <echo message="----------- ${Name} ${version} ------------"/>

    <property name="compile.debug"       value="true" />
    <property name="compile.optimize"    value="true" />
    <property name="compile.target"      value="1.5" />
    <property name="compile.source"      value="1.5" />
    <property name="compile.deprecation" value="false" />

    <property name="src.dir" value="./src/java"/>
    <property name="lib.dir" value="./lib"/>
    <property name="packages" value="org.jdom.test.*"/>

    <property name="build.dir" value="./build"/>
    <property name="build.src" value="./build/src"/>
    <property name="build.dest" value="./build/classes"/>
    <property name="build.javadocs" value="./build/apidocs"/>

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

    <filter token="year" value="${year}"/>
    <filter token="version" value="${version}"/>
    <filter token="date" value="${TODAY}"/>
    <filter token="log" value="true"/>
    <filter token="verbose" value="true"/>

    <!-- Default JAR libraries -->
    <property name="xml-apis.jar"       value="${jdom.lib.dir}/xml-apis.jar"/>
    <property name="parser.jar"         value="${jdom.lib.dir}/xerces.jar"/>
    <property name="jdom-core.jar"      value="${jdom.build.dir}/jdom-${version}.jar"/>
    <property name="junit.jar"          value="${lib.dir}/junit.jar"/>

    <!-- Compilation class path -->
    <path id="compile.class.path">
      <pathelement location="${xml-apis.jar}"/>
      <pathelement location="${parser.jar}"/>
      <pathelement location="${jdom-core.jar}"/>
      <pathelement location="${junit.jar}"/>

      <!-- We used to include the CLASSPATH environment variable in
           compilation path as it might contain the path to the JDK 1.1
           collections.  That's not needed anymore.  We'll keep it here
           in case there's a future need to include the CLASSPATH.
      <pathelement path="${java.class.path}" />
       -->
    </path>

    <!-- Tests configuration -->
    <property name="test.jarFile" value="./build/jdom-test.jar"/>
    <property name="test.outputDir" value="./testOutput"/>
    <property name="test.scratchDir" value="./tmp"/>
    <!-- choose between xml and plain text output for tests -->
    <property name="test.outputFormat" value="xml"/>

    <!-- Compilation class path -->
    <path id="test.class.path">
      <path refid="compile.class.path"/>
      <pathelement location="${build.dir}/${name}.jar"/>
    </path>

  </target>

  <!-- =================================================================== -->
  <!-- Help on usage                                                       -->
  <!-- =================================================================== -->
  <target name="usage">
    <echo message=""/>
    <echo message=""/>
    <echo message="JDOM Build file"/>
    <echo message="-------------------------------------------------------------"/>
    <echo message=""/>
    <echo message=" available targets are:"/>
    <echo message=""/>
    <echo message="   package    --> generates the jdom-test.jar file"/>
    <echo message="   compile    --> compiles the contributed source code"/>
    <echo message="   javadoc    --> generates the API documentation"/>
    <echo message="   clean      --> restores the distribution to its clean state"/>
    <echo message="   test       --> runs JUnit tests for all tests in build (default)"/>
    <echo message="   testreport --> build html report from test output"/>
    <echo message="   testui     --> runs JUnit tests with Swing UI"/>
    <echo message=""/>
    <echo message=" See the comments inside the build.xml file for more details."/>
    <echo message="-------------------------------------------------------------"/>
    <echo message=""/>
    <echo message=""/>
  </target>

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

  <!-- =================================================================== -->
  <!-- Prepares the source code                                            -->
  <!-- =================================================================== -->
  <target name="prepare-src" depends="prepare">
    <!-- create directories -->
    <mkdir dir="${build.src}"/>
    <mkdir dir="${build.dest}"/>

    <!-- copy src files -->
    <copy toDir="${build.src}" >
        <fileset dir="${src.dir}" includes="**/*.java, **/*.properties" />
    </copy>

  </target>

  <!-- =================================================================== -->
  <!-- Compiles the source directory                                       -->
  <!-- =================================================================== -->
  <target name="compile" depends="prepare-src">
    <javac srcdir="${build.src}"
           destdir="${build.dest}"
           debug="${compile.debug}"
           optimize="${compile.optimize}"
           target="${compile.target}"
           source="${compile.source}"
           deprecation="${compile.deprecation}">
        <classpath refid="compile.class.path" />
    </javac>
    <copy toDir="${build.dest}" >
      <fileset dir="${build.src}" includes="**/*.properties" />
    </copy>
  
  </target>

  <!-- =================================================================== -->
  <!-- Creates the class package                                           -->
  <!-- =================================================================== -->
  <target name="package" depends="compile">
    <fixcrlf srcdir="." includes="**/*.bat" excludes="build*.*" eol="crlf"/>
    <fixcrlf srcdir="." includes="**/*.sh" excludes="build*.*" eol="lf"/>
    <jar jarfile="${build.dir}/${name}.jar"
         basedir="${build.dest}"
         includes="org/**, **/*.properties"/>
  </target>

  <!-- =================================================================== -->
  <!-- Creates the API documentation                                       -->
  <!-- =================================================================== -->
  <target name="javadoc" depends="prepare-src">
    <mkdir dir="${build.javadocs}"/>
    <javadoc packagenames="${packages}"
             sourcepath="${build.src}"
             destdir="${build.javadocs}"
             author="true"
             version="true"
             use="true"
             splitindex="true"
             noindex="false"
             windowtitle="${Name} API"
             doctitle="${Name}"
             bottom="Copyright &#169; ${year} Brett McLaughlin, Jason Hunter. All Rights Reserved.">
      <classpath refid="compile.class.path"/>
    </javadoc>
  </target>

  <!-- =================================================================== -->
  <!-- Clean targets                                                       -->
  <!-- =================================================================== -->
  <target name="clean" depends="init">
    <delete dir="${build.dir}"/>
    <delete dir="${test.outputDir}"/>
    <delete dir="${test.scratchDir}"/>
  </target>

  <target name="distclean" depends="clean">
    <delete dir="${dist.root}"/>
    <delete file="${Name}-${version}.tar.gz"/>
    <delete file="${Name}-${version}.tar"/>
    <delete file="${Name}-${version}.zip"/>
  </target>
  
  <target name="test" depends="prepare-tests,package">
    <echo message="Running tests against ${jdom-core.jar} using parser ${parser.jar}"/>

    <junit printSummary="yes" fork="true" dir="${basedir}">
      <classpath refid="test.class.path" />
  
      <formatter type="${test.outputFormat}" />

      <batchtest fork="yes" todir="${test.outputDir}">
        <fileset dir="${build.src}">
          <include name="**/*Test*.java" />
          <exclude name="**/generate/**" />
        </fileset>
      </batchtest>
    </junit>
  </target>

  <target name="testreport" >
    <!--ugh, a few oddities.  Xalan must be in the lib directory and
        there must be an optional.jar there.  It won't use variables
        open index.html in the testOutput directory and you do get a
        nice report
    -->

    <junitreport todir="./testOutput">
      <fileset dir="./testOutput">
        <include name="TEST-*.xml"/>
      </fileset>
      <report format="frames" todir="./testOutput"/>
    </junitreport>
  </target>



  <target name="testui" depends="prepare-tests,package">
    <java classname="org.jdom.test.cases.Alltests" fork="true">
      <arg value="-ui" />
      <classpath refid="test.class.path" />
    </java>
  </target>

    <!-- =================================================================== -->
    <!-- Master targets                                                      -->
    <!-- =================================================================== -->
	<target name="master" depends="distclean,package,test,testreport" 
		description="Called from master build.xml" >
	</target>
	

</project>

<!-- End of file -->
