<?xml version="1.0"?>
<!--
    The contents of this file are subject to the Mozilla Public License Version 1.1
    (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.mozilla.org/MPL/>.

    Software distributed under the License is distributed on an "AS IS" basis, WITHOUT
    WARRANTY OF ANY KIND, either express or implied. See the License for the specific
    language governing rights and limitations under the License.

    The Original Code is the Venice Web Communities System.

    The Initial Developer of the Original Code is Eric J. Bowersox <erbo@ricochet.com>,
    for Silverwrist Design Studios.  Portions created by Eric J. Bowersox are
    Copyright (C) 2001-2004 Eric J. Bowersox/Silverwrist Design Studios.  All Rights Reserved.

    Contributor(s): 
-->
<project name="Venice" default="deploy">

  <!-- ============================================================================
    Load build properties
    ============================================================================ -->

  <property file="build.properties"/>

  <!-- ============================================================================
    Default build properties
    ============================================================================ -->

  <!-- [Compilation control flags] -->
  <property name="compile.debug" value="on"/>
  <property name="compile.deprecation" value="on"/>
  <property name="compile.optimize" value="off"/>
  <property name="build.compiler" value="modern"/>

  <!-- [Target directories] -->
  <property name="deploy.home" value="../venice"/>
  <property name="javadoc.home" value="${deploy.home}/javadoc"/>

  <!-- [Location of Servlet API 2.3] -->
  <property name="servlet.base" value="../servletapi"/>
  <property name="servlet.lib" value="${servlet.base}/lib"/>
  <property name="servlet.jarfile" value="servlet.jar"/>

  <!-- [Location of Commons Collections Library 2.1] -->
  <property name="collections.base" value="../commons-collections"/>
  <property name="collections.lib" value="${collections.base}"/>
  <property name="collections.jarfile" value="commons-collections.jar"/>

  <!-- [Location of Commons Codec Library 1.2] -->
  <property name="codec.base" value="../commons-codec"/>
  <property name="codec.lib" value="${codec.base}"/>
  <property name="codec.jarfile" value="commons-codec-1.2.jar"/>

  <!-- [Location of Jakarta Regexp Library 1.3] -->
  <property name="regexp.base" value="../jakarta-regexp"/>
  <property name="regexp.lib" value="${regexp.base}"/>
  <property name="regexp.jarfile" value="jakarta-regexp-1.3.jar"/>

  <!-- [Location of Log4J 1.2.8] -->
  <property name="log4j.base" value="../log4j"/>
  <property name="log4j.lib" value="${log4j.base}/dist/lib"/>
  <property name="log4j.jarfile" value="log4j-1.2.8.jar"/>

  <!-- [Location of Bean Scripting Framework 2.3] -->
  <property name="bsf.base" value="../bsf"/>
  <property name="bsf.lib" value="${bsf.base}/lib"/>
  <property name="bsf.jarfile" value="bsf.jar"/>

  <!-- [Location of Jacl 1.3.1] -->
  <property name="jacl.base" value="../jacl"/>
  <property name="jacl.lib" value="${jacl.base}"/>
  <property name="jacl.jarfile" value="jacl.jar"/>
  <property name="jacl.tcljarfile" value="tcljava.jar"/>

  <!-- [Location of Rhino 1.5R4.1] -->
  <property name="rhino.base" value="../rhino"/>
  <property name="rhino.lib" value="${rhino.base}"/>
  <property name="rhino.jarfile" value="js.jar"/>

  <!-- ============================================================================
    Path references
    ============================================================================ -->

  <path id="base.build.path">
    <fileset dir="${servlet.lib}" includes="${servlet.jarfile}"/>
    <fileset dir="${collections.lib}" includes="${collections.jarfile}"/>
    <fileset dir="${codec.lib}" includes="${codec.jarfile}"/>
    <fileset dir="${regexp.lib}" includes="${regexp.jarfile}"/>
    <fileset dir="${log4j.lib}" includes="${log4j.jarfile}"/>
    <fileset dir="${bsf.lib}" includes="${bsf.jarfile}"/>
  </path>

  <!-- ============================================================================
    "buildprep" - Creates the build directories
    ============================================================================ -->

  <target name="buildprep">
    <mkdir dir="buildwork"/>
    <mkdir dir="jars"/>
  </target>

  <!-- ============================================================================
    "compile" - Compile all the Java source
    ============================================================================ -->

  <target name="compile" depends="buildprep">
    <javac srcdir="src" destdir="buildwork" debug="${compile.debug}" optimize="${compile.optimize}"
           deprecation="${compile.deprecation}">
      <classpath>
	<pathelement location="buildwork"/>
        <path refid="base.build.path"/>
      </classpath>
    </javac>
    <copy todir="buildwork">
      <fileset dir="src" includes="**/*.properties"/>
    </copy>
  </target>

  <!-- ============================================================================
    "jar" - Create the JAR file of all the Java compiled code
    ============================================================================ -->

  <target name="jar" depends="compile">
    <jar destfile="jars/venice001.jar" basedir="buildwork"/>
  </target>

  <!-- ============================================================================
    "mkbasedirs" - Creates the base directories for "fastupdate"
    ============================================================================ -->

  <target name="mkbasedirs">
    <mkdir dir="${deploy.home}"/>
    <mkdir dir="${deploy.home}/WEB-INF"/>
    <mkdir dir="${deploy.home}/WEB-INF/scripts"/>
    <mkdir dir="${deploy.home}/WEB-INF/rpcscripts"/>
  </target>

  <!-- ============================================================================
    "fastupdate" - Copies everything to the deployment directory that can be
                   copied without a restart.
    ============================================================================ -->

  <target name="fastupdate" depends="mkbasedirs">
    <copy todir="${deploy.home}"> <!-- this copies all the JSP files and stuff -->
      <fileset dir="web"/>
    </copy>
    <copy todir="${deploy.home}/WEB-INF/scripts">  <!-- this copies all the scripts -->
      <fileset dir="scripts"/>
    </copy>
    <copy todir="${deploy.home}/WEB-INF/rpcscripts">  <!-- this copies all the RPC scripts -->
      <fileset dir="rpcscripts"/>
    </copy>
  </target>

  <!-- ============================================================================
    "deploy" - Copy everything to the deployment directory, including stuff that
               requires a restart to take effect.
    ============================================================================ -->

  <target name="deploy" depends="jar,fastupdate">
    <copy todir="${deploy.home}/WEB-INF">
      <fileset dir="etc">
	<include name="*.xml"/>
	<include name="*.css"/>
        <include name="*.dict"/>
      </fileset>
    </copy>
    <mkdir  dir="${deploy.home}/WEB-INF/classes"/>
    <mkdir  dir="${deploy.home}/WEB-INF/lib"/>
    <copy todir="${deploy.home}/WEB-INF/lib">
      <fileset dir="${collections.lib}" includes="${collections.jarfile}"/>
      <fileset dir="${codec.lib}" includes="${codec.jarfile}"/>
      <fileset dir="${regexp.lib}" includes="${regexp.jarfile}"/>
      <fileset dir="${log4j.lib}" includes="${log4j.jarfile}"/>
      <fileset dir="${bsf.lib}" includes="${bsf.jarfile}"/>
      <!-- <fileset dir="${jacl.lib}" includes="${jacl.jarfile}, ${jacl.tcljarfile}"/> -->
      <fileset dir="${rhino.lib}" includes="${rhino.jarfile}"/>
      <fileset dir="lib" includes="*.jar"/>
      <fileset dir="jars" includes="venice001.jar"/>
    </copy>
    <mkdir  dir="${deploy.home}/WEB-INF/tlds"/>
    <copy todir="${deploy.home}/WEB-INF/tlds">
      <fileset dir="tlds">
        <include name="*.tld"/>
      </fileset>
    </copy>
    <mkdir  dir="${deploy.home}/WEB-INF/temp"/>
  </target>

  <!-- ============================================================================
    "javadoc" - Create Javadocs
    ============================================================================ -->

  <target name="javadoc" depends="mkbasedirs">
    <mkdir dir="${javadoc.home}"/>
    <javadoc sourcepath="src" packagenames="*" destdir="${javadoc.home}"/>
  </target>

  <!-- ============================================================================
    "clean" - Cleans up all stuff that was built
    ============================================================================ -->

  <target name="clean">
    <delete dir="${deploy.home}"/>
    <delete dir="buildwork"/>
    <delete dir="jars"/>
  </target>

  <!-- ============================================================================
    "all" - Build entire project
    ============================================================================ -->

  <target name="all" depends="clean,deploy,javadoc"/>

</project>
