<?xml version="1.0"?>
  <!DOCTYPE project [
    <!ENTITY check-targets SYSTEM "./check-targets.ent">
  ]>

<!-- James build file -->
<!--
  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 default="main" basedir=".">
    <!--
    Give user a chance to override without editing this file
    (and without typing -D each time he compiles it)
    -->
    <property file=".ant.properties"/>
    <property file="${user.home}/.ant.properties"/>
    <property file="check-targets.properties"/>
    <property file="include.properties"/>
    <property file="default.properties"/>

    <!--
    ===================================================================
    Set the properties for proposal directories
    ===================================================================
    -->

    <property name="proposal.base" value="proposals"/>
    <property name="proposal.dir" value="${proposal.base}/${proposal.name}"/>
    <property name="java.proposal.dir" value="${proposal.dir}/java"/>
    <property name="conf.proposal.dir" value="${proposal.dir}/conf"/>

    <!--
    ===================================================================
    Set the properties for build tools directory
    ===================================================================
     -->

    <property name="tools.dir" value="tools"/>
    <property name="tools.lib.dir" value="${tools.dir}/lib"/>

    <!--
    ===================================================================
    Set the classpath
    ===================================================================
    -->

    <path id="project.class.path">
        <fileset dir="${lib.dir}">
            <include name="${avalon-framework.jar}"/>
            <include name="${avalon-framework-impl.jar}"/>
            <include name="${dns.jar}"/>
            <include name="${commons-collections.jar}"/>
            <include name="${commons-dbcp.jar}"/>
            <include name="${commons-pool.jar}"/>
            <include name="${jakarta-oro.jar}"/>
            <include name="${excalibur-pool-api.jar}"/>
            <include name="${excalibur-pool-impl.jar}"/>
            <include name="${excalibur-thread-api.jar}"/>
            <include name="${excalibur-datasource.jar}"/>
            <include name="${cornerstone-threads-api.jar}"/>
            <include name="${cornerstone-connection-api.jar}"/>
            <include name="${cornerstone-connection-impl.jar}"/>
            <include name="${cornerstone-store-api.jar}"/>
            <include name="${cornerstone-scheduler-api.jar}"/>
            <include name="${cornerstone-sockets-api.jar}"/>
            <include name="${cornerstone-datasources-api.jar}"/>
            <include name="${javax-mail.jar}"/>
            <include name="${javax-activation.jar}"/>
            <include name="${bcmail.jar}"/>
            <include name="${bcmail-workaround.jar}"/>
            <include name="${javax.management}"/>
            <include name="${jspf.jar}"/>
            <include name="${mstor.jar}"/>
            <include name="${commons-logging.jar}"/>
            <include name="${jdom.jar}"/>
            <include name="${xstream.jar}"/>
        	
            <include name="${torque.jar}"/>
            <include name="${village.jar}"/>
            <include name="${commons-lang.jar}"/>
            <include name="${commons-configuration.jar}"/>
        </fileset>
        <pathelement path="${java.class.path}" />
        <pathelement path="${build.classes}" />
    </path>

    <path id="tools.class.path">
        <fileset dir="${tools.lib.dir}">
            <include name="*.jar"/>
        </fileset>
    </path>

    <taskdef name="sar" classname="org.apache.avalon.phoenix.tools.tasks.Sar">
        <classpath refid="tools.class.path"/>
    </taskdef>

    <!--
    ===================================================================
                                Dependency Check
    ===================================================================
    -->

    &check-targets;
    <target name="check-dependencies" depends="javamail-check,activation-check"/>

    <!--
    ===================================================================
                                  Main target
    ===================================================================
    -->
    <target name="main" depends="dist-lite"/>

    <!--
    ===================================================================
    Prepare-common target - common tasks executed in preparation for
    all targets
    ===================================================================
    -->
    <target name="prepare-common" depends="check-dependencies">

        <echo message="Preparing code"/>
  
        <tstamp/>
        <available file="${james.dir}/${phoenix.dir}/bin" type="dir" property="phoenix.bin.present"/>
        <mkdir dir="${dist.dir}"/>
        <copy todir="${dist.dir}">
            <fileset dir=".">
                <include name="LICENSE.txt"/>
                <include name="README.txt"/>
                <include name="NOTICE.txt"/>
                <include name="UPGRADE.txt"/>
            </fileset>
        </copy>
        <fixcrlf srcdir="${java.dir}" includes="**/*.java" eol="lf" tab="remove" tablength="4" />
        <fixcrlf srcdir="${java.dir}" includes="**/*.minfo" eol="lf" tab="remove" tablength="4" />
        <fixcrlf srcdir="${java.dir}" includes="**/*.xinfo" eol="lf" tab="remove" tablength="4" />
        <fixcrlf srcdir="${java.dir}" includes="**/*.html" eol="lf" tab="remove" tablength="4" />
        <fixcrlf srcdir="${junitjava.dir}" includes="**/*.java" eol="lf" tab="remove" tablength="4" />
        <fixcrlf srcdir="${xdocs.dir}" includes="**/*.xml" eol="lf" tab="remove" tablength="4" />
        <fixcrlf srcdir="${conf.dir}" includes="**/*.xml" eol="lf" tab="remove" tablength="4" />
        <fixcrlf srcdir="${metainf.dir}" includes="**/*" eol="lf" tab="remove" tablength="4" />      
        <fixcrlf srcdir="." includes="build.xml" eol="lf"/>
        <mkdir dir="${build.src}"/>
        <copy todir="${build.src}">
            <fileset dir="${java.dir}">
                <include name="${constants.file}"/>
            </fileset>
        </copy>
        <replace file="${build.src}/${constants.file}" token="@@VERSION@@" value="${version}"/>
        <replace file="${build.src}/${constants.file}" token="@@NAME@@" value="${Name}"/>
        <replace file="${build.src}/${constants.file}" token="@@DATE@@" value="${TODAY}"/>

    </target>

    <!--
    ===================================================================
    Copy files, set permissions and line feeds for the packaged Phoenix distribution
    ===================================================================
    -->
    <target name="prepare-phoenix" depends="prepare-common" if="phoenix.bin.present">
        <echo message="Phoenix distribution present - adjusting linefeeds and permissions, copying files"/>
        <property name="dist.bin" value="${dist.dir}/bin"/>
        <fixcrlf srcdir="${james.dir}/${phoenix.dir}/bin" includes="phoenix.sh" eol="lf"/>
        
        <copy todir="${dist.dir}">
            <fileset dir="${phoenix.dir}">
            </fileset>
        </copy>
       
        <copy todir="${dist.dir}/lib" flatten="true">
            <fileset dir="${lib.dir}">
                <include name="${excalibur-thread-api.jar}"/>
                <include name="${excalibur-thread-impl.jar}"/>
                <include name="${excalibur-pool-impl.jar}"/>
                <include name="${excalibur-pool-api.jar}"/>
                <include name="${commons-collections.jar}"/>
                <!-- needed by excalibur-pool-impl-2.1.jar -->
                <include name="${concurrent.jar}"/>
            </fileset>
        </copy>
       
        <fixcrlf srcdir="${james.dir}/${phoenix.dir}/bin" includes="james-server.sh" eol="lf"/>
        <fixcrlf srcdir="${dist.bin}" includes="run.sh" eol="lf"/>
        <fixcrlf srcdir="${dist.bin}" includes="run.bat" eol="crlf"/>
        <chmod perm="+x">
            <fileset dir="${dist.bin}">
                <include name="run.sh"/>
                <include name="phoenix.sh"/>
                <include name="james-server.sh"/>
            </fileset>
        </chmod>
          
        <!--
        ===================================================================
        Copy files, set permissions and line feeds for sendmail wrapper
        ===================================================================
        -->
          
        <copy todir="${dist.bin}">
          <fileset dir="./src/python/">
            <include name="sendmail.py"/>
          </fileset>
        </copy>
        
        <fixcrlf srcdir="${dist.bin}" includes="sendmail.py" eol="lf"/>
        <chmod perm="+x">
          <fileset dir="${dist.bin}">
              <include name="sendmail.py"/>
          </fileset>
        </chmod>

    </target>

    <!--
    ===================================================================
                                   jmx
    ===================================================================
    -->

    <!-- Make .xinfo, .mxinfo and manifest automatically for blocks -->
    <target name="prepare-mxinfo">
        <taskdef name="generatemeta" classname="org.apache.avalon.phoenix.tools.metagenerate.MetaGenerateTask">
            <classpath refid="tools.class.path"/>
        </taskdef>

        <mkdir dir="${build.classes}" />

        <generatemeta dest="${build.classes}">
            <fileset dir="${java.dir}">
                <include name="**/*.java"/>
            </fileset>
        </generatemeta>

    </target>
    
    <!--
       ===================================================================
                                   meta-inf

           Currently a straight copy from source to build.
           Add augmentions as required.
       ===================================================================
    -->
    <target name="prepare-metainf">
        <copy todir="${build.metainf}">
            <fileset dir="${metainf.dir}"/>
        </copy>
    </target>    

    <!--
    ===================================================================
                                  Prepare target
    ===================================================================
    -->
    <target name="prepare" depends="prepare-common,prepare-phoenix,prepare-mxinfo,prepare-metainf"/>

    <!--
    ===================================================================
                                  compile
    ===================================================================
    -->
    <target name="compile" depends="compile-main, compile-proposal"/>

    <target name="compile-main" depends="prepare">
        <echo message="Compiling James Java sources"/>
        <mkdir dir="${build.classes}"/>
        <javac destdir="${build.classes}" debug="${debug}" optimize="${optimize}" deprecation="${deprecation}" target="${jdk.target}" source="${jdk.source}">
            <classpath refid="project.class.path"/>
            <src path="${build.src}"/>
            <src path="${java.dir}"/>
            <exclude name="${constants.file}"/>
        </javac>
        <copy todir="${build.classes}">
            <fileset dir="${java.dir}">
                <include name="**/*.properties"/>
                <include name="**/*.xinfo"/>
                <include name="**/*.xml"/>
                <include name="**/*.mxinfo"/>
            </fileset>
        </copy>
    </target>

    <!-- Compiles the proposal source, only if proposal.name is specified. -->
    <target name="compile-proposal" depends="prepare" if="proposal.name">
        <echo message="Compiling the ${proposal.name} proposal."/>
        <!-- Now build the proposal source over those classes -->
        <javac destdir="${build.classes}"
               debug="${debug}"
               optimize="${optimize}"
               deprecation="${deprecation}" target="${jdk.target}" source="${jdk.source}">
            <classpath refid="project.class.path" />
            <src path="${java.proposal.dir}"/>
        </javac>

        <!-- Copy .xinfo and .properties files from the proposal source -->
        <copy todir="${build.classes}" overwrite="on">
             <fileset dir="${java.proposal.dir}">
                 <include name="**/*.properties"/>
                 <include name="**/*.xinfo"/>
             </fileset>
        </copy>
    </target>


    <!--
    ===================================================================
                                  Javadocs, and mailet javadocs
    ===================================================================
    -->
    <target name="javadocs">
      
        <echo message="Making James Javadocs"/>
      
        <delete dir="${build.javadocs}"/>
        <mkdir dir="${build.javadocs}"/>
        <javadoc packagenames="org.apache.*" sourcepath="${java.dir}" destdir="${build.javadocs}">
            <classpath refid="project.class.path"/>
            <doclet name="com.sun.tools.doclets.standard.Standard">
                <param name="-author"/>
                <param name="-version"/>
                <param name="-use"/>
                <param name="-breakiterator"/>
                <param name="-link" value="http://java.sun.com/j2se/1.4/docs/api"/>
                <param name="-link" value="http://java.sun.com/j2ee/sdk_1.3/techdocs/api"/>
                <param name="-link" value="http://avalon.apache.org/api"/>
                <param name="-link" value="http://avalon.apache.org/phoenix/api"/>
                <param name="-link" value="http://avalon.apache.org/cornerstone/api"/>
                <param name="-link" value="http://avalon.apache.org/logkit/api"/>
                <param name="-doctitle" value="${Name} ${version}"/>
                <param name="-windowtitle" value="${Name} API"/>
                <param name="-bottom" value="&quot;Copyright &#169; ${year} Apache James Project. All Rights Reserved.&quot;"/>
                <param name="-tag" value="phoenix\:mx\-topic:X"/>
                <param name="-tag" value="phoenix\:mx\-operation:X"/>
                <param name="-tag" value="phoenix\:mx\-description:X"/>
                <param name="-tag" value="phoenix\:mx\-attribute:X"/>
                <param name="-tag" value="phoenix\:mx\-isWriteable:X"/>
            </doclet>
        </javadoc>
        <echo message="Making Mailet Javadocs"/>
        <javadoc packagenames="org.apache.mailet.*" sourcepath="${java.dir}" destdir="${build.dir}/mailet">
            <classpath refid="project.class.path"/>
            <doclet name="com.sun.tools.doclets.standard.Standard">
                <param name="-author"/>
                <param name="-version"/>
                <param name="-breakiterator"/>
                <param name="-use"/>
                <param name="-link" value="http://java.sun.com/j2se/1.4/docs/api"/>
                <param name="-link" value="http://java.sun.com/j2ee/sdk_1.3/techdocs/api"/>
                <param name="-link" value="http://avalon.apache.org/api"/>
                <param name="-link" value="http://avalon.apache.org/phoenix/api"/>
                <param name="-link" value="http://avalon.apache.org/cornerstone/api"/>
                <param name="-link" value="http://avalon.apache.org/logkit/api"/>
                <param name="-doctitle" value="Apache Jakarta Mailet API"/>
                <param name="-windowtitle" value="Apache Jakarta Mailet API"/>
                <param name="-bottom" value="&quot;Copyright &#169; ${year} Apache James Project. All Rights Reserved.&quot;"/>
            </doclet>
        </javadoc>
    </target>

    <!--
    ===================================================================
                                  build xdocs
    ===================================================================
    -->
    <target name="xdocs" depends="prepare">
        <mkdir dir="${build.docs}" />
        <style style="${docs.src}/stylesheets/site.xsl"
                  basedir="${docs.src}/"
                  destdir="${build.docs}/"
                  includes="**/*.xml" >
        </style>
        <copy todir="${build.docs}" filtering="no">
            <fileset dir="${docs.src}">
                <include name="**/*.css"/>
            </fileset>
        </copy>
        <copy todir="${build.docs}/images" filtering="no">
            <fileset dir="${docs.src}/images">
                <include name="**/*.gif"/>
                <include name="**/*.jpeg"/>
                <include name="**/*.jpg"/>
                <include name="**/*.png"/>
            </fileset>
        </copy>
        <mkdir dir="${dist.dir}/docs"/>
        <copy todir="${dist.dir}/docs" filtering="no">
            <fileset dir="${build.docs}"/>
        </copy>
    </target>

    <!--
    ===================================================================
                                build   website
    ===================================================================
    -->
    <target name="website" depends="xdocs,javadocs">

        <echo message="preparing website in ${www.dir}"/>
    	<mkdir dir='${www.dir}'/>
        <delete>
            <fileset dir="${www.dir}">
                <exclude name="rfclist/**"/>
                <exclude name="javadocs/**"/>
                <exclude name="mailet/**"/>
            </fileset>
        </delete>

        <copy todir="${www.dir}" filtering="no">
            <fileset dir="${build.docs}"/>
        </copy>
        <copy todir="${www.dir}" filtering="no">
            <fileset dir="${build.dir}">
                <include name="javadocs/**"/>
                <include name="mailet/**"/>
            </fileset>
        </copy>
        <fixcrlf srcdir="${www.dir}" includes="**/*.html" eol="lf" tab="remove" tablength="4" />
        <fixcrlf srcdir="${www.dir}" includes="**/*.css" eol="lf" tab="remove" tablength="4" />
    </target>

    <!--
    ===================================================================
                Build everything
    ===================================================================
    -->
    <target name="everything" depends="clean,website,dist-bin,dist-src,dist-mailet-SDK"/>

    <!--
    ===================================================================
                                  Build all distributions
    ===================================================================
    -->
    <target name="dist" depends="clean,run-unit-tests,dist-bin,dist-src,dist-mailet-SDK"/>

    <!--
    ===================================================================
                                  Make james and mailet jars
    ===================================================================
    -->

    <target name="jar" depends="compile">

        <mkdir dir="${build.lib}"/>
       
        <!-- Make mailet api jar-->
        <echo message="Making Mailet API Jar (mailet-api-${mailet-api-version}.jar)"/>
        <jar jarfile="${build.lib}/mailet-api-${mailet-api-version}.jar"
                 basedir="${build.classes}"
                 includes="org/apache/mailet/Mailet.class,org/apache/mailet/MailetConfig.class,org/apache/mailet/Mail.class,org/apache/mailet/MailetContext.class,org/apache/mailet/MailAddress.class,org/apache/mailet/MailRepository,org/apache/mailet/SpoolRepository,org/apache/mailet/UserRepository,org/apache/mailet/Datasource,org/apache/mailet/User,org/apache/mailet/MailetException"/>
       
        <!-- Make mailet implementation jar-->
        <echo message="Making Mailet Jar (mailet-${mailet-version}.jar)"/>
        <jar jarfile="${build.lib}/mailet-${mailet-version}.jar"
                 basedir="${build.classes}"
                 includes="org/apache/mailet/**"
                 excludes="org/apache/mailet/Mailet.class,org/apache/mailet/MailetConfig.class,org/apache/mailet/Mail.class,org/apache/mailet/MailetContext.class,org/apache/mailet/MailAddress.class,org/apache/mailet/MailRepository,org/apache/mailet/SpoolRepository,org/apache/mailet/UserRepository,org/apache/mailet/Datasource,org/apache/mailet/User,org/apache/mailet/MailetException"/>
       
        <!-- Make james jar-->
        <echo message="Making James Jar (${name}-${version}.jar)"/>
        <jar jarfile="${build.lib}/${name}-${version}.jar" basedir="${build.classes}" manifest="${src.dir}/Manifest.mf">
            <include name="org/apache/james/**"/>
            <include name="*.xml"/>
            <metainf dir="${build.metainf}"/>        
        </jar>

    </target>

    <!--
    ===================================================================
                                  Make james.sar
    ===================================================================
    -->

    <target name="sar" depends="jar">

        <echo message="Making James Sarfile (james.sar)"/>
      
        <!-- Make sar file-->
        <sar sarfile="${build.lib}/${sar-name}.sar" config="${conf.dir}/james-config.xml"
               environment="${conf.dir}/james-server.xml" assembly="${conf.dir}/james-assembly.xml">
            <lib dir="${build.lib}/">
                <include name="mailet-api-${mailet-api-version}.jar"/>
                <include name="mailet-${mailet-version}.jar"/>
                <include name="${name}-${version}.jar"/>         
            </lib>
            <lib dir="${lib.dir}">
                <include name="${dns.jar}"/>
                <include name="${jakarta-oro.jar}"/>
                <include name="${derby.jar}"/>
                <include name="${excalibur-datasource.jar}"/>
                <include name="${javax-activation.jar}"/>
                <include name="${javax-mail.jar}"/>
                <include name="${commons-dbcp.jar}"/>
                <include name="${commons-pool.jar}"/>
                <include name="${bcmail.jar}"/>
                <include name="${bcmail-workaround.jar}"/>
                <include name="${excalibur-thread-api.jar}"/>
                <include name="${excalibur-thread-impl.jar}"/>
                <include name="${excalibur-pool-api.jar}"/>
                <include name="${excalibur-pool-impl.jar}"/>
                <include name="${commons-collections.jar}"/>
                <include name="${cornerstone-threads-api.jar}"/>
                <include name="${cornerstone-threads-impl.jar}"/>
                <include name="${cornerstone-connection-api.jar}"/>
                <include name="${cornerstone-connection-impl.jar}"/>
                <include name="${cornerstone-store-api.jar}"/>
                <include name="${cornerstone-scheduler-api.jar}"/>
                <include name="${cornerstone-scheduler-impl.jar}"/>
                <include name="${cornerstone-sockets-api.jar}"/>
                <include name="${cornerstone-sockets-impl.jar}"/>
                <include name="${cornerstone-datasources-api.jar}"/>
                <include name="${cornerstone-datasources-impl.jar}"/>
                <include name="${concurrent.jar}"/>
                <include name="${jspf.jar}"/>
                <include name="${mstor.jar}"/>
                <include name="${commons-logging.jar}"/>
                <include name="${jdom.jar}"/>
                <include name="${xstream.jar}"/>
            	
                <include name="${torque.jar}"/>
                <include name="${village.jar}"/>
                <include name="${commons-lang.jar}"/>
                <include name="${commons-configuration.jar}"/>
                <include name="${commons-beanutils.jar}"/>            	
            </lib>
            <zipfileset dir="${conf.dir}" fullpath="conf/sqlResources.xml">
                <include name="sqlResources.xml"/>
            </zipfileset>
            <zipfileset dir="${conf.dir}" fullpath="conf/mailboxManagerSqlResources.xml">
                <include name="mailboxManagerSqlResources.xml"/>
            </zipfileset>
            <zipfileset dir="${conf.dir}" fullpath="conf/james-fetchmail.xml">
                <include name="james-fetchmail.xml"/>
            </zipfileset>
            <zipfileset dir="${conf.dir}" fullpath="conf/james-smtphandlerchain.xml">
                <include name="james-smtphandlerchain.xml"/>
            </zipfileset>
            <zipfileset dir="${conf.dir}" fullpath="conf/miResources.xml">
                <include name="miResources.xml"/>
            </zipfileset>
            <zipfileset dir="${conf.dir}" fullpath="conf/james-listmanager.xml">
                <include name="james-listmanager.xml"/>
            </zipfileset>
            <zipfileset dir="${conf.dir}" fullpath="conf/james-liststores.xml">
                <include name="james-liststores.xml"/>
            </zipfileset>
            <zipfileset dir="${conf.dir}/samples/fetchmail" prefix="conf/samples/fetchmail">
                <include name="*.xml"/>
            </zipfileset>
        </sar>
    </target>

    <!--
    ===================================================================
                                  Make dist directory with unpacked dist ready to run
    ===================================================================
    -->
    <target name="dist-lite" depends="sar">

        <echo message="Installing James to ${dist.dir}"/>
      
        <!--installs sar into ./dist/ ready to test-->
        <copy file="${build.lib}/${sar-name}.sar" todir="${dist.dir}/apps"/>
      
        <!-- Make mailet.jar-->
        <!-- jar jarfile="${build.lib}/mailet.jar"
                 basedir="${build.classes}"
                 manifest="${src.dir}/Manifest.mf"
                 includes="org/apache/mailet/**"/ -->
            <!-- copy file="${build.lib}/mailet.jar" todir="${dist.dir}/lib"/ -->
    </target>

    <!--
    ===================================================================
                                  binary distributions
    ===================================================================
    -->

    <target name="dist-bin-phoenix-warn" depends="dist-bin-common" unless="phoenix.bin.present">
        <echo message ="The Phoenix distribution is not present - the James w/Phoenix binary distribution will not be built."/>
    </target>

    <target name="dist-bin-phoenix" depends="dist-bin-common" if="phoenix.bin.present">
        <echo message ="Building binary w/Phoenix distributions"/>
        <zip zipfile="${dist.binary.dir}/${name}-binary-${version}.zip">
            <fileset dir="dist">
                <include name="${name}-${version}/**"/>
                <exclude name="${name}-${version}/downloads/**"/>
                <include name="LICENSE.txt"/>
                <include name="README.txt"/>
                <include name="NOTICE.txt"/>
                <include name="UPGRADE.txt"/>
            </fileset>
        </zip>
        <tar longfile="gnu" tarfile="${dist.binary.dir}/${name}-binary-${version}.tar">
            <tarfileset dir="dist" username="${name}" group="${name}">
                <include name="${name}-${version}/**"/>
                <exclude name="${name}-${version}/downloads/**"/>
                <include name="LICENSE.txt"/>
                <include name="README.txt"/>
                <include name="NOTICE.txt"/>
                <include name="UPGRADE.txt"/>
            </tarfileset>
        </tar>
        <gzip zipfile="${dist.binary.dir}/${name}-binary-${version}.tar.gz" src="${dist.binary.dir}/${name}-binary-${version}.tar"/>
        <delete file="${dist.binary.dir}/${name}-binary-${version}.tar"/>
    </target>

    <!-- target name="dist-bin-common" depends="dist-lite,xdocs,javadocs" -->
    <target name="dist-bin-common" depends="dist-lite">
        <echo message ="Building binary distributions"/>
        <property name="dist.binary.dir" value="${dist.dir}/downloads/bin"/>
        <mkdir dir="${dist.binary.dir}"/>
        <!-- Sar only-->
        <copy file="${dist.dir}/apps/${sar-name}.sar" todir="${dist.binary.dir}"/>
    </target>

    <target name="dist-bin" depends="dist-bin-common,dist-bin-phoenix-warn,dist-bin-phoenix"/>

    <!--
    ===================================================================
                                  source distributions
    ===================================================================
    -->
    <target name="dist-src-phoenix-warn" depends="dist-src-common" unless="phoenix.bin.present">
        <echo message ="The Phoenix distribution is not present - the James source distribution with Phoenix binaries will not be built."/>
    </target>

    <target name="dist-src-phoenix" depends="dist-src-common" if="phoenix.bin.present">
        <!--Source With Phoenix -->
        <echo message ="Building source distributions with Phoenix binaries"/>
        <zip zipfile="${dist.source.dir}/${name}-with-phoenix-${version}-src.zip">
            <fileset dir=".">
                <include name="*.txt"/>
                <include name="build.*"/>
                <include name="lib/**"/>
                <include name="${phoenix.dir}/**"/>
                <include name="src/**"/>
                <include name="tools/**"/>
                <include name="*.properties" />
                <include name="*.ent" />
            </fileset>
        </zip>
        <tar longfile="gnu" tarfile="${dist.source.dir}/${name}-with-phoenix-${version}-src.tar">
            <tarfileset dir="." username="${name}" group="${name}">
                <include name="*.txt"/>
                <include name="build.*"/>
                <include name="lib/**"/>
                <include name="${phoenix.dir}/**"/>
                <include name="src/**"/>
                <include name="tools/**"/>
                <include name="*.properties" />
                <include name="*.ent" />
            </tarfileset>
        </tar>
        <gzip zipfile="${dist.source.dir}/${name}-with-phoenix-${version}-src.tar.gz"
             src="${dist.source.dir}/${name}-with-phoenix-${version}-src.tar"/>
        <delete file="${dist.source.dir}/${name}-with-phoenix-${version}-src.tar"/>
    </target>

    <target name="dist-src-common" depends="dist-lite,xdocs,javadocs">
        <echo message ="Building source distributions"/>

        <property name="dist.source.dir" value="${dist.dir}/downloads/src"/>
        <mkdir dir="${dist.source.dir}"/>
        <zip zipfile="${dist.source.dir}/${dist.name}-src.zip">
            <fileset dir=".">
                <include name="src/**"/>
                <include name="lib/**"/>
                <include name="tools/**"/>
                <include name="*.txt"/>
                <include name="build.*"/>
                <include name="*.properties" />
                <include name="*.ent" />
            </fileset>
        </zip>
        <tar longfile="gnu" tarfile="${dist.source.dir}/${dist.name}-src.tar">
            <tarfileset dir="." username="${name}" group="${name}">
                <include name="src/**"/>
                <include name="lib/**"/>
                <include name="tools/**"/>
                <include name="*.txt"/>
                <include name="build.*"/>
                <include name="*.properties" />
                <include name="*.ent" />
            </tarfileset>
        </tar>
        <gzip zipfile="${dist.source.dir}/${dist.name}-src.tar.gz" src="${dist.source.dir}/${dist.name}-src.tar"/>
        <delete file="${dist.source.dir}/${dist.name}-src.tar"/>
    </target>

    <target name="dist-src" depends="dist-src-common,dist-src-phoenix-warn,dist-src-phoenix"/>

    <!--
    ===================================================================
                                  Mailet SDK distribution
    ===================================================================
    -->
    <target name="dist-mailet-SDK" depends="dist-lite,xdocs,javadocs">

        <echo message ="building mailet SDK distributions"/>

        <mkdir dir="${dist.dir}/MailetSDK/src"/>
        <mkdir dir="${dist.dir}/MailetSDK/javadocs"/>
        <copy todir="${dist.dir}/MailetSDK/src">
            <fileset dir="src">
                <include name="**/mailet/**"/>
            </fileset>
        </copy>
        <copy todir="${dist.dir}/MailetSDK/javadocs">
            <fileset dir="${build.dir}/mailet">
                <include name="**/*"/>
            </fileset>
        </copy>
        <zip zipfile="${dist.dir}/downloads/bin/${name}-MailetSDK-${version}.zip">
            <fileset dir="dist">
                <include name="${name}-${version}/**"/>
                <exclude name="${name}-${version}/downloads/**"/>
            </fileset>
        </zip>
        <tar longfile="gnu" tarfile="${dist.dir}/downloads/bin/${name}-MailetSDK-${version}.tar">
            <tarfileset dir="dist" username="${name}" group="${name}">
                <include name="${name}-${version}/**"/>
                <exclude name="${name}-${version}/downloads/**"/>
            </tarfileset>
        </tar>
        <gzip zipfile="${dist.dir}/downloads/bin/${name}-MailetSDK-${version}.tar.gz"
            src="${dist.dir}/downloads/bin/${name}-MailetSDK-${version}.tar"/>
        <delete file="${dist.dir}/downloads/bin/${name}-MailetSDK-${version}.tar"/>
        <delete dir="${dist.dir}/MailetSDK"/>
    </target>

    <!--
    ===================================================================
                                  delete dist/ and build/
    ===================================================================
    -->
    <target name="clean">
        <echo message ="deleting working directories ready for a clean build"/>
        <delete dir="${dist.dir}"/>
        <delete dir="${build.dir}"/>
    </target>

    <!--
    ===================================================================
                                  unit tests
    ===================================================================
    -->
    <target name="unit-tests-classpath" depends="compile">
        <path id="unittest.class.path">
            <pathelement location="tools/lib/commons-net-1.4.1.jar"/>
            <pathelement location="tools/lib/jmock-1.1.0.jar"/>
            <fileset dir="${lib.dir}">
                <include name="*.jar"/>
            </fileset>
        </path>
    </target>
        
    <target name="compile-unit-tests" depends="unit-tests-classpath">
        <echo message="Compiling James Unit Test Java sources"/>
        <mkdir dir="${build.test}"/>
        <mkdir dir="${build.test.classes}"/>
        <javac destdir="${build.test.classes}" debug="${debug}" optimize="${optimize}" deprecation="${deprecation}" target="${jdk.target}" source="${jdk.source}">
            <classpath refid="unittest.class.path"/>
            <classpath refid="project.class.path"/>
            <src path="${junitjava.dir}"/>
            <exclude name="${constants.file}"/>
        </javac>
        <copy todir="${build.test.classes}">
            <fileset dir="${junitjava.dir}" includes="**/*.zone" />
            <fileset dir="${junitjava.dir}" includes="**/*.xml" />        	
        </copy>
    </target>

    <target name="run-unit-tests" depends="compile-unit-tests">
        <echo message="Running James Unit Tests"/>
        <mkdir dir="${build.test}"/>
        <mkdir dir="${build.test.reports}"/>
        <junit printsummary="yes" haltonfailure="yes"  >
            <classpath refid="unittest.class.path"/>
            <classpath refid="project.class.path"/>
            <classpath>
              <pathelement location="${build.test.classes}"/>
            </classpath>
        
            <formatter type="plain"/>
        
            <batchtest fork="yes" todir="${build.test.reports}">
              <fileset dir="${junitjava.dir}">
                <include name="**/*Test.java"/>
                <exclude name="**/AllTests.java"/>
                <exclude name="**/Abstract*.java"/>
              </fileset>
            </batchtest>
        </junit>
    </target>

    <target name="ensure-test-name" unless="test">
        <fail message="You must run this target with -Dtest=TestName"/>
    </target>

    <target name="run-unit-test" depends="compile-unit-tests, ensure-test-name">
        <echo message="Running A Single James Unit Test"/>
        <mkdir dir="${build.test}"/>
        <mkdir dir="${build.test.reports}"/>
        <junit printsummary="yes" haltonfailure="yes"  >
            <classpath refid="unittest.class.path"/>
            <classpath refid="project.class.path"/>
            <classpath>
              <pathelement location="${build.test.classes}"/>
            </classpath>
        
            <formatter type="plain"/>
        
            <batchtest fork="yes" todir="${build.test.reports}">
                <fileset dir="${junitjava.dir}">
                    <include name="**/${test}.java"/>
                </fileset>
            </batchtest>
        </junit>
    </target>

    <!--
    ===================================================================
                                   Help on usage
    ===================================================================
    -->
    <target name="usage">
        <echo message=""/>
        <echo message=""/>
        <echo message="James Build file"/>
        <echo message="-------------------------------------------------------------"/>
        <echo message=""/>
        <echo message=" available targets are:"/>
        <echo message=""/>
        <echo message="   dist-lite --> generates unpacked distribution (default)"/>
        <echo message="   website   --> makes all the docs and javadocs"/>
        <echo message="   compile   --> compiles the source code"/>
        <echo message="   dist      --> generates all the James distributions, packed"/>
        <echo message="   clean     --> cleans up the directory"/>
        <echo message="   xdocs     --> creates the documentaion for James"/>
        <echo message="   javadocs  --> creates the Javadoc"/>
        <echo message=""/>
        <echo message=" See the comments inside the build.xml file for more details."/>
        <echo message="-------------------------------------------------------------"/>
        <echo message=""/>
        <echo message=""/>
    </target>

</project>
