<?xml version="1.0" encoding="iso-8859-1"?>
<!--

    Copyright (c) 1997, 2020 Oracle and/or its affiliates. All rights reserved.

    This program and the accompanying materials are made available under the
    terms of the Eclipse Public License v. 2.0, which is available at
    http://www.eclipse.org/legal/epl-2.0.

    This Source Code may also be made available under the following Secondary
    Licenses when the conditions for such availability set forth in the
    Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
    version 2 with the GNU Classpath Exception, which is available at
    https://www.gnu.org/software/classpath/license.html.

    SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0

-->

<!DOCTYPE project [
  <!ENTITY commonBuild SYSTEM "ant-common.xml">
]>

<!--

    NOTE: Jakarta Mail is now built using Maven:
    https://eclipse-ee4j.github.io/jakartamail/Build-Instructions

    This ant build file is obsolete and may not work.

-->

<project name="Jakarta Mail" default="all" basedir=".">

<!-- ========== Initialize Properties =================================== -->

    <!--
        component.name: required property.  the value should be the
                        name of the component directory
    -->
    <property name="component.name" value="mail"/>

    <property file="./build.properties"/>
    
    &commonBuild;

    <!-- all -->
    <target name="all" depends="compile, assemble"
            description="Build entire component">
    </target>

    <!-- build -->
    <target name="build" depends="compile, assemble"
            description="Build entire component">
    </target>

    <!-- init. Initialization involves creating publishing directories and
         OS specific targets. -->
    <target name="init" description="${component.name} initialization">
        <tstamp>
            <format property="start.time" pattern="MM/dd/yyyy hh:mm aa"/>
        </tstamp>
        <echo message="Building component ${component.name}"/>
        <mkdir dir="${component.classes.dir}"/>
    </target>

    <!-- compile -->
    <target name="compile" depends="init"
            description="Compile Jakarta Mail sources">

        <copy file="${resources.dir}/jakarta/mail/Version.java"
		toFile="${src.dir}/jakarta/mail/Version.java">
            <filterset begintoken="$${" endtoken="}">
                <filter token="mail.version" value="${release.version}"/>
            </filterset>
        </copy>
        <javac srcdir="${src.dir}"
               destdir="${component.classes.dir}"
               debug="${javac.debug}"
               optimize="${javac.optimize}"
               source="${javac.source}"
               deprecation="${javac.deprecation}"
               failonerror="true"
               target="${javac.target}"
	       includeantruntime="false">
            <classpath>
                <pathelement location="${activation.jar}"/>
            </classpath>
            <include name="jakarta/mail/**"/>
            <include name="com/sun/mail/**"/>
        </javac>
    </target>
    
    <!-- prepare manifest files for jars -->
    <target name="cook-manifest" depends="init"
            description="Generate MANIFEST.MF files">
	<!--

	    Could make this simpler with ant-contrib foreach task...

	<foreach list=",imap.,pop3.,smtp.,dsn." target="cook-manifest-file"
	    param="mf"/>
	-->
        <mkdir dir="${component.classes.dir}/manifest"/>
        <copy file="${resources.dir}/META-INF/MANIFEST.MF"
		tofile="${component.classes.dir}/manifest/MANIFEST.MF">
            <filterset begintoken="{" endtoken="}">
		<filter token="mail.spec.version"
		    value="${release.specversion}"/>
		<filter token="mail.version" value="${release.version}"/>
            </filterset>
        </copy>
        <mkdir dir="${component.classes.imap.dir}/manifest"/>
        <copy file="${resources.imap.dir}/META-INF/MANIFEST.MF"
		tofile="${component.classes.imap.dir}/manifest/MANIFEST.MF">
            <filterset begintoken="{" endtoken="}">
		<filter token="mail.spec.version"
		    value="${release.specversion}"/>
		<filter token="mail.version" value="${release.version}"/>
            </filterset>
        </copy>
        <mkdir dir="${component.classes.pop3.dir}/manifest"/>
        <copy file="${resources.pop3.dir}/META-INF/MANIFEST.MF"
		tofile="${component.classes.pop3.dir}/manifest/MANIFEST.MF">
            <filterset begintoken="{" endtoken="}">
		<filter token="mail.spec.version"
		    value="${release.specversion}"/>
		<filter token="mail.version" value="${release.version}"/>
            </filterset>
        </copy>
        <mkdir dir="${component.classes.smtp.dir}/manifest"/>
        <copy file="${resources.smtp.dir}/META-INF/MANIFEST.MF"
		tofile="${component.classes.smtp.dir}/manifest/MANIFEST.MF">
            <filterset begintoken="{" endtoken="}">
		<filter token="mail.spec.version"
		    value="${release.specversion}"/>
		<filter token="mail.version" value="${release.version}"/>
            </filterset>
        </copy>
        <mkdir dir="${component.classes.dsn.dir}/manifest"/>
        <copy file="${resources.dsn.dir}/META-INF/MANIFEST.MF"
		tofile="${component.classes.dsn.dir}/manifest/MANIFEST.MF">
            <filterset begintoken="{" endtoken="}">
		<filter token="mail.spec.version"
		    value="${release.specversion}"/>
		<filter token="mail.version" value="${release.version}"/>
            </filterset>
        </copy>
        <mkdir dir="${component.classes.gimap.dir}/manifest"/>
        <copy file="${resources.gimap.dir}/META-INF/MANIFEST.MF"
		tofile="${component.classes.gimap.dir}/manifest/MANIFEST.MF">
            <filterset begintoken="{" endtoken="}">
		<filter token="mail.spec.version"
		    value="${release.specversion}"/>
		<filter token="mail.version" value="${release.version}"/>
            </filterset>
        </copy>
    </target>

    <!--

	This could be used with foreach, above.
	XXX - do nested variable references work?

    <target name="cook-manifest-file">
        <mkdir dir="${component.classes.${mf}dir}/manifest"/>
        <copy file="${resources.${mf}dir}/META-INF/MANIFEST.MF"
		tofile="${component.classes.${mf}dir}/manifest/MANIFEST.MF">
            <filterset begintoken="{" endtoken="}">
		<filter token="mail.spec.version"
		    value="${release.specversion}"/>
		<filter token="mail.version" value="${release.version}"/>
            </filterset>
        </copy>
    </target>
    -->

    <!-- gimap compile -->
    <target name="gimapcompile" depends="init"
            description="Compile com/sun/mail/gimap sources">

        <mkdir dir="${component.classes.gimap.dir}"/>
        <javac srcdir="${src.gimap.dir}"
               destdir="${component.classes.gimap.dir}"
               debug="${javac.debug}"
               optimize="${javac.optimize}"
               source="${javac.source}"
               deprecation="${javac.deprecation}"
               failonerror="true"
               target="${javac.target}"
	       includeantruntime="false">
            <classpath>
                <pathelement location="${component.classes.dir}"/>
                <pathelement location="${activation.jar}"/>
            </classpath>
            <include name="com/sun/mail/gimap/**"/>
        </javac>
    </target>

    <!-- dsn compile -->
    <target name="dsncompile" depends="init"
            description="Compile com/sun/mail/dsn sources">

        <mkdir dir="${component.classes.dsn.dir}"/>
        <javac srcdir="${src.dsn.dir}"
               destdir="${component.classes.dsn.dir}"
               debug="${javac.debug}"
               optimize="${javac.optimize}"
               source="${javac.source}"
               deprecation="${javac.deprecation}"
               failonerror="true"
               target="${javac.target}"
	       includeantruntime="false">
            <classpath>
                <pathelement location="${component.classes.dir}"/>
                <pathelement location="${activation.jar}"/>
            </classpath>
            <include name="com/sun/mail/dsn/**"/>
        </javac>
    </target>

    <!-- demo compile -->
    <target name="democompile" depends="init"
            description="Compile demo sources">

        <mkdir dir="${component.classes.demo.dir}"/>
        <javac srcdir="${src.demo.dir}"
               destdir="${component.classes.demo.dir}"
               debug="${javac.debug}"
               optimize="${javac.optimize}"
               source="${javac.source}"
               deprecation="${javac.deprecation}"
               failonerror="true"
               target="${javac.target}"
	       includeantruntime="false">
            <classpath>
                <pathelement location="${component.classes.dir}"/>
                <pathelement location="${activation.jar}"/>
            </classpath>
            <include name="*"/>
        </javac>

        <mkdir dir="${component.classes.client.dir}"/>
        <javac srcdir="${src.client.dir}"
               destdir="${component.classes.client.dir}"
               debug="${javac.debug}"
               optimize="${javac.optimize}"
               source="${javac.source}"
               deprecation="${javac.deprecation}"
               failonerror="true"
               target="${javac.target}"
	       includeantruntime="false">
            <classpath>
                <pathelement location="${component.classes.dir}"/>
                <pathelement location="${activation.jar}"/>
            </classpath>
            <include name="*"/>
        </javac>

        <mkdir dir="${component.classes.servlet.dir}"/>
        <javac srcdir="${src.servlet.dir}"
               destdir="${component.classes.servlet.dir}"
               debug="${javac.debug}"
               optimize="${javac.optimize}"
               source="${javac.source}"
               deprecation="${javac.deprecation}"
               failonerror="true"
               target="${javac.target}"
	       includeantruntime="false">
            <classpath>
                <pathelement location="${component.classes.dir}"/>
                <pathelement location="${activation.jar}"/>
                <pathelement location="${javaee.jar}"/>
            </classpath>
            <include name="*"/>
        </javac>

        <mkdir dir="${component.classes.logging.dir}"/>
        <javac srcdir="${src.logging.dir}"
               destdir="${component.classes.logging.dir}"
               debug="${javac.debug}"
               optimize="${javac.optimize}"
               source="${javac.source}"
               deprecation="${javac.deprecation}"
               failonerror="true"
               target="${javac.target}"
	       includeantruntime="false">
            <classpath>
                <pathelement location="${component.classes.dir}"/>
                <pathelement location="${component.classes.demo.dir}"/>
                <pathelement location="${activation.jar}"/>
            </classpath>
            <include name="*"/>
        </javac>

	<!-- XXX - still need to add rules to build webapp -->

    </target>

    <!-- assemble -->
    <target name="assemble" depends="jar"/>

    <target name="clean" description="Clean the build">
        <delete includeEmptyDirs="true" failonerror="false">
            <fileset dir="${component.classes.dir}"/>
            <fileset dir="${component.classes.dsn.dir}"/>
            <fileset dir="${component.classes.gimap.dir}"/>
            <fileset dir="${component.classes.demo.dir}"/>
            <fileset dir="${component.classes.client.dir}"/>
            <fileset dir="${component.classes.servlet.dir}"/>
            <fileset dir="${component.classes.logging.dir}"/>
        </delete>
    </target>

    <target name="clobber" description="Clobber all derived files">
        <delete includeEmptyDirs="true" failonerror="false">
            <fileset dir="target"/>
        </delete>
    </target>

    <!-- Jakarta Mail bundle build targets -->

    <target name="release" depends="init, jars, democompile, docs">
	<!-- XXX - need to replace "." with "_" in release.version -->
        <property name="rel" value="jakartamail-${release.version}"/>
        <property name="zipname" value="${rel}.zip"/>
        <delete file="${basedir}/target/${zipname}"/>
        <echo message="Creating Jakarta Mail bundle ${basedir}/target/${zipname}"/>
        <zip destfile="${basedir}/target/${zipname}">
	    <zipfileset dir="${release.dir}" prefix="${rel}"/>
            <zipfileset dir="${src.demo.dir}" prefix="${rel}/demo"
                excludes="**/internal/**"/>
            <zipfileset dir="${src.client.dir}" prefix="${rel}/demo/client"/>
            <zipfileset dir="${src.servlet.dir}"
		prefix="${rel}/demo/servlet"/>
            <zipfileset dir="webapp" prefix="${rel}/demo/webapp"
		excludes="src/**,pom.xml"/>
            <zipfileset dir="${src.webapp.dir}"
		prefix="${rel}/demo/webapp/src/classes"/>
            <zipfileset dir="${docroot.webapp.dir}"
		prefix="${rel}/demo/webapp/src/docroot"/>
            <zipfileset dir="${src.taglib.dir}"
		prefix="${rel}/demo/webapp/src/taglib"/>
            <zipfileset dir="${resources.taglib.dir}"
		prefix="${rel}/demo/webapp/src/taglib"/>
            <zipfileset dir="${src.logging.dir}"
		prefix="${rel}/demo/logging"/>
        </zip>
    </target>

    <!-- Build all jars needed for release -->
    <target name="jars"
	depends="jar, mailapijar, pop3jar, imapjar, smtpjar, gimapjar, dsnjar"/>

    <!-- Assemble mail.jar -->
    <target name="jar" depends="init, compile, cook-manifest">
        <mkdir dir="${release.dir}"/>
        <jar jarfile="${release.mail.jar}"
		manifest="${component.classes.dir}/manifest/MANIFEST.MF">
            <metainf dir="${resources.legal.dir}/META-INF"
		    includes="LICENSE.txt"/>
            <metainf dir="${resources.dir}/META-INF"
                    includes="javamail.charset.map,javamail.default.*,mailcap"/>
            <fileset dir="${component.classes.dir}">
                <include name="jakarta/mail/**/*.class"/>
                <include name="com/sun/mail/**/*.class"/>
            </fileset>
        </jar>
    </target>

    <!-- Create zip file of source code to publish to maven repo -->
    <target name="src">
        <zip file="target/mail.src.zip">
            <fileset dir="${src.dir}">
                <include name="jakarta/mail/**/*.java"/>
                <include name="com/sun/mail/**/*.java"/>
            </fileset>
        </zip>
    </target>

    <target name="imapjar" depends="init, compile, cook-manifest">
        <mkdir dir="${release.dir}/lib"/>
        <jar jarfile="${release.imap.jar}"
		manifest="${component.classes.imap.dir}/manifest/MANIFEST.MF">
            <metainf dir="${resources.legal.dir}/META-INF"
		    includes="LICENSE.txt"/>
            <metainf dir="${resources.imap.dir}/META-INF"
		    includes="javamail.providers"/>
            <fileset dir="${component.classes.dir}">
                <include name="com/sun/mail/iap/*.class"/>
                <include name="com/sun/mail/imap/*.class"/>
                <include name="com/sun/mail/imap/protocol/*.class"/>
            </fileset>
        </jar>
    </target>

    <target name="pop3jar" depends="init, compile, cook-manifest">
        <mkdir dir="${release.dir}/lib"/>
        <jar jarfile="${release.pop3.jar}"
		manifest="${component.classes.pop3.dir}/manifest/MANIFEST.MF">
            <metainf dir="${resources.legal.dir}/META-INF"
		    includes="LICENSE.txt"/>
            <metainf dir="${resources.pop3.dir}/META-INF"
		    includes="javamail.providers"/>
            <fileset dir="${component.classes.dir}">
                <include name="com/sun/mail/pop3/*.class"/>
            </fileset>
        </jar>
     </target>

     <target name="smtpjar" depends="init, compile, cook-manifest">
        <mkdir dir="${release.dir}/lib"/>
        <jar jarfile="${release.smtp.jar}"
		manifest="${component.classes.smtp.dir}/manifest/MANIFEST.MF">
            <metainf dir="${resources.legal.dir}/META-INF"
		    includes="LICENSE.txt"/>
            <metainf dir="${resources.smtp.dir}/META-INF"
		    includes="javamail.providers,javamail.address.map"/>
            <fileset dir="${component.classes.dir}">
                <include name="com/sun/mail/smtp/*.class"/>
            </fileset>
        </jar>
     </target>

     <target name="gimapjar" depends="init, gimapcompile, cook-manifest">
        <mkdir dir="${release.dir}/lib"/>
        <jar jarfile="${release.gimap.jar}"
		manifest="${component.classes.gimap.dir}/manifest/MANIFEST.MF">
            <metainf dir="${resources.legal.dir}/META-INF"
		    includes="LICENSE.txt"/>
            <metainf dir="${resources.gimap.dir}/META-INF"
		    includes="mailcap"/>
            <fileset dir="${component.classes.gimap.dir}">
                <include name="com/sun/mail/gimap/*.class"/>
            </fileset>
        </jar>
     </target>

     <target name="dsnjar" depends="init, dsncompile, cook-manifest">
        <mkdir dir="${release.dir}/lib"/>
        <jar jarfile="${release.dsn.jar}"
		manifest="${component.classes.dsn.dir}/manifest/MANIFEST.MF">
            <metainf dir="${resources.legal.dir}/META-INF"
		    includes="LICENSE.txt"/>
            <metainf dir="${resources.dsn.dir}/META-INF"
		    includes="mailcap"/>
            <fileset dir="${component.classes.dsn.dir}">
                <include name="com/sun/mail/dsn/*.class"/>
            </fileset>
        </jar>
     </target>

     <target name="mailapijar" depends="init, compile, cook-manifest">
        <mkdir dir="${release.dir}/lib"/>
        <jar jarfile="${release.mailapi.jar}"
		manifest="${component.classes.dir}/manifest/MANIFEST.MF">
            <metainf dir="${resources.legal.dir}/META-INF"
		    includes="LICENSE.txt"/>
            <metainf dir="${resources.dir}/META-INF"
		    includes="javamail.charset.map, mailcap"/>
            <fileset dir="${component.classes.dir}">
                <include name="jakarta/mail/**/*.class"/>
                <include name="com/sun/mail/util/*.class"/>
                <include name="com/sun/mail/handlers/*.class"/>
            </fileset>
        </jar>
    </target>

    <!-- javadocs -->
    <target name="docs" depends="init, jar, jar">
        <copy todir="${release.dir}">
            <fileset dir="${basedir}/doc/release" includes="*.txt" />
        </copy>
        <mkdir dir="${release.docs.dir}"/>
        <copy todir="${release.docs.dir}">
            <fileset dir="${basedir}/doc/spec" includes="*.txt" />
        </copy>
	<!--
	    To allow us to generate javadocs that only include some
	    classes in certain packages, we need to copy the sources
	    to another location and run javadoc against that subset
	    of the sources.
	-->
        <copy todir="${release.dir}/javadoc">
	    <fileset dir="${src.dir}">
		<include name="**/*.html"/>
		<include name="jakarta/mail/**"/>
	    </fileset>
	    <fileset dir="${src.dir}"
		includes="
		    com/sun/mail/imap/IMAPFolder.java,
		    com/sun/mail/imap/IMAPMessage.java,
		    com/sun/mail/imap/IMAPStore.java,
		    com/sun/mail/imap/IMAPSSLStore.java
		    com/sun/mail/imap/ACL.java,
		    com/sun/mail/imap/Rights.java,
		    com/sun/mail/imap/Quota.java,
		    com/sun/mail/imap/SortTerm.java,
		    com/sun/mail/pop3/POP3Store.java,
		    com/sun/mail/pop3/POP3SSLStore.java,
		    com/sun/mail/pop3/POP3Folder.java,
		    com/sun/mail/pop3/POP3Message.java,
		    com/sun/mail/smtp/SMTPMessage.java,
		    com/sun/mail/smtp/SMTPAddressFailedException.java,
		    com/sun/mail/smtp/SMTPAddressSucceededException.java,
		    com/sun/mail/smtp/SMTPSendFailedException.java,
		    com/sun/mail/smtp/SMTPSenderFailedException.java,
		    com/sun/mail/smtp/SMTPTransport.java,
		    com/sun/mail/smtp/SMTPSSLTransport.java,
		    com/sun/mail/util/MailConnectException.java,
		    com/sun/mail/util/MailSSLSocketFactory.java,
		    com/sun/mail/util/ReadableMime.java,
		    com/sun/mail/util/logging/MailHandler.java
		"/>
	    <fileset dir="${src.dsn.dir}"
		includes="
		    com/sun/mail/dsn/package.html,
		    com/sun/mail/dsn/DeliveryStatus.java,
		    com/sun/mail/dsn/DispositionNotification.java,
		    com/sun/mail/dsn/MessageHeaders.java,
		    com/sun/mail/dsn/MultipartReport.java,
		    com/sun/mail/dsn/Report.java
		"/>
	    <fileset dir="${src.dsn.dir}"
		includes="
		    com/sun/mail/gimap/package.html,
		    com/sun/mail/gimap/GmailStore.java,
		    com/sun/mail/gimap/GmailSSLStore.java,
		    com/sun/mail/gimap/GmailFolder.java,
		    com/sun/mail/gimap/GmailMessage.java,
		    com/sun/mail/gimap/GmailMsgIdTerm.java,
		    com/sun/mail/gimap/GmailThrIdTerm.java,
		    com/sun/mail/gimap/GmailRawSearchTerm.java
		"/>
        </copy>
        <mkdir dir="${release.javadocs.dir}"/>
        <javadoc packagenames="jakarta.mail, jakarta.mail.internet,
                               jakarta.mail.search, jakarta.mail.event,
                               jakarta.mail.util,
                               com.sun.mail.imap,
                               com.sun.mail.pop3,
                               com.sun.mail.smtp,
                               com.sun.mail.gimap,
                               com.sun.mail.util, com.sun.mail.util.logging,
                               com.sun.mail.dsn"
            destdir="${release.javadocs.dir}"
	    sourcepath="${release.dir}/javadoc"
            classpath="${activation.jar}:${release.mail.jar}:${release.dsn.jar}:${release.gimap.jar}"
            author="false"
            version="false"
            use="true"
            overview="${release.dir}/javadoc/overview.html"
            windowtitle="Jakarta Mail API documentation"
            doctitle="Jakarta Mail API documentation">
            <group title="Jakarta Mail API Packages" packages="javax.*"/>
            <group title="Sun-specific Packages" packages="com.sun.*"/>
	    <bottom>
<![CDATA[Copyright &#169; 1996-2013,
    <a href="http://www.oracle.com">Oracle</a>
    and/or its affiliates. All Rights Reserved.
    Use is subject to
    <a href="{@docRoot}/doc-files/speclicense.html" target="_top">license terms<
    /a>.
]]>

	    </bottom>
	    <!-- following can really slow down javadoc generation
	    <link href="${javase.url}"/>
	    <link href="${jaf.url}"/>
	    -->
        </javadoc>
    </target>

    <target name="push-to-maven-prepare" depends="-push-to-maven-init, jar, src"
        description="creates an image for the 'push-to-maven' goal">
        <delete dir="target/maven-repo" /><!-- clean it -->
        <maven-repository-importer
		destdir="target/maven-repo" version="${release.version}">
            <artifact jar="target/release/mail.jar" pom="mail.pom"
		    srczip="target/mail.src.zip" />
        </maven-repository-importer>
    </target>

    <target name="push-to-maven" depends="push-to-maven-prepare"
        description="pushes jars to the java.net maven repository">
        <cvs-import src="target/maven-repo" dest="glassfish/repo" />
    </target>
</project>
