<?xml version="1.0"?>

<!-- ======================================================================= -->
<!-- Hop build file                                                      -->
<!-- ======================================================================= -->
<project name="Hop" default="main" basedir=".">

    <!-- =================================================================== -->
    <!-- Initializes some variables                                          -->
    <!-- =================================================================== -->
    <target name="init">
        <property name="Name" value="Hop"/>
        <property name="year" value="1998-2001"/>
        <property name="version" value="1.0.beta1"/>
        <property name="project" value="hop"/>
        <property name="build.compiler" value="classic"/>
        <property name="build.dir" value="../work"/>
        <property name="build.src" value="${build.dir}/src"/>
        <property name="build.dest" value="${build.dir}/classes"/>
        <property name="build.checkout" value="${build.dir}/checkout"/>
        <property name="javadoc.destdir" value="../docs/apidocs"/>
        <property name="jar.name" value="helma"/>
        <property name="final.name" value="${project}-${version}"/>
        <property name="final.dir" value="../${final.name}/"/>
        <property name="debug" value="off"/>
        <property name="optimize" value="on"/>
        <property name="deprecation" value="off"/>

        <tstamp/>

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

        <!-- JDK1.1 collections support -->
        <property name="coll.import" value="com.sun.java.util.collections"/>
        <available classname="${coll.import}.Collection" property="coll.present"/>

    </target>

    <!-- =================================================================== -->
    <!-- Copies the source code to the build directory and does filtering    -->
    <!-- =================================================================== -->
    <target name="prepare" depends="init">
        <mkdir dir="${build.dir}"/>
        <mkdir dir="${build.dest}"/>
        <mkdir dir="${build.src}"/>
        <mkdir dir="${build.checkout}"/>

        <cvs cvsRoot=":pserver:anonymous@coletta.helma.at:/opt/cvs"
            package="hop"
            dest="${build.checkout}"/>

        <cvs cvsRoot=":pserver:anonymous@coletta.helma.at:/opt/cvs"
            package="hopbuild/lib"
            dest="${build.dir}"/>

        <copy todir="${build.src}">
            <fileset dir="${build.checkout}/hop"
                includes="helma/**/*.java,FESI/**/*.java,Acme/**/*.java"/>
        </copy>

    </target>

    <!-- =================================================================== -->
    <!-- Does replacement on files for dealing with collections.             -->
    <!-- XXX The efficiency could be improved here; all replacements should  -->
    <!-- XXX happen during one read/write phase and only for files that have -->
    <!-- XXX changed.                                                        -->
    <!-- =================================================================== -->
    <target name="collections" if="coll.present" depends="prepare">
      <replace dir="${build.src}/helma" includes="**"
             token="java.util.Collection" value="${coll.import}.Collection"/>
      <replace dir="${build.src}/helma" includes="**"
             token="java.util.Map" value="${coll.import}.Map"/>
      <replace dir="${build.src}/helma" includes="**"
             token="java.util.HashMap" value="${coll.import}.HashMap"/>
      <replace dir="${build.src}/helma" includes="**"
             token="java.util.List" value="${coll.import}.List"/>
      <replace dir="${build.src}/helma" includes="**"
             token="java.util.LinkedList" value="${coll.import}.LinkedList"/>
      <replace dir="${build.src}/helma" includes="**"
             token="java.util.ArrayList" value="${coll.import}.ArrayList"/>
      <replace dir="${build.src}/helma" includes="**"
             token="java.util.Set" value="${coll.import}.Set"/>
      <replace dir="${build.src}/helma" includes="**"
             token="java.util.HashSet" value="${coll.import}.HashSet"/>
      <replace dir="${build.src}/helma" includes="**"
             token="java.util.Iterator" value="${coll.import}.Iterator"/>
      <!-- The following replace handles the "import java.util.*" case by    -->
      <!-- adding an "import com.sun.java.util.collections.*" after it.      -->
      <!-- BTW, \u000a is the Unicode escape for a new line. (jhunter)       -->
      <replace dir="${build.src}/helma/framework/core" includes="**"
             token="java.util.*"
             value="java.util.*;\u000aimport ${coll.import}.*"/>
      <replace dir="${build.src}/helma/objectmodel" includes="**"
             token="java.util.*"
             value="java.util.*;\u000aimport ${coll.import}.*"/>
    </target>


    <!-- =================================================================== -->
    <!-- Compiles the source directory                                       -->
    <!-- =================================================================== -->
    <target name="compile" depends="prepare">
        <javac srcdir="${build.src}"
            destdir="${build.dest}"
            debug="${debug}"
            deprecation="${deprecation}"
            optimize="${optimize}">
            <classpath>
                <fileset dir="${build.dir}/hopbuild/lib">
                     <include name="**/*.jar" />
                </fileset>
                <pathelement path="${classpath}" />
            </classpath>
        </javac>

        <rmic classname="helma.framework.core.Application" base="${build.dest}"/>
        <rmic classname="helma.image.Server" base="${build.dest}"/>
        <rmic classname="helma.image.RemoteImage" base="${build.dest}"/>

    </target>

    <!-- =================================================================== -->
    <!-- Creates a .jar file               -->
    <!-- =================================================================== -->
    <target name="jar" depends="compile">
        <jar jarfile="${build.dir}/${jar.name}.jar"
            basedir="${build.dest}"
            excludes="**/package.html"/>
    </target>

    <!-- =================================================================== -->
    <!-- Creates the API documentation                                       -->
    <!-- =================================================================== -->
    <target name="javadocs" depends="prepare">
        <mkdir dir="${javadoc.destdir}"/>
        <javadoc packagenames="helma.*"
            sourcepath="${build.src}"
            destdir="${javadoc.destdir}"
            author="false"
            private="false"
            version="false"
            windowtitle="${Name} ${version} API"
            doctitle="${Name} ${version} API"
            bottom="Copyright &#169; 1998-2001 Helma.org. All Rights Reserved."
        />
    </target>

    <!-- =================================================================== -->
    <!-- Package                                                             -->
    <!-- =================================================================== -->
    <target name="package" depends="jar,javadocs">
        <mkdir dir="${final.dir}"/>
        <copydir src="${build.dir}/src/" dest="${final.dir}/src/"/>
        <copydir src="../docs" dest="${final.dir}/docs"/>
        <copydir src="../lib" dest="${final.dir}/lib"/>
        <copydir src="../build" dest="${final.dir}/build"/>
        <copyfile src="${build.dir}/${final.name}.jar" dest="${final.dir}/${final.name}.jar"/>
    </target>

    <!-- =================================================================== -->
    <!-- Packages the distribution with ZIP                                  -->
    <!-- =================================================================== -->
    <target name="package-zip" depends="package">
        <zip zipfile="../${Name}-${version}.zip" basedir="../" includes="**/${final.name}/**"/>
    </target>

    <!-- =================================================================== -->
    <!-- Packages the distribution with TAR-GZIP                             -->
    <!-- =================================================================== -->
    <target name="package-tgz" depends="package">
        <tar tarfile="../${Name}-${version}.tar" basedir="../" includes="**/${final.name}/**"/>
        <gzip zipfile="../${Name}-${version}.tar.gz" src="../${Name}-${version}.tar"/>
    </target>

    <!-- =================================================================== -->
    <!-- Packages the distribution with ZIP and TAG-GZIP                     -->
    <!-- =================================================================== -->
    <target name="package-all" depends="package-zip, package-tgz">
    </target>

    <!-- =================================================================== -->
    <!-- Packages just the jar with ZIP                                  -->
    <!-- =================================================================== -->
    <target name="snapshot" depends="jar">
        <copy file="${build.dir}/${jar.name}.jar" tofile="../helma-${DSTAMP}.jar"/>
    </target>


</project>