<?xml version="1.0"?>
<!--
 * Licensed to the Apache Software Foundation (ASF) under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The ASF licenses this file to You 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.
-->
<project name="xml-commons-resolver" default="all" >
<description>
Build file for org.apache.xml.resolver. 

Dependencies: none for building code (except using Ant 1.5+ to build).
For documentation, see comments - requires forrest and requires that 
you build the xml-commons overall site first.
Also, you probably want to set -Ddocbook.dir=/somewhere/docbook
Also, you may need to adjust src/documentation/sitemap.xmap 
    near "wild assumption about location of DocBook stylesheets".

@author Norman.Walsh@Sun.COM
@author shane_curcuru@yahoo.com
</description>

  <!-- Name and version information -->
  <property name="name.resolver" value="xml-commons-resolver"/>
  <property name="impl.name" value="XmlResolver"/>
  <property name="impl.version" value="1.2"/>

  <!-- Allow properties following these statements to be overridden -->
  <!-- Note that all of these don't have to exist.  They've just been defined
       incase they are used. -->
  <property file="build.properties"/>
  <property file=".ant.properties"/>
  <property file="${user.home}/.ant.properties"/>
  <property file="default.properties"/>

  <!-- Location of where to put our build output -->
  <property name="tmp.dir" value="."/>

  <!-- Build directories -->
  <property name="build.dir" value="${tmp.dir}/build"/>
  <property name="build.classes.dir" value="${build.dir}/classes"/>
  <property name="build.etc.dir" value="${build.classes.dir}/org/apache/xml/resolver/etc"/>
  <property name="docs.dir" value="${build.dir}"/>
  <property name="docs.user.dir" value="${docs.dir}/docs"/>
  <property name="docs.java.dir" value="${docs.dir}/apidocs/resolver"/>
  <property name="docs.site.dir" value="../build/site"/>
  <property name="docs.src.dir"
    value="../src/documentation/content/xdocs/components/resolver"/>
  <property name="dist.basename" value="${name.resolver}-${impl.version}"/> 

  <!-- Source constants and directories -->
  <property name="src.dir" value="src" />
  <property name="etc.dir" value="etc" />
  <property name="resolver.subdir" value="org/apache/xml/resolver" />
  <property name="resolver.jar.location" value="${build.dir}" />
  <property name="resolver.jar.name" value="resolver.jar" />
  <property name="resolver.jar" value="${resolver.jar.location}/${resolver.jar.name}" />

  <!-- NOTE: Removed jaxp.jar/xmlParserAPIs.jar/xerces2.jar since Ant 
       already natively has those in it's classpath already. Sep-03 -sc -->

  <!-- Test results directory -->
  <property name="check.dir" value="${tmp.dir}/${project.name}/check"/>

  <!-- Build properties -->
  <property name="build.debug" value="on"/>
  <property name="build.deprecation" value="on"/>
  <property name="build.optimize" value="off"/>

  <!-- Document constants -->
  <property name="company.name" value="Apache Software Foundation"/>

  <property name="copyright.date" value="2001-2003"/>
  <property name="copyright.message"
            value="Copyright &#169; ${copyright.date} ${company.name}. All Rights Reserved."/>

  <!-- Public Targets -->
  <target name="main"
          depends="all,check"
          description="Alias for all, check."/>

  <target name="all"
          depends="jar,docs"
          description="This is the default target.  Compiles the program and docs.">
  </target>

  <target name="gump"
          depends="jar,javadocs"
          description="This is the gump target.  Compiles the program and generates javadoc.">
  </target>

  <target name="compile" depends="init"
    description="Compile all classes">

   <echo message="Compiling..." />

   <javac srcdir="${src.dir}" destdir="${build.classes.dir}" debug="true" optimize="true" deprecation="true" verbose="false">
     <!-- <classpath> not needed since Ant already supplies these Sep-03 -sc -->
     <include name="${resolver.subdir}/*.java"/>
     <include name="${resolver.subdir}/helpers/*.java"/>
     <include name="${resolver.subdir}/readers/*.java"/>
     <include name="${resolver.subdir}/tools/*.java"/>
     <include name="${resolver.subdir}/apps/*.java"/>
   </javac>
  </target>

  <target name="jar" depends="compile"
    description="Jar all classes">
    <echo message="Jarring ${resolver.jar} from ${build.classes.dir}" />
    <copy todir="${build.classes.dir}">
      <fileset dir="${src.dir}" includes="**/*.properties"/>
    </copy>
    <copy todir="${build.etc.dir}">
      <fileset dir="${etc.dir}"/>
    </copy>

    <jar jarfile="${resolver.jar}" manifest="${build.dir}/manifest.resolver" basedir="${build.classes.dir}" index="true" />
  </target>

  <target name="install">
    <echo message="${name.resolver} currently doesn&apos;t support install."/>
  </target>

  <target name="uninstall">
    <echo message="${name.resolver} currently doesn&apos;t support uninstall."/>
  </target>

  <target name="clean"
          description="Deletes all files that are generated by the build.">
    <delete dir="${build.dir}"/>
    <delete file="${src.dir}/${resolver.subdir}/Version.java"/>
  </target>

  <target name="distclean"
          depends="clean"
          description="Deletes all files that a left from clean and returns the project to its distributed state.">
  </target>

  <target name="docs"
          depends="javadocs,htmldocs"
          description="Generates all documentation for a project.">
  </target>

  <target name="javadocs"
          depends="init"
          description="Generates the JavaDocs for the project.">

    <mkdir dir="${docs.java.dir}"/>
	  <javadoc sourcepath="${src.dir}"
		   destdir="${docs.java.dir}"
                   Overview="${src.dir}/${resolver.subdir}/overview.html"
                   author="true"
                   version="true"
                   use="true"
		   windowtitle="${name.resolver} API"
		   doctitle="${name.resolver}"
		   bottom="${copyright.message}">
            <package name="org.apache.xml.resolver"/>
            <package name="org.apache.xml.resolver.helpers"/>
            <package name="org.apache.xml.resolver.readers"/>
            <package name="org.apache.xml.resolver.tools"/>
            <package name="org.apache.xml.resolver.apps"/>
	  </javadoc>
  </target>

  <target name="htmldocs" depends="jar">
    <echo message="Building docs for ${name.resolver} ..." />
<!-- Note: The docs are built in two ways until we stabilise the doc generation.
Both ways have system-specific pathnames, so both may bust on your system.
-->
    <property name="xalan.jar" value="../../xml-xalan/java/build/classes"/>
    <property name="docbook.dir" value="../../docbook"/>

    <java fork="true" classname="org.apache.xalan.xslt.Process">
      <classpath>
	<pathelement location="${xalan.jar}"/>
	<pathelement location="${build.dir}/resolver.jar"/>
    <pathelement path="${java.class.path}"/>
      </classpath>
<!-- why doesn't this work???
      <arg value="-URIRESOLVER"/>
      <arg value="org.apache.xml.resolver.tools.CatalogResolver"/>
      <arg value="-ENTITYRESOLVER"/>
      <arg value="org.apache.xml.resolver.tools.CatalogResolver"/>
-->
      <arg value="-IN"/>
      <arg value="${docs.src.dir}/resolver-article.xml"/>
      <arg value="-OUT"/>
      <arg value="${build.dir}/docs/resolver.html"/>
      <arg value="-XSL"/>
      <arg value="${docbook.dir}/html/docbook.xsl"/>
    </java>
    <java fork="true" classname="org.apache.xalan.xslt.Process">
      <classpath>
	<pathelement location="${xalan.jar}"/>
	<pathelement location="${build.dir}/resolver.jar"/>
    <pathelement path="${java.class.path}"/>
      </classpath>
      <arg value="-URIRESOLVER"/>
      <arg value="org.apache.xml.resolver.tools.CatalogResolver"/>
      <arg value="-ENTITYRESOLVER"/>
      <arg value="org.apache.xml.resolver.tools.CatalogResolver"/>
      <arg value="-IN"/>
      <arg value="${docs.src.dir}/resolver-release-notes.xml"/>
      <arg value="-OUT"/>
      <arg value="${build.dir}/docs/release-notes.html"/>
      <arg value="-XSL"/>
      <arg value="${docbook.dir}/html/docbook.xsl"/>
    </java>

    <!-- Copy the docs that Forrest built. -->
    <copy todir="${build.dir}/docs" failonerror="false">
      <fileset dir="${docs.site.dir}/components/resolver"
               includes="resolver-*.html"/>
    </copy>
  </target>

  <target name="dist"
          depends="all, docs"
          description="Generates all the artifacts used for a distribution.">
    <mkdir dir="${build.dir}/${dist.basename}"/>
    <mkdir dir="${build.dir}/${dist.basename}/src"/>
    <mkdir dir="${build.dir}/${dist.basename}/etc"/>
        
    <!-- Copy all sources and original source manifest -->
    <copy todir="${build.dir}/${dist.basename}/src">
      <fileset dir="${src.dir}" includes="${resolver.subdir}/"/>
      <fileset dir="${src.dir}" includes="manifest.resolver"/>
    </copy>  
    <!-- Must include etc dir so distro downloaders can rebuild from source -->
    <copy todir="${build.dir}/${dist.basename}/etc">
      <fileset dir="${etc.dir}" />
    </copy>  

    <!-- Copy docs/javadocs -->
    <copy todir="${build.dir}/${dist.basename}/docs">
      <fileset dir="${docs.user.dir}"/>
    </copy>
    <copy todir="${build.dir}/${dist.basename}/apidocs/resolver">
      <fileset dir="${docs.java.dir}"/>
    </copy>

    <!-- Copy pertinent top-level files and the .jar -->
    <copy todir="${build.dir}/${dist.basename}">
      <fileset dir=".." includes="KEYS"/>
      <fileset dir="." includes="resolver.xml"/>
      <fileset dir="src/org/apache/xml/resolver" includes="LICENSE.resolver.txt"/>
      <fileset dir="src/org/apache/xml/resolver" includes="NOTICE-resolver.txt"/>
    </copy>
    <copy todir="${build.dir}/${dist.basename}" file="${resolver.jar}"/>

    <!-- Note: we really should create separate bin and src distros, to 
         follow everyone else's standards, but I don't have time now Sep-03 -sc -->
    <tar tarfile="${build.dir}/${dist.basename}.tar" >
      <tarfileset dir="${build.dir}">
        <include name="${dist.basename}/"/>
      </tarfileset>
    </tar>

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

  <target name="test"
          depends="check"
          description="Alias for check">
  </target>

  <target name="check"
          depends="jar"
          description="Compile and execute any tests.">
    <echo message="BEGIN Simple test: just call resolver (manual verification required)."/>
    <java fork="true" classname="org.apache.xml.resolver.apps.resolver">
      <classpath>
        <pathelement location="/share/projects/apache/xml-xerces/java/build/xercesImpl.jar"/>
        <pathelement location="${resolver.jar}"/>
        <pathelement path="${java.class.path}"/>
      </classpath>
    </java>
    <echo message="END Simple test: just call resolver (manual verification required)."/>
  </target>

  <!-- Internal Targets -->
  <target name="init">
    <echo message="Building ${name.resolver} (version: ${impl.version}) Buildfile: $Revision$"/>
    <mkdir dir="${build.classes.dir}" />
    <mkdir dir="${build.etc.dir}" />
    <mkdir dir="${docs.user.dir}" />
    <mkdir dir="${docs.java.dir}" />
    <filter token="impl.version" value="${impl.version}"/>
    <filter token="impl.name" value="${impl.name}"/>
    <copy todir="${build.dir}" file="${src.dir}/manifest.resolver" filtering="true"/>
    <copy tofile="${src.dir}/${resolver.subdir}/Version.java" file="${src.dir}/${resolver.subdir}/Version.src" filtering="true"/>
  </target>
</project>
