<!-- $Id: build.xml,v 1.57 2009/07/23 06:48:27 jhunter Exp $ -->

<!-- 
For instructions on how to build JDOM, please view the README.txt file.
-->

<project default="package" 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:
        - lib.dir            The directory where to look for the default JAR
                             files.  Defaults to ./lib
        - xml-apis.jar       The JAR containing the DOM, SAX and JAXP classes.
                             Defaults to ${lib.dir}/xml-apis.jar
        - parser.jar         The JAR containing the XML parser to use.
                             Defaults to ${lib.dir}/xerces.jar
        - jaxen.lib.dir      The directory containing the Jaxen JAR libraries.
                             Defaults to ${lib.dir}
     -->
    <property file="${user.home}/jdom.build.properties" />
    <property file="${basedir}/build.properties" />

    <property name="Name" value="JDOM"/>
    <property name="name" value="jdom"/>
    <property name="version" value="1.1.2-snap"/>
    <property name="version.impl" value="${version}"/>
    <property name="version.spec" value="1.0"/>
    <property name="year" value="2011"/>

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

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

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

    <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}"/>

    <property name="package.dir" value="./package"/>

    <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="${lib.dir}/xml-apis.jar"/>
    <property name="parser.jar"         value="${lib.dir}/xerces.jar"/>
    <property name="jdom-core"          value="${build.dest}"/>
    <property name="jaxen.lib.dir"      value="${lib.dir}"/>

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

      <fileset dir="${jaxen.lib.dir}">
        <include name="jaxen.jar"/>
        <include name="saxpath*.jar"/>
      </fileset>

      <!-- 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>

    <path id="run.class.path">
      <path refid="compile.class.path"/>
      <pathelement location="${jdom-core}"/>
    </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.jar file (default)"/>
    <echo message="   compile  --> compiles the source code"/>
    <echo message="   javadoc  --> generates the API documentation"/>
    <echo message="   clean    --> cleans up the directory"/>
    <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 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}"
          filtering="yes">
      <fileset dir="${src.dir}"/>
    </copy>
  </target>

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

    <!-- copy src files -->
    <copy todir="${samples.dest}"
          filtering="yes">
          <fileset dir="${samples.dir}"/>
    </copy>
  </target>

  <!-- =================================================================== -->
  <!-- Compiles the source directory                                       -->
  <!-- =================================================================== -->
  <target name="compile" depends="prepare-src"
          description="Compiles the source code">
    <!-- Compile the JaxenXPath adapter only if Jaxen classes are found -->
    <available property="jaxen.present"
               classname="org.jaxen.JaxenException"
               classpathref="compile.class.path"/>

    <javac srcdir="${build.src}"
           destdir="${build.dest}"
           debug="${compile.debug}"
           optimize="${compile.optimize}"
           target="${compile.target}"
           source="${compile.source}"
           deprecation="${compile.deprecation}">

      <exclude name="**/Jaxen*" unless="jaxen.present"/>

      <classpath refid="compile.class.path"/>
    </javac>
  </target>

  <!-- =================================================================== -->
  <!-- Compiles the "About" code unless JDK1.1 is being used               -->
  <!-- =================================================================== -->
  <target name="about" depends="init"
          description="Compiles the About code">
  	<!-- putting classes in default package is poor form -->
  	<echo message="JDOMAbout is not longer deployed" />
    <!-- javac srcdir="${package.dir}"
           destdir="${build.dest}"
           debug="${compile.debug}"
           optimize="${compile.optimize}"
           target="${compile.target}"
           source="${compile.source}"
           deprecation="${compile.deprecation}">
      <classpath refid="compile.class.path"/>
    </javac -->
  </target>

  <!-- =================================================================== -->
  <!-- Compiles the samples directory                                      -->
  <!-- =================================================================== -->
  <target name="samples" depends="prepare-samples,package"
          description="Compiles the samples directory">
    <javac srcdir="${samples.dest}"
           destdir="${samples.dest}"
           debug="${compile.debug}"
           optimize="${compile.optimize}"
           target="${compile.target}"
           source="${compile.source}"
           deprecation="${compile.deprecation}">
      <classpath refid="run.class.path"/>
    </javac>
  </target>

  <!-- =================================================================== -->
  <!-- Creates the class package                                           -->
  <!-- =================================================================== -->
  <target name="package" depends="compile,javadoc"
          description="Creates the class package">
    <fixcrlf srcdir="." includes="**/*.bat" excludes="build*.*" eol="crlf"/>
    <fixcrlf srcdir="." includes="**/*.sh" excludes="build*.*" eol="lf"/>

    <!-- Filters defined specifically for updating the manifest -->
    <filter token="version.spec" value="${version.spec}"/>
    <filter token="version.impl" value="${version.impl}"/>
    <copy todir="${build.dest}/META-INF"
          filtering="yes">
          <fileset dir="${package.dir}/META-INF"/>
          <fileset dir=".">
                <include name="LICENSE.txt"/>
          </fileset>
    </copy>
    <jar jarfile="${build.dir}/${name}-${version.impl}.jar"
         basedir="${build.dest}"
         excludes="META-INF/MANIFEST.MF"
         manifest="${build.dest}/META-INF/MANIFEST.MF"/>
    <jar jarfile="${build.dir}/${name}-${version.impl}-sources.jar"
         basedir="${build.src}" />
    <jar jarfile="${build.dir}/${name}-${version.impl}-javadoc.jar"
         basedir="${build.javadocs}" />
  </target>

  <!-- =================================================================== -->
  <!-- Creates the API documentation                                       -->
  <!-- =================================================================== -->
  <target name="javadoc" depends="prepare-src"
          description="Creates the API documentation">
    <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} v${version}"
             doctitle="${Name} v${version}&lt;br&gt;API Specification"
             header="&lt;b&gt;${Name}&lt;br&gt;&lt;font size='-1'&gt;${version}&lt;/font&gt;&lt;/b&gt;"
             bottom="Copyright &#169; ${year} Jason Hunter, Brett McLaughlin. All Rights Reserved.">
      <classpath refid="run.class.path"/>
    </javadoc>
  </target>

  <!-- =================================================================== -->
  <!-- Creates the API documentation, with links to JDK 1.4 classes        -->
  <!-- We can use linkoffline with a newer Ant and avoid this target       -->
  <!-- =================================================================== -->
  <target name="javadoc-link" depends="prepare-src"
          description="Creates the API documentation with links to JDK 1.4 classes">
    <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} v${version}"
             doctitle="${Name} v${version}&lt;br&gt;API Specification"
             header="&lt;b&gt;${Name}&lt;br&gt;&lt;font size='-1'&gt;${version}&lt;/font&gt;&lt;/b&gt;"
             bottom="Copyright &#169; ${year} Jason Hunter, Brett McLaughlin. All Rights Reserved.">
      <classpath refid="run.class.path"/>

      <link href="http://java.sun.com/j2se/1.4/docs/api"/>
    </javadoc>
  </target>

  <!-- =================================================================== -->
  <!-- Clean targets                                                       -->
  <!-- =================================================================== -->
  <target name="clean" depends="init"
          description="Removes build files">
    <delete dir="${build.dir}"/>
  </target>

  <target name="distclean" depends="clean"
          description="Removes the dist files">
    <delete dir="${dist.root}"/>
    <delete file="${Name}-${version}.tar.gz"/>
    <delete file="${Name}-${version}.tar"/>
    <delete file="${Name}-${version}.zip"/>
  </target>

    <!-- =================================================================== -->
    <!-- Master targets                                                      -->
    <!-- =================================================================== -->
	<target name="master" depends="distclean,package" 
		description="Called from master build.xml" >
	</target>
	
</project>
<!-- End of file -->
