<?xml version="1.0"?>
<!--
 * Copyright 2001-2004 The Apache Software Foundation.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
-->
<!-- 
    @author David Megginson, david@megginson.com
    @author shane_curcuru@lotus.com
    @author Davanum Srinivas, dims@yaoo.com
-->
<project name="xml-commons-external" default="jar" >

  <!-- Name and version information -->
  <property name="name.external" value="xml-commons-external"/>
  <property name="impl.name" value="XmlCommonsExternal"/>
  <!-- If no external version is provided, don't use one -->
  <property name="version" value="1.2.04"/>
  <property name="impl.version" value="${version}"/>

  <!-- Location of the system's temporary directory; all output sent here -->
  <property name="tmp.dir" value="." />

  <!-- Properties to control compilation -->
  <property name="debug" value="off"/>

  <!-- Build directories -->
  <property name="build.dir" value="${tmp.dir}/build" />
  <property name="build.classes.dir" value="${build.dir}/classes" />
  <property name="build.docs.dir" value="${build.dir}/docs" />
  <property name="build.javadocs.dir" value="${build.docs.dir}/javadoc" />
  <property name="external.javadoc.title" value="JAXP 1.2, DOM 2.0, SAX 2.01, SAX2-ext 1.0" />

  <property name="dist.basename" value="${name.external}-${impl.version}" />

  <!-- Source constants and directories -->
  <property name="src.dir" value="src" />
  <property name="docs.dir" value="xdocs" />
  <property name="api.jar.location" value="${build.dir}" />
  <property name="api.jar.name" value="xml-apis.jar" />
  <property name="api.jar" value="${api.jar.location}/${api.jar.name}" />

  <!-- License and readme files of various types -->
  <property name="licenses.external.dir" value="."/>
  <patternset id="licenses.external">
    <include name="LICENSE.dom-documentation.txt" />
    <include name="LICENSE.dom-software.txt" />
    <include name="README.dom.txt" />
    <include name="LICENSE.sax.txt" />
    <include name="README.sax.txt" />
  </patternset>
  <property name="licenses.asf.dir" value="."/>
  <patternset id="licenses.asf" >
    <include name="LICENSE" />  
    <include name="NOTICE" />  
  </patternset>
  <property name="keys.external.dir" value="."/>
  <patternset id="keys.external">
    <include name="KEYS" />
  </patternset>  
  
  

  <target name="all" depends="jar,javadoc,exportsrc,bin.distro"
    description="Jar external classes, create javadoc, create sources.tar.gz, create binary.tar.gz">
  </target>

  <target name="prepare" 
    description="Create build output directories">
    <echo message="Building ${name.external} (version: ${impl.version}) Buildfile: $Revision: 226173 $"/>
    <mkdir dir="${build.classes.dir}" />
    <mkdir dir="${build.docs.dir}" />
    <mkdir dir="${build.javadocs.dir}" />
    <filter token="java.version" value="${java.version}"/>
    <filter token="java.vendor" value="${java.vendor}"/>    
    <filter token="impl.version" value="${impl.version}"/>
    <filter token="impl.name" value="${impl.name}"/>
    <copy file="${src.dir}/org/apache/xmlcommons/Version.src" 
        tofile="${src.dir}/org/apache/xmlcommons/Version.java" 
        filtering="true" preservelastmodified="true" />
    <copy todir="${build.dir}" file="${src.dir}/manifest.commons" filtering="true"/>
  </target>

  <target name="compile" depends="prepare"
    description="Compile all classes">
   <javac srcdir="${src.dir}" destdir="${build.classes.dir}"
          debug="${debug}" />
  </target>

  <target name="jar" depends="compile"
    description="Jar all classes">
    <echo message="Jarring ${api.jar} from ${build.classes.dir}" />

    <!-- Copy various licenses so they appear in the .jar file -->
    <property name="jar-licenses" value="${build.classes.dir}/license" />
    <mkdir dir="${jar-licenses}" />
    <copy todir="${jar-licenses}">
      <fileset dir="${licenses.external.dir}">
        <patternset refid="licenses.external"/>
      </fileset>
      <fileset dir="${licenses.asf.dir}">
        <patternset refid="licenses.asf"/>
      </fileset>
    </copy>

    <jar jarfile="${api.jar}" 
        basedir="${build.classes.dir}" 
        manifest="${build.dir}/manifest.commons"  />
  </target>

  <target name="javadoc" depends="prepare"
    description="Build javadocs and copy doc over">
    <javadoc packagenames="org.xml.sax.*,org.w3c.dom.*,javax.xml.parsers.*,javax.xml.transform.*"
      sourcepath="${src.dir}" 
      destdir="${build.javadocs.dir}" 
      version="yes" 
      windowtitle="${external.javadoc.title}" 
      doctitle="${external.javadoc.title}"
    />
    <!-- Legal question: what should the bottom= copyright line be
         for this mixed set of javadocs? -->
    <!-- Just copy existing .html files over as well -->
    <copy todir="${build.docs.dir}">
      <fileset dir="${docs.dir}"/>
    </copy>
   </target>

  <target name="exportsrc" depends="prepare"
    description="Create a simple distribution of sources">
    <!-- Note: this *only* a copy of the .java sources that 
         go into our .jar file, not all our sources! -->

    <patternset id="external-srcs" >
    <!-- Relative to external/src, which is ${src.dir}  -->
      <include name="org/"/>
      <include name="javax/"/>
    </patternset>

    <tar tarfile="${build.dir}/${name.external}-${impl.version}-src.tar" >
      <tarfileset dir="${src.dir}">
        <patternset refid="external-srcs"/>
      </tarfileset>
      <tarfileset dir="${build.dir}">
        <include name="manifest.commons"/>
      </tarfileset>
      <tarfileset dir="${licenses.external.dir}">
        <patternset refid="licenses.external"/>
      </tarfileset>
      <tarfileset dir="${licenses.asf.dir}">
        <patternset refid="licenses.asf"/>
      </tarfileset>
    </tar>
    
    <!-- Xerces would like a zipped version instead for various reasons
        principally involving CVS limitations.  -->
    <gzip src="${build.dir}/${name.external}-${impl.version}-src.tar" zipfile="${build.dir}/${name.external}-${impl.version}-src.tar.gz"/>
    <delete file="${build.dir}/${name.external}-${impl.version}-src.tar" />
    <zip zipfile="${build.dir}/${name.external}-${impl.version}-src.zip" >
      <zipfileset dir="${src.dir}">
        <patternset refid="external-srcs"/>
      </zipfileset>
      <zipfileset dir="${build.dir}">
        <include name="manifest.commons"/>
      </zipfileset>
      <zipfileset dir="${licenses.external.dir}">
        <patternset refid="licenses.external"/>
      </zipfileset>
      <zipfileset dir="${licenses.asf.dir}">
        <patternset refid="licenses.asf"/>
      </zipfileset>
    </zip>
  </target>

  <target name="bin.distro" depends="jar,javadoc"
    description="Create a binary distribution for xml-common-external">

    <mkdir dir="${build.dir}/${dist.basename}"/>
    <mkdir dir="${build.dir}/${dist.basename}/docs"/>

    <copy todir="${build.dir}/${dist.basename}/docs">
      <fileset dir="${build.docs.dir}"/>
    </copy>
    <copy todir="${build.dir}/${dist.basename}">
      <fileset dir="${build.dir}" includes="xml-apis.jar"/>
      <fileset dir="${build.dir}" includes="manifest.commons"/>  
    </copy>
    <copy todir="${build.dir}/${dist.basename}">
      <fileset dir="${licenses.external.dir}">
        <patternset refid="licenses.external"/>
      </fileset>
      <fileset dir="${licenses.asf.dir}">
        <patternset refid="licenses.asf"/>
      </fileset>
      <fileset dir="${keys.external.dir}">
        <patternset refid="keys.external"/>
      </fileset>      
    </copy>

    <tar tarfile="${build.dir}/${dist.basename}-bin.tar" >
      <tarfileset dir="${build.dir}">
        <include name="${dist.basename}/"/>
      </tarfileset>
    </tar>

    <gzip src="${build.dir}/${dist.basename}-bin.tar" zipfile="${build.dir}/${dist.basename}-bin.tar.gz"/>
    <delete file="${build.dir}/${dist.basename}-bin.tar" />
    <zip zipfile="${build.dir}/${dist.basename}-bin.zip" >
      <zipfileset dir="${build.dir}">
        <include name="${dist.basename}/"/>
      </zipfileset>
    </zip>
  </target>

  <target name="clean" 
      description="Clean the output build area">
    <delete file="${api.jar}"/>
    <delete dir="${build.dir}"/>
    <delete file="${src.dir}/org/apache/xmlcommons/Version.java"/>
  </target>

</project>
