<?xml version="1.0" encoding="UTF-8"?>
<!--

Ant buildfile for 'FreeMarker' application. Compatible with Ant version 1.3.

Authors:  Alex Petrushko <alpet@ocf.berkeley.edu>
          Nicholas Cull <run2000@users.sourceforge.net>
      Jonathan Revusky <jon@revusky.com>
      Attila Szegedi <szegedia@users.sourceforge.net>

Version: $Id: build.xml,v 1.138.2.4 2006/12/27 16:11:23 szegedia Exp $

-->

<project basedir="." default="jar" name="freemarker"
        xmlns:javacc="http://javacc.dev.java.net/"
        xmlns:docgen="http://freemarker.org/docgen"
>

    <property name="libs.location" value="http://freemarker.sourceforge.net/jarsforbuild"/>
    <property name="repositoryRootDir" value="../../../"/>

    <property file="src/freemarker/version.properties" />
    <property name="src.dir" value="src"/>
    <property name="lib.dir" value="lib"/>
    <property name="examples.dir" value="examples"/>
    <property name="build.dir" value="build"/>
    <property name="build.examples.dir" value="build/examples"/>
    <property name="build.jython-webapp.dir" value="${build.examples.dir}/jython-webapp"/>
    <property name="build.classes.dir" value="build/classes"/>
    <property name="build.javadoc.dir" value="build/api" />
    <property name="build.manual.dir" value="build/manual" />
    <property name="testcase.dir" value="build/testcase"/>
    <property name="dist.dir" value="build/dist"/>
    <property name="dist.dir.versioned" value="${dist.dir}/freemarker-${version}"/>
    <property name="docgen.dir" value="../docgen" />
    <property name="javadoc.use" value="yes" /> <!-- when tar dir deepth limit is a problem, set to "no" -->

    <property name="freemarker.tar" value="build/freemarker-${version}.tar" />
    <property name="freemarker.gzip" value="${freemarker.tar}.gz" />

    <property name="lib.javarebel-sdk" location="lib/javarebel-sdk.jar"/>
    <property name="lib.xml-apis" location="lib/xml-apis.jar"/>
    <property name="lib.jdom" location="lib/jdom.jar"/>
    <property name="lib.jaxen" location="lib/jaxen.jar"/>
    <property name="lib.xalan" location="lib/xalan.jar"/>
    <property name="lib.saxpath" location="lib/saxpath.jar"/>
    <property name="lib.log4j" location="lib/log4j.jar"/>
    <property name="lib.logkit" location="lib/logkit.jar"/>
    <property name="lib.slf4j" location="lib/slf4j-api.jar"/>
    <property name="lib.commons-logging" location="lib/commons-logging.jar"/>
    <property name="lib.xerces" location="lib/xerces.jar"/>
    <property name="lib.junit" location="lib/junit.jar"/>
    <property name="lib.dom4j" location="lib/dom4j.jar"/>
    <property name="lib.struts" location="lib/struts.jar"/>
    <property name="lib.rhino" location="lib/js.jar"/>
    <property name="lib.servlet" location="lib/servlet.jar"/>
    <property name="lib.jsp12" location="lib/jsp-api-1.2.jar"/>
    <property name="lib.jsp20" location="lib/jsp-api-2.0.jar"/>
    <property name="lib.jsp21" location="lib/jsp-api-2.1.jar"/>
    
    <property name="lib.jython20" location="lib/jython-2.0.jar"/>
    <property name="lib.jython22" location="lib/jython-2.2.1.jar"/>
    <property name="lib.jython25" location="lib/jython-2.5.jar"/>
    <!-- If not overridden, use default -->
    <property name="boot.class.path" value="${sun.boot.class.path}"/>
    <!-- Path elements to dependencies -->

    <path id="compile.nomultiversion.classpath">
        <pathelement path="${lib.servlet}"/>
        <pathelement path="${lib.xml-apis}"/>
        <pathelement path="${lib.jdom}"/>
        <pathelement path="${lib.jaxen}"/>
        <pathelement path="${lib.dom4j}"/>
        <pathelement path="${lib.saxpath}"/>
        <pathelement path="${lib.xalan}"/> <!-- Xalan is not included with Sun JRE 1.5! -->
        <pathelement path="${lib.logkit}"/>
        <pathelement path="${lib.log4j}"/>
        <pathelement path="${lib.slf4j}"/>
        <pathelement path="${lib.commons-logging}"/>
        <pathelement path="${lib.rhino}"/>
        <pathelement path="${lib.javarebel-sdk}"/>
        <pathelement path="${java.class.path}"/>
    </path>
    
    <path id="compile.classpath">
        <path refid="compile.nomultiversion.classpath"/>
        <pathelement path="${lib.jsp21}"/>
    </path>

    <path id="compile.jsp1.classpath">
        <path refid="compile.nomultiversion.classpath"/>
        <pathelement path="${lib.jsp12}"/>
    </path>

    <path id="compile.jsp2.classpath">
    <path refid="compile.nomultiversion.classpath"/>
    <pathelement path="${lib.jsp20}"/>
    </path>
    
    <path id="compile.jython20.classpath">
        <path refid="compile.nomultiversion.classpath"/>
        <pathelement path="${lib.jython20}"/>
    </path>
    
    <path id="compile.jython22.classpath">
        <path refid="compile.nomultiversion.classpath"/>
        <pathelement path="${lib.jython22}"/>
    </path>
    
    <path id="compile.jython25.classpath">
        <path refid="compile.nomultiversion.classpath"/>
        <pathelement path="${lib.jython25}"/>
    </path>
    
    <path id="compile.classpath.testcases">
        <pathelement path="${lib.junit}"/>
        <pathelement path="${lib.jython25}"/>
        <pathelement path="${lib.jdom}"/>
        <pathelement path="${lib.servlet}"/>
        <pathelement path="${lib.jsp20}"/>
    </path>

    <path id="compile.classpath.javadoc">
        <pathelement path="${lib.xerces}"/>
        <pathelement path="${lib.jdom}"/>
        <pathelement path="${lib.dom4j}"/>
        <pathelement path="${lib.rhino}"/>
        <pathelement path="${lib.jaxen}"/>
        <pathelement path="${lib.jython22}"/>
        <pathelement path="${lib.saxpath}"/>
        <pathelement path="${lib.xalan}"/> <!-- Xalan is not included with Sun JRE 1.5 with the old classname! -->
        <pathelement path="${lib.servlet}"/>
        <pathelement path="${lib.jsp21}"/>
        <pathelement path="${lib.logkit}"/>
        <pathelement path="${lib.log4j}"/>
        <pathelement path="${lib.slf4j}"/>
        <pathelement path="${lib.commons-logging}"/>
        <pathelement path="${src.dir}"/>
        <pathelement path="${java.class.path}"/>
        <pathelement path="${lib.javarebel-sdk}"/>
    </path>

    <path id="compile.classpath.examples">
        <pathelement path="${lib.servlet}"/>
        <pathelement path="${lib.dir}/freemarker.jar"/>
        <pathelement path="${lib.struts}"/>
    </path>
    
    <!-- Pattern set for FreeMarker compilation -->
    <patternset id="freemarker.compile">
        <include name="freemarker/cache/**"/>
        <include name="freemarker/debug/**"/>
        <include name="freemarker/ext/**"/>
        <include name="freemarker/log/**"/>
        <include name="freemarker/core/**" />
        <include name="freemarker/template/**"/>
        <exclude name="freemarker/core/RegexBuiltins.java"/>
        <exclude name="freemarker/ext/ant/**"/>
        <exclude name="freemarker/ext/beans/EnumModels.java"/>
        <exclude name="freemarker/ext/dom/XalanXPathSupport.java"/>
        <exclude name="freemarker/ext/dom/SunInternalXalanXPathSupport.java"/>
        <exclude name="freemarker/ext/dom/JaxenXPathSupport.java"/>
        <exclude name="freemarker/ext/jdom/NodeListModel.java"/>
        <exclude name="freemarker/ext/jython/**"/>
        <exclude name="freemarker/ext/jruby/**"/>
        <exclude name="freemarker/ext/jsp/TaglibFactory.java"/>
        <exclude name="freemarker/ext/jsp/FreeMarkerPageContext1.java"/>
        <exclude name="freemarker/ext/jsp/FreeMarkerPageContext2.java"/>
        <exclude name="freemarker/ext/jsp/FreeMarkerJspFactory2.java"/>
        <exclude name="freemarker/ext/rhino/**"/>
        <exclude name="freemarker/ext/xml/Dom4jNavigator.java"/>
        <exclude name="freemarker/ext/xml/JdomNavigator.java"/>
        <exclude name="freemarker/log/AvalonLoggerFactory.java"/>
        <exclude name="freemarker/log/JDK14LoggerFactory.java"/>
        <exclude name="freemarker/log/Log4JLoggerFactory.java"/>
        <exclude name="freemarker/template/utility/JythonRuntime.java"/>
        <exclude name="freemarker/template/utility/J2SE14TimeZoneOffsetCalculator.java"/>
    </patternset>

    <!-- Pattern set for FreeMarker jar -->
    <patternset id="freemarker.jar">
        <include name="freemarker/**"/>
    </patternset>

    <patternset id="freemarker.compile.jdk14">
        <include name="freemarker/log/JDK14LoggerFactory.java"/>
        <include name="freemarker/core/RegexBuiltins.java"/>
        <include name="freemarker/template/utility/J2SE14TimeZoneOffsetCalculator.java"/>
    </patternset>

    <patternset id="freemarker.compile.jdk15">
        <include name="freemarker/ext/beans/EnumModels.java"/>
        <include name="freemarker/ext/dom/SunInternalXalanXPathSupport.java"/>
    </patternset>

    <patternset id="freemarker.compile.xalan">
        <include name="freemarker/ext/dom/XalanXPathSupport.java"/>
    </patternset>
    
    <patternset id="freemarker.compile.logkit">
        <include name="freemarker/log/AvalonLoggerFactory.java"/>
    </patternset>

    <patternset id="freemarker.compile.log4j">
        <include name="freemarker/log/Log4JLoggerFactory.java"/>
    </patternset>

    <patternset id="freemarker.compile.slf4j">
        <include name="freemarker/log/SLF4JLoggerFactory.java"/>
    </patternset>
    
    <patternset id="freemarker.compile.commons-logging">
        <include name="freemarker/log/CommonsLoggingLoggerFactory.java"/>
    </patternset>
    
    <patternset id="freemarker.compile.dom4j">
        <include name="freemarker/ext/xml/Dom4jNavigator.java"/>
    </patternset>

    <patternset id="freemarker.compile.jaxen">
        <include name="freemarker/ext/dom/JaxenXPathSupport.java"/>
    </patternset>

    <patternset id="freemarker.compile.jdom">
        <include name="freemarker/ext/jdom/NodeListModel.java"/>
        <include name="freemarker/ext/xml/JdomNavigator.java"/>
    </patternset>

    <patternset id="freemarker.compile.jython20">
        <include name="freemarker/ext/ant/**"/>
        <include name="freemarker/template/utility/JythonRuntime.java"/>
        <include name="freemarker/ext/jython/**"/>
        <exclude name="freemarker/ext/jython/Jython22VersionAdapter.java"/>
        <exclude name="freemarker/ext/jython/Jython25VersionAdapter.java"/>
    </patternset>

    <patternset id="freemarker.compile.jython22">
        <include name="freemarker/ext/jython/Jython22VersionAdapter.java"/>
    </patternset>

    <patternset id="freemarker.compile.jython25">
        <include name="freemarker/ext/jython/Jython25VersionAdapter.java"/>
    </patternset>
    
    <patternset id="freemarker.compile.rhino">
        <include name="freemarker/ext/rhino/**"/>
    </patternset>

    <patternset id="freemarker.compile.jsp1">
        <include name="freemarker/ext/jsp/TaglibFactory.java"/>
        <include name="freemarker/ext/jsp/FreeMarkerPageContext1.java"/>
    </patternset>

    <patternset id="freemarker.compile.jsp2">
        <include name="freemarker/ext/jsp/FreeMarkerPageContext2.java"/>
        <include name="freemarker/ext/jsp/FreeMarkerJspFactory2.java"/>
    </patternset>

    <!-- Pattern set for FreeMarker test case compilation -->
    <patternset id="freemarker.compile.testcases">
        <include name="freemarker/testcase/**"/>
    </patternset>

    <!-- Pattern set for FreeMarker test case test files -->
    <patternset id="freemarker.testcases">
        <include name="freemarker/testcase/reference/**"/>
        <include name="freemarker/testcase/template/**"/>
        <include name="freemarker/testcase/servlets/reference/**"/>
        <include name="freemarker/testcase/servlets/template/**"/>
        <include name="freemarker/testcase/servlets/WEB-INF/**"/>
        <include name="freemarker/testcase/*.properties"/>
        <include name="freemarker/testcase/*.xml"/>
        <include name="freemarker/testcase/models/*.properties"/>
    </patternset>

    <!-- Pattern set for FreeMarker JavaDoc -->
    <patternset id="freemarker.javadoc.files">
        <exclude name="manual/**"/>
    </patternset>

    <!-- Pattern set for FreeMarker distribution -->
    <patternset id="freemarker.distribution.src">
        <include name="build.xml"/>
        <include name="examples/**"/>
        <include name="LICENSE.txt"/>
        <include name="NOTICE.txt"/>
        <include name="README.txt"/>
        <include name="src/**"/>
        <include name="examples/**"/>
        <exclude name="**/CVS/**"/>
        <exclude name="**/*.bak"/>
        <exclude name="**/src/**/*.class" />
        <exclude name="**/src/**/*.LOCK" />
        <exclude name="**/.nbattrs" />
    </patternset>

    <target name="fetchlibs" unless="all.libs.present" description="fetch build dependencies and put them in lib directory">
        <mkdir dir="lib"/>
        <echo>Fetching libraries from server.</echo>
        <get src="${libs.location}/README.txt" dest="lib/README.txt" usetimestamp="true"/>
        <get src="${libs.location}/ant.jar" dest="lib/ant.jar" usetimestamp="true"/>
        <get src="${libs.location}/xml-apis.jar" dest="lib/xml-apis.jar" usetimestamp="true"/>
        <get src="${libs.location}/dom4j.jar" dest="lib/dom4j.jar" usetimestamp="true"/>
        <get src="${libs.location}/emma.jar" dest="lib/emma.jar" usetimestamp="true"/>
        <get src="${libs.location}/emma_ant.jar" dest="lib/emma_ant.jar" usetimestamp="true"/>
        <get src="${libs.location}/javacc.jar" dest="lib/javacc.jar" usetimestamp="true"/>
        <get src="${libs.location}/freemarker-bootstrap.jar" dest="lib/freemarker-bootstrap.jar" usetimestamp="true"/>
        <get src="${libs.location}/jaxen.jar" dest="lib/jaxen.jar" usetimestamp="true"/>
        <get src="${libs.location}/javarebel-sdk.jar" dest="lib/javarebel-sdk.jar" usetimestamp="true"/>
        <get src="${libs.location}/2.3/jdom.jar" dest="lib/jdom.jar" usetimestamp="true"/>
        <get src="${libs.location}/js.jar" dest="lib/js.jar" usetimestamp="true"/>
        <get src="${libs.location}/junit.jar" dest="lib/junit.jar" usetimestamp="true"/>
        <get src="${libs.location}/jython-2.0.jar" dest="lib/jython-2.0.jar" usetimestamp="true"/>
        <get src="${libs.location}/jython-2.2.1.jar" dest="lib/jython-2.2.1.jar" usetimestamp="true"/>
        <get src="${libs.location}/jython-2.5.jar" dest="lib/jython-2.5.jar" usetimestamp="true"/>
        <get src="${libs.location}/log4j.jar" dest="lib/log4j.jar" usetimestamp="true"/>
        <get src="${libs.location}/2.3/logkit.jar" dest="lib/logkit.jar" usetimestamp="true"/>
        <get src="${libs.location}/slf4j-api.jar" dest="lib/slf4j-api.jar" usetimestamp="true"/>
        <get src="${libs.location}/slf4j-jdk14.jar" dest="lib/slf4j-jdk14.jar" usetimestamp="true"/> <!-- Needed only for testing SLF4J: -->
        <get src="${libs.location}/commons-logging.jar" dest="lib/commons-logging.jar" usetimestamp="true"/>
        <get src="${libs.location}/2.3/rt122.jar" dest="lib/rt122.jar" usetimestamp="true"/>
        <get src="${libs.location}/saxpath.jar" dest="lib/saxpath.jar" usetimestamp="true"/>
        <get src="${libs.location}/servlet.jar" dest="lib/servlet.jar" usetimestamp="true"/>
        <get src="${libs.location}/struts.jar" dest="lib/struts.jar" usetimestamp="true"/>
        <get src="${libs.location}/jsp-api-1.2.jar" dest="lib/jsp-api-1.2.jar" usetimestamp="true"/>
        <get src="${libs.location}/jsp-api-2.0.jar" dest="lib/jsp-api-2.0.jar" usetimestamp="true"/>
        <get src="${libs.location}/jsp-api-2.1.jar" dest="lib/jsp-api-2.1.jar" usetimestamp="true"/>
        <get src="${libs.location}/xalan.jar" dest="lib/xalan.jar" usetimestamp="true"/>
    </target>

    <target name="init">
        <condition property="all.libs.present">
            <and>
                <available file="lib/README.txt"/>
                <available file="lib/ant.jar"/>
                <available file="lib/xml-apis.jar"/>
                <available file="lib/dom4j.jar"/>
                <available file="lib/emma.jar"/>
                <available file="lib/emma_ant.jar"/>
                <available file="lib/javacc.jar"/>
                <available file="lib/freemarker-bootstrap.jar"/>
                <available file="lib/javarebel-sdk.jar"/>
                <available file="lib/jaxen.jar"/>
                <available file="lib/jdom.jar"/>
                <available file="lib/js.jar"/>
                <available file="lib/junit.jar"/>
                <available file="lib/jython-2.0.jar"/>
                <available file="lib/jython-2.2.1.jar"/>
                <available file="lib/jython-2.5.jar"/>
                <available file="lib/log4j.jar"/>
                <available file="lib/logkit.jar"/>
                <available file="lib/slf4j-api.jar"/>
                <available file="lib/slf4j-jdk14.jar"/>
                <available file="lib/commons-logging.jar"/>
                <available file="lib/rt122.jar"/>
                <available file="lib/saxpath.jar"/>
                <available file="lib/servlet.jar"/>
                <available file="lib/struts.jar"/>
                <available file="lib/jsp-api-1.2.jar"/>
                <available file="lib/jsp-api-2.0.jar"/>
                <available file="lib/jsp-api-2.1.jar"/>
                <available file="lib/xalan.jar"/>
            </and>
        </condition>
        <antcall target="fetchlibs"/>
        <available
            property="log4j.available"
            classname="org.apache.log4j.Logger"
            classpathref="compile.classpath"/>
        <available
            property="logkit.available"
            classname="org.apache.log.Logger"
            classpathref="compile.classpath"/>
        <available
            property="slf4j.available"
            classname="org.slf4j.Logger"
            classpathref="compile.classpath"/>
        <available
            property="commons-logging.available"
            classname="org.apache.commons.logging.Log"
            classpathref="compile.classpath"/>
        <available
            property="jdk14.available"
            classname="java.util.logging.Logger"
            classpathref="compile.classpath"/>
        <available
            property="jdk15.available"
            classname="java.lang.Enum"
            classpathref="compile.classpath"/>
        <available
            property="jython20.available"
            file="${lib.jython20}"/>
        <available
            property="jython22.available"
            file="${lib.jython22}"/>
        <available
            property="jython25.available"
            file="${lib.jython25}"/>
        <available
            property="jsp21.available"
            classname="javax.el.ELResolver"
            classpathref="compile.classpath"/>
        <available
            property="dom4j.available"
            classname="org.dom4j.Node"
            classpathref="compile.classpath"/>
        <available
            property="jaxen.available"
            classname="org.jaxen.XPath"
            classpathref="compile.classpath"/>
        <available
            property="jdom.available"
            classname="org.jdom.Element"
            classpathref="compile.classpath"/>
        <available
            property="rhino.available"
            classname="org.mozilla.javascript.Scriptable"
            classpathref="compile.classpath"/>
        <available
            property="xalan.available"
            classname="org.apache.xpath.XPathAPI"
            classpathref="compile.classpath" />
    <uptodate property="parser.gen"
                targetfile="src/freemarker/core/FMParser.jj">
        <srcfiles dir="src/freemarker/core" includes="FMParser.java" />
    </uptodate>
    </target>
    
    <!-- The build targets begin here -->
    <target depends="" name="clean" description="Erase the deployment tree">
        <delete dir="${build.dir}" />
        <delete file="${lib.dir}/freemarker.jar" />
        <delete dir="docs"/>
        <delete file="src/freemarker/core/FMParser.java" />
        <delete file="src/freemarker/core/FMParserConstants.java" />
        <delete file="src/freemarker/core/FMParserTokenManager.java" />
        <delete file="src/freemarker/core/SimpleCharStream.java" />
        <delete file="src/freemarker/core/Token.java" />
        <delete file="src/freemarker/core/TokenMgrError.java" />
        <delete file="/src/freemarker/core/Node.java"/>
    
        <!-- Forces up-to-date check (task.@unless condition is false here): -->
        <antcall target="fetchlibs" />
    </target>

    <target depends="" name="prepare" description="Create the target directories">
        <mkdir dir="${build.dir}"/>
        <mkdir dir="${lib.dir}"/>
    </target>

    <target depends="" name="javadoc" description="Build the JavaDoc documentation" >
        <mkdir dir="${build.javadoc.dir}"/>
        <delete includeEmptyDirs="yes">
            <fileset dir="${build.javadoc.dir}" includes="**/*" />
        </delete>
        <javadoc author="true"
                destdir="${build.javadoc.dir}"
                doctitle="FreeMarker ${version}"
                packagenames="freemarker.debug, freemarker.template.*, freemarker.core.*, freemarker.ext.*, freemarker.cache.*, freemarker.log.*"
                sourcepath="${src.dir}"
                version="true"
                windowtitle="FreeMarker ${version} API"
                classpathref="compile.classpath.javadoc"
                use="${javadoc.use}">
        </javadoc>
    </target>

    <target depends="" name="manual" description="Build the Manual" >
        <taskdef resource="org/freemarker/docgen/antlib.properties"
            uri="http://freemarker.org/docgen"
            classpath="${repositoryRootDir}/docgen/build/lib/docgen.jar"
        />
        <docgen:transform
            srcdir="src/manual" destdir="${build.manual.dir}"
        />
    </target>
    
    <target name="javacc"
        description="Build the JavaCC parser from its grammar file">
        <taskdef name="generate" classname="org.apache.tools.ant.taskdefs.optional.javacc.JavaCC"
            uri="http://javacc.dev.java.net/"
            classpath="lib/javacc.jar"
        />
        
        <javacc:generate
            target="${src.dir}/freemarker/core/FMParser.jj"
            outputdirectory="src/freemarker/core"
            javacchome="lib"
        />
        <replace
            file="src/freemarker/core/FMParser.java"
            token="private final LookaheadSuccess"
            value="private static final LookaheadSuccess"
       />
       <replace
            file="src/freemarker/core/FMParserConstants.java"
            token="public interface FMParserConstants"
            value="interface FMParserConstants"
        />
        <replace
            file="src/freemarker/core/FMParserTokenManager.java"
            token="public class FMParserTokenManager"
            value="class FMParserTokenManager"
        />
        <replace
            file="src/freemarker/core/Token.java"
            token="public class Token"
            value="class Token implements java.io.Serializable"
        />
        <replace
            file="src/freemarker/core/SimpleCharStream.java"
            token="public final class SimpleCharStream"
            value="final class SimpleCharStream"
        />
        <replace
            file="src/freemarker/core/FMParser.java"
            token="enum"
            value="ENUM"
        />
    </target>

    <target name="freecc" depends="init" if="parser.gen"
            description="Build the parser from its grammar file"
    >
           <!--condition property="execution.mode" value="-Xint">
               <and>
                   <os family="windows"/>
                   <equals arg1="${ant.java.version}" arg2="1.5"/>
               </and>
           </condition-->
           <property name="execution.mode" value="-Xmixed"/>
        <java classname="org.visigoths.freecc.Main"
                classpath="lib/freecc.jar:lib/freemarker-bootstrap.jar"
                failonerror="true" fork="true"
        >
            <jvmarg value="${execution.mode}"/>
            <arg value="-OUTPUT_DIRECTORY=src/freemarker/core" />
            <arg value="-JDK_VERSION=1.4" />
            <arg file="src/freemarker/core/FMParser.jj" />
            <assertions><enable/></assertions>
     </java>
   </target>
    
    <target name="compile" depends="init, prepare, javacc"
            description="Compile Java source files">
        <mkdir dir="${build.classes.dir}"/>
        <javac deprecation="off"
                destdir="${build.classes.dir}" debug="on" optimize="off"
                bootclasspath="lib/rt122.jar" source="1.2" target="1.2"
                includeantruntime="false">
            <src path="${src.dir}"/>
            <patternset refid="freemarker.compile"/>
            <classpath refid="compile.classpath"/>
        </javac>
        <rmic base="${build.classes.dir}" classpathref="compile.classpath"
          includes="freemarker/debug/impl/Rmi*Impl.class" verify="yes" stubversion="1.2"/>
        <antcall target="compile-log4j"/>
        <antcall target="compile-logkit"/>
        <antcall target="compile-slf4j"/>
        <antcall target="compile-commons-logging"/>
        <antcall target="compile-jdk14"/>
        <antcall target="compile-jdk15"/>
        <antcall target="compile-jsp1"/>
        <antcall target="compile-jsp2"/>
        <antcall target="compile-jython20"/>
        <antcall target="compile-jython22"/>
        <antcall target="compile-jython25"/>
        <antcall target="compile-dom4j"/>
        <antcall target="compile-jdom"/>
        <antcall target="compile-xalan"/>
        <antcall target="compile-jaxen"/>
        <antcall target="compile-rhino"/>
        <copy toDir="${build.classes.dir}">
          <fileset
            dir="${src.dir}"
            excludes="**/CVS/**,**/*.bak,**/*.java,**/*.jj,**/package.html,freemarker/testcase/**"/>
        </copy>
    </target>

    <target name="compile-log4j" if="log4j.available" depends="init">
        <javac destdir="${build.classes.dir}"
                bootclasspath="lib/rt122.jar" target="1.2" source="1.2"
                deprecation="off" debug="on" optimize="off"
                includeantruntime="false">
            <src path="${src.dir}"/>
            <classpath refid="compile.classpath"/>
            <patternset refid="freemarker.compile.log4j"/>
        </javac>
    </target>

    <target name="compile-logkit" if="logkit.available" depends="init">
        <javac destdir="${build.classes.dir}"
                bootclasspath="lib/rt122.jar" target="1.2" source="1.2"
                deprecation="off" debug="on" optimize="off"
                includeantruntime="false">
            <src path="${src.dir}"/>
            <classpath refid="compile.classpath"/>
            <patternset refid="freemarker.compile.logkit"/>
        </javac>
    </target>

    <target name="compile-slf4j" if="slf4j.available" depends="init">
        <javac destdir="${build.classes.dir}"
                bootclasspath="lib/rt122.jar" target="1.2" source="1.2"
                deprecation="off" debug="on" optimize="off"
                includeantruntime="false">
            <src path="${src.dir}"/>
            <classpath refid="compile.classpath"/>
            <patternset refid="freemarker.compile.slf4j"/>
        </javac>
    </target>

    <target name="compile-commons-logging" if="commons-logging.available" depends="init">
        <javac destdir="${build.classes.dir}"
                bootclasspath="lib/rt122.jar" target="1.2" source="1.2"
                deprecation="off" debug="on" optimize="off"
                includeantruntime="false">
            <src path="${src.dir}"/>
            <classpath refid="compile.classpath"/>
            <patternset refid="freemarker.compile.commons-logging"/>
        </javac>
    </target>

    <target name="compile-jdk14" if="jdk14.available" depends="init">
        <javac destdir="${build.classes.dir}"
                target="1.4" source="1.4"
                deprecation="off" debug="on" optimize="off"
                includeantruntime="false">
            <src path="${src.dir}"/>
            <classpath refid="compile.classpath"/>
            <patternset refid="freemarker.compile.jdk14"/>
        </javac>
    </target>

    <target name="compile-jdk15" if="jdk15.available" depends="init">
        <javac destdir="${build.classes.dir}"
                target="1.5" source="1.5"
                deprecation="off" debug="on" optimize="off"
                includeantruntime="false">
            <src path="${src.dir}"/>
            <classpath refid="compile.classpath"/>
            <patternset refid="freemarker.compile.jdk15"/>
        </javac>
    </target>

    <target name="compile-jython20" if="jython20.available" depends="init">
        <javac destdir="${build.classes.dir}"
                bootclasspath="lib/rt122.jar" target="1.2" source="1.2"
                deprecation="off" debug="on" optimize="off"
                includeantruntime="false">
            <src path="${src.dir}"/>
            <classpath refid="compile.jython20.classpath"/>
            <patternset refid="freemarker.compile.jython20"/>
        </javac>
    </target>

    <target name="compile-jython22" if="jython22.available" depends="init">
        <javac destdir="${build.classes.dir}"
                bootclasspath="lib/rt122.jar" target="1.2" source="1.2"
                deprecation="off" debug="on" optimize="off"
                includeantruntime="false">
            <src path="${src.dir}"/>
            <classpath refid="compile.jython22.classpath"/>
            <patternset refid="freemarker.compile.jython22"/>
        </javac>
    </target>
    
    <target name="compile-jython25" if="jython25.available" depends="init">
        <!-- Needs J2SE 1.5 bootclaspath -->
        <javac destdir="${build.classes.dir}"
                target="1.2" source="1.2"
                deprecation="off" debug="on" optimize="off"
                includeantruntime="false">
            <src path="${src.dir}"/>
            <classpath refid="compile.jython25.classpath"/>
            <patternset refid="freemarker.compile.jython25"/>
        </javac>
    </target>
    
    <target name="compile-jsp1" depends="init">
        <javac destdir="${build.classes.dir}"
                bootclasspath="lib/rt122.jar" target="1.2" source="1.2"
                deprecation="off" debug="on" optimize="off"
                includeantruntime="false">
            <src path="${src.dir}"/>
            <classpath refid="compile.jsp1.classpath"/>
            <patternset refid="freemarker.compile.jsp1"/>
        </javac>
    </target>

    <target name="compile-jsp2" depends="init">
        <javac destdir="${build.classes.dir}"
                bootclasspath="lib/rt122.jar" target="1.2" source="1.2"
                deprecation="off" debug="on" optimize="off"
                includeantruntime="false">
            <src path="${src.dir}"/>
            <classpath refid="compile.jsp2.classpath"/>
            <patternset refid="freemarker.compile.jsp2"/>
        </javac>
    </target>

    <target name="compile-rhino" if="rhino.available" depends="init">
        <javac destdir="${build.classes.dir}"
                bootclasspath="lib/rt122.jar" target="1.2" source="1.2"
                deprecation="off" debug="on" optimize="off"
                includeantruntime="false">
            <src path="${src.dir}"/>
            <classpath refid="compile.classpath"/>
            <patternset refid="freemarker.compile.rhino"/>
        </javac>
    </target>

    <target name="compile-dom4j" if="dom4j.available" depends="init">
        <javac destdir="${build.classes.dir}"
                bootclasspath="lib/rt122.jar" target="1.2" source="1.2"
                deprecation="off" debug="on" optimize="off"
                includeantruntime="false">
            <src path="${src.dir}"/>
            <classpath refid="compile.classpath"/>
            <patternset refid="freemarker.compile.dom4j"/>
        </javac>
    </target>

    <target name="compile-jaxen" if="jaxen.available" depends="init">
        <javac destdir="${build.classes.dir}"
                bootclasspath="lib/rt122.jar" target="1.2" source="1.2"
                deprecation="off" debug="on" optimize="off"
                includeantruntime="false">
            <src path="${src.dir}"/>
            <classpath refid="compile.classpath"/>
            <patternset refid="freemarker.compile.jaxen"/>
        </javac>
    </target>

    <target name="compile-jdom" if="jdom.available" depends="init">
        <javac destdir="${build.classes.dir}"
                bootclasspath="lib/rt122.jar" target="1.2" source="1.2"
                deprecation="off" debug="on" optimize="off"
                includeantruntime="false">
            <src path="${src.dir}"/>
            <classpath refid="compile.classpath"/>
            <patternset refid="freemarker.compile.jdom"/>
        </javac>
    </target>
    
    <target name="compile-xalan" if="xalan.available" depends="init">
        <javac destdir="${build.classes.dir}"
                bootclasspath="lib/rt122.jar" target="1.2" source="1.2"
                deprecation="off" debug="on" optimize="off"
                includeantruntime="false">
            <src path="${src.dir}"/>
            <classpath refid="compile.classpath"/>
            <patternset refid="freemarker.compile.xalan"/>
        </javac>
    </target>

    <target depends="compile" name="jar" description="Create the freemarker.jar">
        <jar basedir="${build.classes.dir}" jarfile="${lib.dir}/freemarker.jar">
            <patternset refid="freemarker.jar"/>
            <metainf dir=".">
                <include name="LICENSE.txt" />
                <include name="NOTICE.txt" />
            </metainf>
            <manifest>
                <attribute name="Main-Class" value="freemarker.core.CommandLine" />
                <attribute name="Extension-name" value="FreeMarker" />
                <attribute name="Specification-Title" value="FreeMarker" />
                <attribute name="Specification-Version" value="${versionForMf}" />
                <attribute name="Specification-Vendor" value="Visigoth Software Society" />
                <attribute name="Implementation-Title" value="VSS Java FreeMarker" />
                <attribute name="Implementation-Version" value="${versionForMf}" />
                <attribute name="Implementation-Vendor" value="Visigoth Software Society" />
            </manifest>
       </jar>
    </target>

    <target depends="compile" name="testcases" description="Build test cases">
        <mkdir dir="${testcase.dir}"/>
        <copy toDir="${testcase.dir}">
            <fileset dir="${build.classes.dir}"/>
        </copy>
        
        <javac deprecation="on" destdir="${testcase.dir}" debug="on" optimize="off" includeantruntime="false">
            <src path="${src.dir}"/>
            <classpath refid="compile.classpath.testcases"/>
            <patternset refid="freemarker.compile.testcases"/>
        </javac>

        <copy todir="${testcase.dir}">
            <fileset dir="${src.dir}">
                <patternset refid="freemarker.testcases"/>
            </fileset>
        </copy>
    </target>

    <target name="test" depends="compile, testcases" description="Run test cases">
        <junit haltonfailure="off" fork="true">
            <classpath>
              <path path="${java.class.path}"/>
              <path refid="compile.classpath"/>
              <pathelement path="${lib.junit}"/>
              <pathelement path="${lib.jdom}"/>
              <pathelement path="${lib.jython25}"/>
              <pathelement path="${build.classes.dir}"/>
              <pathelement path="${testcase.dir}"/>
            </classpath>
            <formatter type="plain"/>
            <formatter type="xml"/>

            <batchtest todir="${testcase.dir}">
              <fileset dir="${testcase.dir}">
                <include name="**/*Test.class" />
                <include name="**/*TestSuite.class" />
                <exclude name="**/PerformanceTest.class" />
              </fileset>
            </batchtest>
        </junit>
    </target>

    <!--
      Reusable task for building example webapps. Invoke with antcall task.
      Params:
      - webapp: The directory of the webapp relative to the example directory
    -->
    <target name="example-general-webapp" depends="init"
            description="Reusable task for building example webapps. For internal usage only.">
        <mkdir dir="${build.examples.dir}/${webapp}"/>
        <copy toDir="${build.examples.dir}/${webapp}">
          <fileset dir="${examples.dir}/${webapp}" excludes="**/CVS/**,**/*.bak"/>
        </copy>
        <javac deprecation="on" destdir="${build.examples.dir}/${webapp}/WEB-INF/classes" includeantruntime="false">
            <src path="${examples.dir}/${webapp}/WEB-INF/classes"/>
            <classpath refid="compile.classpath.examples" />
        </javac>
        <mkdir dir="${build.examples.dir}/${webapp}/WEB-INF/lib"/>
        <copy file="lib/freemarker.jar" toDir="${build.examples.dir}/${webapp}/WEB-INF/lib"/>
    </target>

    <target name="example-webapp1" depends="init" description="Build the example webapps">
        <antcall target="example-general-webapp">
          <param name="webapp" value="webapp1"/>
        </antcall>
    </target>

    <target name="example-webapp2" depends="init" description="Build the example webapps">
        <antcall target="example-general-webapp">
          <param name="webapp" value="webapp2"/>
        </antcall>
    </target>

    <target name="example-jsp-webapp" depends="init" description="Build the JSP example webapp">
        <antcall target="example-general-webapp">
          <param name="webapp" value="jsp-webapp"/>
        </antcall>
    </target>

    <target name="example-struts-webapp" depends="init" description="Build the struts example webapp">
        <antcall target="example-general-webapp">
          <param name="webapp" value="struts-webapp"/>
        </antcall>
    </target>

    <target name="prepare-jython-webapp">
        <property name="twit.jar.loc" location="${build.jython-webapp.dir}/WEB-INF/lib/twit.jar"/>
        <uptodate
            property="jython-webapp.upToDate"
          targetfile="${twit.jar.loc}"
      >
          <srcfiles dir="examples/jython-webapp/WEB-INF" includes="UpperClassTwitOfTheYearServlet.py"/>
          <srcfiles dir="${src.dir}" includes="freemarker/ext/servlet/FreemarkerServlet.java"/>
      </uptodate>

        <mkdir dir="${build.jython-webapp.dir}/WEB-INF/lib"/>
          <copy toDir="${build.jython-webapp.dir}">
          <fileset dir="${examples.dir}/jython-webapp" excludes="**/CVS/**,**/*.bak"/>
        </copy>

        <property name="jythonc" location="${jython25.home}/Tools/jythonc/jythonc.py"/>
        <property name="freemarker.jar.loc" location="lib/freemarker.jar"/>
        <copy file="lib/freemarker.jar" toDir="${build.jython-webapp.dir}/WEB-INF/lib"/>
    </target>

    <target name="example-jython-webapp" depends="init, prepare-jython-webapp" if="jython.available" unless="jython-webapp.upToDate"
            description="Build the Jython Webapp example code">
        <java fork="true" classname="org.python.util.jython" dir="${build.jython-webapp.dir}/WEB-INF">
            <classpath>
              <path  refid="compile.classpath"/>
              <pathelement location="${freemarker.jar.loc}"/>
            </classpath>
            <sysproperty key="python.home" value="${jython25.home}"/>
            <sysproperty key="python.home" value="${jython25.home}"/>
            <arg value="${jythonc}"/>
            <arg value="--core"/>
            <arg value="--bean"/>
            <arg value="${twit.jar.loc}"/>
            <arg value="UpperClassTwitOfTheYearServlet.py"/>
        </java>

        <delete dir="${build.jython-webapp.dir}/WEB-INF/jpywork"/>
        
    </target>

    <target name="examples"
        depends="example-webapp1, example-webapp2, example-struts-webapp, example-jsp-webapp, example-jython-webapp"/>
    
    <target name="fail.logkit" unless="logkit.available" depends="init">
      <fail message="Can't build dist because LogKit classes are not available."/>
    </target>

    <target name="fail.log4j" unless="log4j.available" depends="init">
      <fail message="Can't build dist because Log4J classes are not available."/>
    </target>

    <target name="fail.slf4j" unless="slf4j.available" depends="init">
      <fail message="Can't build dist because SLF4J classes are not available."/>
    </target>

    <target name="fail.commons-logging" unless="commons-logging.available" depends="init">
      <fail message="Can't build dist because Apache commons-logging classes are not available."/>
    </target>

    <target name="fail.jdk14" unless="jdk14.available" depends="init">
      <fail message="Can't build dist because JDK 1.4 classes are not available."/>
    </target>

    <target name="fail.jdk15" unless="jdk15.available" depends="init">
      <fail message="Can't build dist because JDK 1.5 classes are not available."/>
    </target>

    <target name="fail.jython20" unless="jython20.available" depends="init">
      <fail message="Can't build dist because Jython 2.0 classes are not available."/>
    </target>

    <target name="fail.jython22" unless="jython22.available" depends="init">
      <fail message="Can't build dist because Jython 2.2 classes are not available."/>
    </target>

    <target name="fail.jython25" unless="jython25.available" depends="init">
      <fail message="Can't build dist because Jython 2.5 classes are not available."/>
    </target>

    <target name="fail.jsp21" unless="jsp21.available" depends="init">
      <fail message="Can't build dist because JSP 2.1 classes are not available."/>
    </target>

    <target name="fail.rhino" unless="rhino.available" depends="init">
      <fail message="Can't build dist because Rhino classes are not available."/>
    </target>

    <target name="fail.jaxen" unless="jaxen.available" depends="init">
      <fail message="Can't build dist because Jaxen classes are not available."/>
    </target>

    <target name="fail.xalan" unless="xalan.available" depends="init">
      <fail message="Can't build dist because Xalan classes are not available."/>
    </target>

    <target
            name="dist"
            depends="init, fail.logkit, fail.log4j, fail.slf4j, fail.commons-logging, fail.jdk14, fail.jdk15,
                    fail.jython20, fail.jython22, fail.jython25,
                    fail.jsp21, fail.rhino, fail.jaxen, fail.xalan,
                    jar, javadoc, manual"
            description="Build the FreeMarker distribution files">
        <delete dir="${dist.dir}" />
        <mkdir dir="${dist.dir}" />
        <mkdir dir="${dist.dir.versioned}" />
        <copy todir="${dist.dir.versioned}" includeEmptyDirs="no">
            <fileset dir=".">
                <patternset refid="freemarker.distribution.src"/>
            </fileset>
        </copy>
        <replace
            file="${dist.dir.versioned}/README.txt"
            token="{version}"
            value="${version}"
        />

        <copy todir="${dist.dir.versioned}/lib"  includeEmptyDirs="no">
          <fileset file="lib/freemarker.jar" />
        </copy>

        <!-- Generate website pages and copy them to distro -->
        <ant dir="${repositoryRootDir}site" target="all">
          <property name="site.offline" value="yes"/>
        </ant>
        <copy todir="${dist.dir.versioned}/docs">
          <fileset dir="${repositoryRootDir}site/build/site"/>
        </copy>
        
        <!-- Copy Manual -->
        <copy todir="${dist.dir.versioned}/docs/docs" includeEmptyDirs="no">
            <fileset dir="${build.manual.dir}" />
        </copy>
        
        <!-- Copy javadocs -->
        <copy todir="${dist.dir.versioned}/docs/docs/api" includeEmptyDirs="no">
            <fileset dir="${build.javadoc.dir}" />
        </copy>
        
        <antcall target="packdist"/>
    </target>
    
    <target name="packdist">
        <delete file="${freemarker.tar}" />
        <tar tarfile="${freemarker.tar}" basedir="${dist.dir}" />
        <delete file="${freemarker.gzip}" />
        <gzip zipfile="${freemarker.gzip}" src="${freemarker.tar}" />
        <delete file="${freemarker.tar}" />
    </target>
    
    <target name="packdocs">
        <delete file="build/docs.tar" />
        <tar tarfile="build/docs.tar" basedir="${dist.dir.versioned}/docs" />
        <delete file="build/docs.tar.gz" />
        <gzip zipfile="build/docs.tar.gz" src="build/docs.tar" />
        <delete file="build/docs.tar" />
    </target>

    <target name="packapidocs">
        <delete file="build/apidocs.tar" />
        <tar tarfile="build/apidocs.tar" basedir="build/api" />
        <delete file="build/apidocs.tar.gz" />
        <gzip zipfile="build/apidocs.tar.gz" src="build/apidocs.tar" />
        <delete file="build/apidocs.tar" />
    </target>

<!-- The following ant target builds a war file for the HelloServlet
and guestbook examples. Once you build the .war file and drop it in
the appropriate directory, you should be able to see the following
URL's: http://localhost:8080/fmexamples/servlet/hello
and: http://localhost:8080/fmexamples/servlet/guestbook -->

    <target name="war-jython-webapp"
             depends="example-jython-webapp" if="jython.available">
        <jar jarfile="fm-jython-example.war" basedir="${build.jython-webapp.dir}" />
    </target>

    <target depends="clean,
                    prepare,
                    javadoc,
                    jar,
                    example-webapp1, example-webapp2,
                    testcases"

            name="all"
            description="Build everything" />

  <!--
    Uploads the freemarker.jar that is in the current DISTRIBUTION DIRECTORY
    into the place that the central Maven2 repository syncs itself with
    periodically. Of course it also uploads the Maven-specific metadata files.

    Use this after "dist" (without interleaving "clean").

    Note: maven-ant-tasks-x.x.x.jar must be added to ${ANT_HOME}/lib for
          this to work. Get it here: http://maven.apache.org/download.html
  -->
  <target name="maven-upload" xmlns:artifact="antlib:org.apache.maven.artifact.ant">
     <echo file="build/pom.xml"><![CDATA[<?xml version="1.0" encoding="utf-8"?>
        <project xmlns="http://maven.apache.org/POM/4.0.0"
          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
          xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
          <modelVersion>4.0.0</modelVersion>
          <groupId>org.freemarker</groupId>
          <artifactId>freemarker</artifactId>
          <version>${version}</version>
          <packaging>jar</packaging>
          <name>FreeMarker</name>
          <description>
            FreeMarker is a "template engine"; a generic tool to generate text output based on templates.
          </description>
          <url>http://freemarker.org</url>
          <licenses>
            <license>
              <name>BSD-style license</name>
              <url>http://freemarker.org/LICENSE.txt</url>
            </license>
          </licenses>
          <scm>
            <url>http://freemarker.svn.sourceforge.net/viewvc/freemarker/</url>
            <connection>scm:svn:https://freemarker.svn.sourceforge.net/svnroot/freemarker</connection>
          </scm>
          <dependencies>
            <!-- no required dependencies -->
          </dependencies>
        </project>
     ]]></echo>
     
     <jar destfile="build/maven-source-attachment.jar"
            basedir="src" excludes="freemarker/testcase/**, manual/**"
     />

     <artifact:install-provider artifactId="wagon-ssh" version="1.0-beta-2"/>

     <input
          validargs="y,n"
          addproperty="mavenUpload.answer"
     >
You are about uploading
${dist.dir.versioned}/lib/freemarker.jar
into the Maven central repostiry sync. directory.
Be sure that's the final (released) variation there,
and that the version number is correct.
Proceed? </input>
     <condition property="mavenUpload.yes">
        <equals arg1="y" arg2="${mavenUpload.answer}"/>
     </condition>
     <fail unless="mavenUpload.yes" message="Task aborted by user." />

     <input
          message="Enter your SourceForge.net user name: "
          addproperty="mavenUpload.user"
    />
     <input
          message="Enter your SourceForge.net password (WILL BE DISPLAYED AS YOU TYPE IT!): "
          addproperty="mavenUpload.password"
    />

     <artifact:deploy file="${dist.dir.versioned}/lib/freemarker.jar">
        <!-- For testing use something like url="file:///my-test-dir". -->
        <remoteRepository url="sftp://web.sourceforge.net/home/groups/f/fr/freemarker/htdocs/maven2">
           <authentication
             username="${mavenUpload.user},freemarker"
             password="${mavenUpload.password}"
          />
        </remoteRepository>
        <pom file="build/pom.xml" />
        <attach file="build/maven-source-attachment.jar" classifier="sources" />
     </artifact:deploy>
     
     <echo>**********************************************</echo>
     <echo>CLEAR THE SCREEN, NOW! Your password is on it!</echo>
     <echo>**********************************************</echo>
  </target>

</project>
