<?xml version="1.0"?>

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

    <!-- =================================================================== -->
    <!-- Initializes some variables                                          -->
    <!-- =================================================================== -->
    <target name="init">
        <property name="Name" value="helma"/>
        <property name="year" value="1998-2001"/>
        <property name="version" value="1.2"/>
        <property name="project" value="helma"/>
        <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="cvs.root" value=":pserver:anonymous@coletta.helma.at:/opt/cvs"/>
        <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="${cvs.root}" package="hop" dest="${build.checkout}"/>
	<cvs cvsRoot="${cvs.root}" package="apps/hopblog" dest="${build.dir}"/>
        <cvs cvsRoot="${cvs.root}" package="hopbuild/lib" dest="${build.dir}"/>
	<cvs cvsRoot="${cvs.root}" package="hopbuild/skeleton" 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">
        <mkdir dir="${final.dir}"/>
 	<!-- mkdir dir="${final.dir}/static"/ -->
 	<mkdir dir="${final.dir}/src"/>
        <jar jarfile="${final.dir}/src/${Name}-src.jar"
            basedir="${build.src}"/>
        <!-- copy todir="${final.dir}/src">
            <fileset dir="${build.dir}/src"/>
        </copy -->
        <copy todir="${final.dir}/docs">
            <fileset dir="../docs"/>
        </copy>
        <copy todir="${final.dir}/lib">
            <fileset dir="../lib"/>
        </copy>
        <copy todir="${final.dir}">
            <fileset dir="${build.dir}/hopbuild/skeleton"/>
        </copy>
        <copy todir="${final.dir}/apps/base">
            <fileset dir="${build.dir}/apps/hopblog" excludes="**/CVS"/>
        </copy>
 	<copy file="${build.dir}/${jar.name}.jar" todir="${final.dir}/lib"/>
        <chmod file="${final.dir}/hop.sh" perm="755"/>
   </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=".." excludes="**">
             <tarfileset dir=".." mode="755">
                  <include name="${final.name}/hop.sh"/>
             </tarfileset>
             <tarfileset dir="..">
                  <include name="${final.name}/**"/>
                  <exclude name="${final.name}/hop.sh"/>
	     </tarfileset>
        </tar>
        <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>

    <!-- =================================================================== -->
    <!-- Packages and FTPs the distribution with ZIP and TAG-GZIP            -->
    <!-- =================================================================== -->
    <target name="ftp-all" depends="package-all">
        <ftp server="piefke.helma.at"
            userid="anonymous"
            password="tobi@helma.at">
            <fileset dir="${build.dir}">
                 <include name="${Name}-${version}.zip,${Name}-${version}.tar.gz"/>
            </fileset>
        </ftp>
    </target>


    <target name="ftp-test" depends="">
         <ftp server="piefke.helma.at"
            userid="anonymous"
            password="tobi@helma.at">
            <fileset dir="${build.dir}">
                 <include name="${Name}-${version}.zip,${Name}-${version}.tar.gz"/>
            </fileset>
        </ftp>
    </target>


</project>



