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

    DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.

    Copyright (c) 1997-2017 Oracle and/or its affiliates. All rights reserved.

    The contents of this file are subject to the terms of either the GNU
    General Public License Version 2 only ("GPL") or the Common Development
    and Distribution License("CDDL") (collectively, the "License").  You
    may not use this file except in compliance with the License.  You can
    obtain a copy of the License at
    https://oss.oracle.com/licenses/CDDL+GPL-1.1
    or LICENSE.txt.  See the License for the specific
    language governing permissions and limitations under the License.

    When distributing the software, include this License Header Notice in each
    file and include the License file at LICENSE.txt.

    GPL Classpath Exception:
    Oracle designates this particular file as subject to the "Classpath"
    exception as provided by Oracle in the GPL Version 2 section of the License
    file that accompanied this code.

    Modifications:
    If applicable, add the following below the License Header, with the fields
    enclosed by brackets [] replaced by your own identifying information:
    "Portions Copyright [year] [name of copyright owner]"

    Contributor(s):
    If you wish your version of this file to be governed by only the CDDL or
    only the GPL Version 2, indicate your decision by adding "[Contributor]
    elects to include this software in this distribution under the [CDDL or GPL
    Version 2] license."  If you don't indicate a single choice of license, a
    recipient has the option to distribute your version of this file under
    either the CDDL, the GPL Version 2 or to extend the choice of license to
    its licensees as provided above.  However, if you add GPL Version 2 code
    and therefore, elected the GPL Version 2 license, then the option applies
    only if the new code is made subject to such option by the copyright
    holder.

-->

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

<!--

    NOTE: JavaMail is now built using Maven:
    https://java.net/projects/javamail/pages/BuildInstructions

    This ant build file is obsolete and may not work.

-->

<project name="JavaMail" 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 JavaMail sources">

        <copy file="${resources.dir}/javax/mail/Version.java"
		toFile="${src.dir}/javax/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="javax/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>

    <!-- JavaMail bundle build targets -->

    <target name="release" depends="init, jars, democompile, docs">
	<!-- XXX - need to replace "." with "_" in release.version -->
        <property name="rel" value="javamail-${release.version}"/>
        <property name="zipname" value="${rel}.zip"/>
        <delete file="${basedir}/target/${zipname}"/>
        <echo message="Creating JavaMail 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="javax/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="javax/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="javax/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="javax/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="javax.mail, javax.mail.internet,
                               javax.mail.search, javax.mail.event,
                               javax.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="JavaMail API documentation"
            doctitle="JavaMail API documentation">
            <group title="JavaMail 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>
