<?xml version="1.0"?>

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

Build file for Xerces-Java

Notes:
   This is a build file for use with the Jakarta Ant build tool.

Installation Instructions:
   To install Ant on your system, you need to checkout the
   "jakarta-tools" CVS module. Then you should place the files
     - ant.jar
     - projectx-tr2.jar
     - javac.jar
   in your classpath.

Build Instructions:
   To build, run

     java org.apache.tools.ant.Main <target>

   on the directory where this file is located with the target you want.
   There is also a batch file called "build.bat" to invoke Ant from a
   Windows command line shell. On the UNIX platform, use "build.sh" shell
   script to invoke Ant.

Most useful targets:

 - package -> creates the "xerces.jar" package in "./build"
 - docs -> creates the HTML documentation in "./build/docs"
 - javadocs - crates the javadocs in "./build/javadocs"
 - dist -> creates the complete distribution
 - site -> regenerates the web site

Note:

  In order to regenerate the web site, you must have the "xml-site" and "xml-xerces"
  CVS modules checked-out in the same directory, or this won't work. for example

    xml.apache.org/xml-site
    xml.apache.org/xml-xerces
    ...

  Have fun!

Authors:
  Stefano Mazzocchi <stefano@apache.org>
  Anupam Bagchi     <abagchi@apache.org>

Copyright:
  Copyright (c) 2000 The Apache Software Foundation.

   $Id$

==================================================================== -->

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

  <target name="init">
    <property name="name" value="xerces"/>
    <property name="Name" value="Xerces-J"/>
    <property name="version" value="1.1.0"/>
    <property name="version_postfix" value="_1_1_0"/>
    <property name="year" value="1999-2000"/>
	<property name="copyright" value="Copyright &#169; ${year} Apache XML Project. All Rights Reserved."/>

	<echo message= "---------------- ${Name} ${version} [${year}] ---------------"/>
    <property name="build.compiler" value="classic"/>
    <property name="debug" value="off"/>
    <property name="optimize" value="on"/>
    <property name="deprecation" value="off"/>

    <property name="src.dir" value="./src"/>
    <property name="docs.dir" value="./docs"/>
    <property name="data.dir" value="./data"/>
    <property name="samples.dir" value="./samples"/>
    <property name="tests.dir" value="./tests"/>
    <property name="tools.dir" value="./tools"/>
    <property name="docs.book" value="${docs.dir}/docs-book.xml"/>
    <property name="version.file" value="org/apache/xerces/framework/Version.java"/>

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

    <property name="doc.generator" value="org.apache.stylebook.StyleBook"/>
    <property name="doc.generator.package" value="${tools.dir}/stylebook-1.0-b2.jar"/>
    <property name="doc.style" value="${tools.dir}/style-apachexml.jar"/>

    <property name="build.dir" value="./build"/>
    <property name="build.src" value="${build.dir}/src"/>
    <property name="build.dest" value="${build.dir}/classes"/>
    <property name="build.docs" value="${build.dir}/docs/html"/>
    <property name="build.samples" value="${build.dir}/samples"/>
    <property name="build.tests" value="${build.dir}/tests"/>
    <property name="build.data" value="${build.dir}/data"/>
    <property name="build.javadocs" value="${build.dir}/docs/apiDocs"/>

    <property name="distsrc.dir" value="${build.dir}/${Name}-src${version_postfix}"/>
    <property name="distbin.dir" value="${build.dir}/${Name}-bin${version_postfix}"/>

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

  </target>

  <!-- =================================================================== -->
  <!-- Help on usage                                                       -->
  <!-- =================================================================== -->
  <target name="usage">
    <echo message=""/>
    <echo message=""/>
    <echo message="${Name} Build instructions"/>
    <echo message="-------------------------------------------------------------"/>
    <echo message=""/>
    <echo message=" available targets are:"/>
    <echo message=""/>
    <echo message="   compile  --> compiles the source code"/>
    <echo message="   jar      --> generates the xerces.jar file"/>
    <echo message="   samples  --> compiles the samples source code"/>
    <echo message="   tests    --> compiles the tests source code"/>
    <echo message="   sampjar  --> generates the xercesSamples.jar file"/>
    <echo message="   jars     --> generates the xerces and xercesSamples jar files"/>
    <echo message="   docs     --> generates the HTML documentation"/>
    <echo message="   javadocs --> generates the API documentation (needs Java 1.2 or higher)"/>
    <echo message="   pack-src --> generates the source distributions of Xerces-Java (zip and tar.gz)"/>
    <echo message="   pack-bin --> generates the binary distributions of Xerces-Java (zip and tar.gz)"/>
    <echo message="   all      --> generates the binary and source distributions of Xerces-Java"/>
    <echo message="   test     --> runs a sanity test on the sample files"/>
    <echo message="   clean    --> cleans up all generated files and directories"/>
    <echo message="   usage    --> provides help on using the build tool (default)"/>
    <echo message=""/>
    <echo message=" See 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>

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

    <!-- copy src files -->
    <copydir src="${src.dir}" dest="${build.src}" includes="**/Makefile, **/Makefile.incl, javax/**, org/**"
             excludes="**/classfiles_updated **/CVS* **/.#*
                       **/SchemaImporter.java **/RevalidatingDOMParser.java
                       **/DatatypeContentModel.java **/ComplexTypeInfo.java
                       **/DTDImporter.java "/>
	<deltree dir="${build.src}/whiteboard"/>

    <!-- substitute tokens as needed -->
    <replace file="${build.src}/${version.file}" token="@@version@@" value="${version}"/>
    <!-- <replace file="${build.src}/${version.file}" token="@@year@@" value="${year}"/> -->
  </target>

  <!-- =================================================================== -->
  <!-- Compiles the source directory                                       -->
  <!-- =================================================================== -->
  <target name="compile" depends="prepare-src">
    <javac srcdir="${build.src}"
    	   destdir="${build.dest}"
    	   debug="${debug}"
	       deprecation="${deprecation}"
	       optimize="${optimize}" />
  </target>

  <!-- =================================================================== -->
  <!-- Creates the class package                                           -->
  <!-- =================================================================== -->
  <target name="jar" depends="compile">
    <jar jarfile="${build.dir}/${name}.jar"
         basedir="${build.dest}"
         includes="org/**, javax/**"/>
  </target>

  <!-- =================================================================== -->
  <!-- Compiles the samples                                                -->
  <!-- =================================================================== -->
  <target name="samples" depends="jar">
    <mkdir dir="${build.samples}"/>
    <copydir src="${samples.dir}" dest="${build.samples}" />
    <javac srcdir="${build.samples}"
           destdir="${build.dest}"
           classpath="${build.dir}/${name}.jar"
           debug="${debug}"/>
  </target>

  <!-- =================================================================== -->
  <!-- Compiles the tests                                                  -->
  <!-- =================================================================== -->
  <target name="tests" depends="jar">
    <mkdir dir="${build.tests}"/>
    <copydir src="${tests.dir}" dest="${build.tests}" />
    <javac srcdir="${build.tests}"
           destdir="${build.dest}"
           classpath="${build.dir}/${name}.jar"
           debug="${debug}"/>
  </target>

  <!-- =================================================================== -->
  <!-- Creates the samples package                                         -->
  <!-- =================================================================== -->
  <target name="sampjar" depends="samples">
    <jar jarfile="${build.dir}/${name}Samples.jar"
         basedir="${build.dest}"
         includes="dom/**,sax/**,ui/**"/>
  </target>

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

  <!-- =================================================================== -->
  <!-- Generate HTML docs                                                  -->
  <!-- =================================================================== -->
  <target name="docs" depends="prepare, prepare-docs">
	<echo message="Building docs for ${Name} ${version} ..." />
    <java fork="yes"
          classpath="${java.class.path}:${doc.generator.package}"
          classname="${doc.generator}"
          args="targetDirectory=${build.docs} ${docs.book} ${doc.style}"/>
  </target>

  <!-- =================================================================== -->
  <!-- Creates the API documentation                                       -->
  <!-- =================================================================== -->
  <target name="javadocs" depends="prepare-src">
    <mkdir dir="${build.javadocs}"/>
    <javadoc packagenames="${packages}"
             sourcepath="${build.src}"
             destdir="${build.javadocs}"
             author="true"
             version="true"
             use="true"
             windowtitle="${Name} API"
             doctitle="${Name}"
             bottom="${copyright}" />
  </target>

  <!-- =================================================================== -->
  <!-- Prepares the source distribution                                    -->
  <!-- =================================================================== -->
  <target name="pack-src" depends="init">
    <echo message="Building the source distribution files (zip,tar)"/>
    <mkdir dir="${distsrc.dir}"/>
    <mkdir dir="${distsrc.dir}/src"/>
    <mkdir dir="${distsrc.dir}/data"/>
    <mkdir dir="${distsrc.dir}/docs"/>
    <mkdir dir="${distsrc.dir}/samples"/>

    <copydir src="${src.dir}" dest="${distsrc.dir}/src" excludes="**/CVS*, **/.#*"
             includes="**/Makefile, **/Makefile.incl, org/**, javax/**"/>
    <copydir src="${data.dir}" dest="${distsrc.dir}/data" excludes="**/CVS*, **/.#*"/>
    <copydir src="${docs.dir}" dest="${distsrc.dir}/docs"
             excludes="**/CVS*, **/*.#*, pdf/**, html/**, **/apiDocs*"/>
    <copydir src="${samples.dir}" dest="${distsrc.dir}/samples" excludes="**/CVS*, **/*.#*"/>

    <copyfile src="LICENSE" dest="${distsrc.dir}/LICENSE"/>
    <copyfile src="README" dest="${distsrc.dir}/README"/>
    <copyfile src="Readme.html" dest="${distsrc.dir}/Readme.html"/>
    <copyfile src="STATUS" dest="${distsrc.dir}/STATUS"/>
    <copyfile src="build.xml" dest="${distsrc.dir}/build.xml"/>
    <copyfile src="${basedir}/build.sh" dest="${distsrc.dir}/build.sh" />
    <chmod src="${distsrc.dir}/build.sh" perm="ugo+rx" />
    <copyfile src="${basedir}/build.bat" dest="${distsrc.dir}/build.bat" />

    <zip zipfile="${build.dir}/${Name}-src${version_postfix}.zip" basedir="${build.dir}"
         includes="${Name}-src${version_postfix}/**"/>
    <tar tarfile="${build.dir}/${Name}-src${version_postfix}.tar" basedir="${build.dir}"
         includes="${Name}-src${version_postfix}/**"/>
    <gzip zipfile="${build.dir}/${Name}-src${version_postfix}.tar.gz"
          src="${build.dir}/${Name}-src${version_postfix}.tar" />
  </target>

  <!-- =================================================================== -->
  <!-- Prepares the binary distribution                                    -->
  <!-- =================================================================== -->
  <target name="pack-bin" depends="jar, sampjar, javadocs, docs">

    <echo message="Building the binary distribution files (zip,tar)"/>
    <mkdir dir="${distbin.dir}"/>
    <mkdir dir="${distbin.dir}/data"/>
    <mkdir dir="${distbin.dir}/docs"/>
    <mkdir dir="${distbin.dir}/docs/html"/>
    <mkdir dir="${distbin.dir}/docs/apiDocs"/>

    <copydir src="${data.dir}" dest="${distbin.dir}/data" excludes="**/CVS*, **/*.#*"/>
    <copydir src="${build.docs}" dest="${distbin.dir}/docs/html"/>
    <copydir src="${build.javadocs}" dest="${distbin.dir}/docs/apiDocs"/>

    <copyfile src="${build.dir}/${name}.jar" dest="${distbin.dir}/${name}.jar"/>
    <copyfile src="${build.dir}/${name}Samples.jar" dest="${distbin.dir}/${name}Samples.jar"/>

    <copyfile src="LICENSE" dest="${distbin.dir}/LICENSE"/>
    <copyfile src="Readme.html" dest="${distbin.dir}/Readme.html"/>

    <zip zipfile="${build.dir}/${Name}-bin${version_postfix}.zip" basedir="${build.dir}"
         includes="${Name}-bin${version_postfix}/**"/>
    <tar tarfile="${build.dir}/${Name}-bin${version_postfix}.tar" basedir="${build.dir}"
         includes="${Name}-bin${version_postfix}/**"/>
    <gzip zipfile="${build.dir}/${Name}-bin${version_postfix}.tar.gz"
          src="${build.dir}/${Name}-bin${version_postfix}.tar" />

  </target>

  <!-- =================================================================== -->
  <!-- Do a sanity test using xercesSamples.jar                            -->
  <!-- =================================================================== -->
  <target name="test" depends="sampjar">
	<echo message="Performing sanity test for ${Name} ${version} ..." />
	<echo message="Using classpath=&apos;${build.dir}/${name}Samples.jar;${build.dir}/${name}.jar&apos;" />
	<echo message="Running SAXCount ..." />
    <java fork="yes"
          classpath="${build.dir}/${name}Samples.jar:${build.dir}/${name}.jar;"
          classname="sax.SAXCount"
          args="${data.dir}/personal.xml"/>
	<echo message="Running SAXWriter ..." />
    <java fork="yes"
          classpath="${build.dir}/${name}Samples.jar:${build.dir}/${name}.jar"
          classname="sax.SAXWriter"
          args="${data.dir}/personal.xml"/>
	<echo message="Running DOMCount ..." />
    <java fork="yes"
          classpath="${build.dir}/${name}Samples.jar:${build.dir}/${name}.jar"
          classname="dom.DOMCount"
          args="${data.dir}/personal.xml"/>
	<echo message="Running DOMWriter ..." />
    <java fork="yes"
          classpath="${build.dir}/${name}Samples.jar:${build.dir}/${name}.jar"
          classname="dom.DOMWriter"
          args="${data.dir}/personal.xml"/>
	<echo message="Running DOMFilter ..." />
    <java fork="yes"
          classpath="${build.dir}/${name}Samples.jar:${build.dir}/${name}.jar"
          classname="dom.DOMFilter"
          args="-p dom.wrappers.DOMParser ${data.dir}/personal.xml"/>
    <!-- The following are samples but not command-line applications.
	<echo message="Running IteratorView ..." />
    <java fork="yes"
          classpath="${build.dir}/${name}Samples.jar:${build.dir}/${name}.jar"
          classname="dom.traversal.IteratorView"
          args="${data.dir}/personal.xml"/>
	<echo message="Running TreeWalkerView ..." />
    <java fork="yes"
          classpath="${build.dir}/${name}Samples.jar:${build.dir}/${name}.jar"
          classname="dom.traversal.TreeWalkerView"
          args="${data.dir}/personal.xml"/>
	<echo message="Running TreeViewer ..." />
    <java fork="yes"
          classpath="${build.dir}/${name}Samples.jar:${build.dir}/${name}.jar"
          classname="dom.TreeViewer"
          args="${data.dir}/personal.xml"/>
     -->
  </target>

  <!-- =================================================================== -->
  <!-- Builds both xerces and sample jar files                             -->
  <!-- =================================================================== -->
  <target name="jars" depends="jar, sampjar">
  </target>

  <!-- =================================================================== -->
  <!-- Builds and packages sources and binary distributions                -->
  <!-- =================================================================== -->
  <target name="all" depends="pack-src, pack-bin">
  </target>

  <!-- =================================================================== -->
  <!-- Cleans everything                                                   -->
  <!-- =================================================================== -->
  <target name="clean" depends="init">
    <delete file="${name}.jar"/>
    <delete file="${name}Samples.jar"/>
    <deltree dir="${build.dir}"/>
  </target>

</project>
