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

<project name="crypto.bcbuild" default="build" basedir=".">

    <property file="bc-build.properties" />

    <property environment="env" />

    <property name="target.name" value="${target.prefix}-${release.suffix}" />
    <property name="build.dir" value="${src.dir}/.." />
    <property name="bzip2.src.dir" value="${basedir}/pg/src/main/java" />
    <property name="artifacts.reports.xml.dir" value="${artifacts.dir}/reports/xml" />
    <property name="artifacts.reports.html.dir" value="${artifacts.dir}/reports/html" />
    <property name="artifacts.jars.dir" value="${artifacts.dir}/jars" />
    <property name="artifacts.docs.dir" value="${artifacts.dir}/javadoc" />

    <property name="jce.target" value="jce-${target.name}" />
    <property name="jce.target.dir" value="${artifacts.dir}/${jce.target}" />
    <property name="jce.target.src.dir" value="${jce.target.dir}/src" />
    <property name="jce.target.docs.dir" value="${jce.target.dir}/javadoc" />
    <property name="jce.target.src.zip" value="${jce.target.dir}/src.zip" />

    <property name="provider.target" value="bcprov-${target.name}" />
    <property name="provider.target.dir" value="${artifacts.dir}/${provider.target}" />
    <property name="provider.target.src.dir" value="${provider.target.dir}/src" />
    <property name="provider.target.docs.dir" value="${provider.target.dir}/javadoc" />
    <property name="provider.target.src.zip" value="${provider.target.dir}/src.zip" />

    <property name="mail.target" value="bcmail-${target.name}" />
    <property name="mail.target.dir" value="${artifacts.dir}/${mail.target}" />
    <property name="mail.target.src.dir" value="${mail.target.dir}/src" />
    <property name="mail.target.docs.dir" value="${mail.target.dir}/javadoc" />
    <property name="mail.target.src.zip" value="${mail.target.dir}/src.zip" />

    <property name="pkix.target" value="bcpkix-${target.name}" />
    <property name="pkix.target.dir" value="${artifacts.dir}/${pkix.target}" />
    <property name="pkix.target.src.dir" value="${pkix.target.dir}/src" />
    <property name="pkix.target.docs.dir" value="${pkix.target.dir}/javadoc" />
    <property name="pkix.target.src.zip" value="${pkix.target.dir}/src.zip" />

    <property name="pg.target" value="bcpg-${target.name}" />
    <property name="pg.target.dir" value="${artifacts.dir}/${pg.target}" />
    <property name="pg.target.src.dir" value="${pg.target.dir}/src" />
    <property name="pg.target.docs.dir" value="${pg.target.dir}/javadoc" />
    <property name="pg.target.src.zip" value="${pg.target.dir}/src.zip" />

    <property name="lcrypto.target" value="lcrypto-${target.name}" />
    <property name="lcrypto.target.dir" value="${artifacts.dir}/${lcrypto.target}" />
    <property name="lcrypto.target.src.dir" value="${lcrypto.target.dir}/src" />
    <property name="lcrypto.target.classes.dir" value="${lcrypto.target.dir}/classes" />
    <property name="lcrypto.target.docs.dir" value="${lcrypto.target.dir}/javadoc" />

    <path id="project.classpath">
        <pathelement location="${mail.jar.home}" />
        <pathelement location="${activation.jar.home}" />
        <pathelement location="${junit.jar.home}" />
    </path> 

    <target name="pack200-on" if="pack200.enabled">
        <taskdef name="pack200" classname="com.sun.tools.apache.ant.pack200.Pack200Task"
            classpath="lib/Pack200Task.jar"/>
        <macrodef name="packJar">
            <attribute name="jarbase" />
            <element name="manifest-element" />
            <element name="fileset-element" />
            <sequential>
                <jar jarfile="@{jarbase}.tmp.jar">
                    <manifest-element/>
                    <fileset-element/>
                </jar>
                <pack200 src="@{jarbase}.tmp.jar" destfile="@{jarbase}.jar" repack="true" segmentLimit="-1" />
                <delete file="@{jarbase}.tmp.jar" />
            </sequential>
        </macrodef>
    </target>
    <target name="pack200-off" unless="pack200.enabled">
        <macrodef name="packJar">
            <attribute name="jarbase" />
            <element name="manifest-element" />
            <element name="fileset-element" />
            <sequential>
                <jar jarfile="@{jarbase}.jar">
                    <manifest-element/>
                    <fileset-element/>
                </jar>
            </sequential>
        </macrodef>
    </target>
    <target name="initPackJar" depends="pack200-on, pack200-off" />

    <target name="initMacros" depends="initPackJar">

        <macrodef name="compile">
            <attribute name="target" />
            <element name="manifestElements" />
            <element name="jarFileSet" />
            <sequential>
                <mkdir dir="${build.dir}/@{target}/classes" />
                <mkdir dir="${artifacts.dir}/@{target}" />

                <javac source="${bc.javac.source}" target="${bc.javac.target}"
                    srcdir="${artifacts.dir}/@{target}/src"
                    destdir="${build.dir}/@{target}/classes"
                    debug="${release.debug}">
                    <classpath>
                        <path refid="project.classpath" /> 
                        <fileset dir="${artifacts.jars.dir}">
                            <include name="**/*.jar" />
                        </fileset>
                    </classpath>
                </javac>
                <copy todir="${build.dir}/@{target}/classes">
                     <fileset dir="${artifacts.dir}/@{target}/src" includes="**/*.properties" />
                </copy>
                <packJar jarbase="${artifacts.jars.dir}/@{target}">
                    <manifest-element>
                        <manifest>
                            <manifestElements/>
                        </manifest>
                    </manifest-element>
                    <fileset-element>
                        <fileset dir="${build.dir}/@{target}/classes">
                            <jarFileSet/>
                        </fileset>
                    </fileset-element>
                </packJar>
            </sequential>
        </macrodef>

        <macrodef name="compile-test">
            <attribute name="target" />
            <element name="manifestElements" />
            <sequential>
                <mkdir dir="${build.dir}/@{target}/classes" />
                <mkdir dir="${artifacts.dir}/@{target}" />

                <javac source="${bc.javac.source}" target="${bc.javac.target}"
                    srcdir="${artifacts.dir}/@{target}/src"
                    destdir="${build.dir}/@{target}/classes"
                    debug="${release.debug}">
                    <classpath>
                        <path refid="project.classpath" /> 
                        <fileset dir="${artifacts.jars.dir}">
                            <include name="**/*.jar" />
                        </fileset>
                    </classpath>
                </javac>
                <copy todir="${build.dir}/@{target}/classes">
                     <fileset dir="${artifacts.dir}/@{target}/src" includes="**/*.asc" />
                     <fileset dir="${artifacts.dir}/@{target}/src" includes="**/*.pem" />
                     <fileset dir="${artifacts.dir}/@{target}/src" includes="**/*.p7m" />
                     <fileset dir="${artifacts.dir}/@{target}/src" includes="**/*.message" />
                     <fileset dir="${artifacts.dir}/@{target}/src" includes="**/*.properties" />
                     <fileset dir="${artifacts.dir}/@{target}/src" includes="**/*.eml" />
                     <fileset dir="${artifacts.dir}/@{target}/src" includes="**/*.sig" />
                     <fileset dir="${artifacts.dir}/@{target}/src" includes="**/*.data" />
                     <fileset dir="${artifacts.dir}/@{target}/src" includes="**/*.crt" />
                     <fileset dir="${artifacts.dir}/@{target}/src" includes="**/*.cvcert" />
                     <fileset dir="${artifacts.dir}/@{target}/src" includes="**/*.csr" />
                     <fileset dir="${artifacts.dir}/@{target}/src" includes="**/*.crl" />
                     <fileset dir="${artifacts.dir}/@{target}/src" includes="**/*.cer" />
                     <fileset dir="${artifacts.dir}/@{target}/src" includes="**/*.der" />
                     <fileset dir="${artifacts.dir}/@{target}/src" includes="**/*.txt" />
                     <fileset dir="${artifacts.dir}/@{target}/src" includes="**/*.rsp" />
                </copy>
                <packJar jarbase="${artifacts.jars.dir}/@{target}">
                    <manifest-element>
                        <manifest>
                            <manifestElements/>
                        </manifest>
                    </manifest-element>
                    <fileset-element>
                        <fileset dir="${build.dir}/@{target}/classes">
                            <include name="**/*.class" />
                            <include name="**/*.asc" />
                            <include name="**/*.pem" />
                            <include name="**/*.p7m" />
                            <include name="**/*.crl" />
                            <include name="**/*.der" />
                            <include name="**/*.crt" />
                            <include name="**/*.csr" />
                            <include name="**/*.cvcert" />
                            <include name="**/*.eml" />
                            <include name="**/*.sig" />
                            <include name="**/*.data" />
                            <include name="**/*.cer" />
                            <include name="**/*.der" />
                            <include name="**/*.message" />
                            <include name="**/*.txt" />
                            <include name="**/*.rsp" />
                            <include name="**/*.properties" />
                        </fileset>
                    </fileset-element>
                </packJar>
            </sequential>
        </macrodef>

        <macrodef name="compile-doc">
            <attribute name="srcDir" />
            <attribute name="docsDir" />
            <element name="docElements" />
            <sequential>
            <mkdir dir="@{docsDir}" />
            <javadoc maxmemory="384m" sourcepath="@{srcDir}"
                     destdir="@{docsDir}"
                     windowtitle="Bouncy Castle Library ${release.name} API Specification"
                     header="&lt;b&gt;Bouncy Castle Cryptography Library ${release.name}&lt;/b&gt;">
                <docElements/>
                <arg value="${javadoc.args}" />
                <classpath>
                    <path refid="project.classpath" /> 
                    <fileset dir="${artifacts.jars.dir}">
                        <include name="**/*.jar" />
                    </fileset>
                    <pathelement path="${env.CLASSPATH}" />
                </classpath>
            </javadoc>
            </sequential>
        </macrodef>

        <macrodef name="copyStandardFiles">
            <attribute name="toDir" />
            <sequential>
                <copy toDir="@{toDir}">
                     <fileset dir="${basedir}">
                         <include name="*.html" />
                     </fileset>
                </copy>
                <copy toDir="@{toDir}/docs">
                     <fileset dir="${basedir}/docs">
                         <include name="**/*.html" />
                     </fileset>
                </copy>
            </sequential>
        </macrodef>

    </target>

    <target name="build" depends="initMacros, build-lw, build-libraries, build-test" />

    <target name="build-lw" depends="initMacros">
        <!--
              Lightweight Libraries
        -->

        <mkdir dir="${lcrypto.target.dir}" />
        <mkdir dir="${lcrypto.target.src.dir}" />
        <mkdir dir="${lcrypto.target.classes.dir}" />

        <copyStandardFiles toDir="${lcrypto.target.dir}" />

        <copy todir="${lcrypto.target.src.dir}">
             <fileset dir="${src.dir}">
                 <exclude name="build/**" />
                 <include name="org/bouncycastle/*.java" />
                 <include name="org/bouncycastle/math/**/*.java" />
                 <include name="org/bouncycastle/crypto/**/*.java" />
                 <include name="org/bouncycastle/util/**/*.java" />
                 <include name="org/bouncycastle/asn1/**/*.java" />
                 <include name="org/bouncycastle/bcpg/**/*.java" />
                 <include name="org/bouncycastle/apache/**/*.java" />
                 <include name="org/bouncycastle/pqc/crypto/**/*.java" />
                 <include name="org/bouncycastle/pqc/math/**/*.java" />
                 <include name="org/bouncycastle/pqc/asn1/**/*.java" />
             </fileset>
        </copy>

        <javac source="${bc.javac.source}" target="${bc.javac.target}"
            srcdir="${lcrypto.target.src.dir}"
            destdir="${lcrypto.target.classes.dir}"
            debug="${release.debug}">
        </javac>
    </target>

    <!--
          Provider
    -->
    <target name="build-provider" depends="initMacros">
        <property name="provider" value="bcprov-${target.name}" />
        <property name="extprovider" value="bcprov-ext-${target.name}" />

        <mkdir dir="${artifacts.jars.dir}" />
        <delete dir="${provider.target.dir}" />
        <mkdir dir="${provider.target.dir}" />

        <copyStandardFiles toDir="${provider.target.dir}" />

        <copy todir="${provider.target.src.dir}">
             <fileset dir="${src.dir}">
                 <exclude name="build/**" />
                 <exclude name="PKITS/**" />
                 <exclude name="cmp/**" />
                 <exclude name="rfc4134/**" />
                 <exclude name="org/bouncycastle/**/AllTests.java" />
                 <exclude name="org/bouncycastle/**/test/**" />
                 <exclude name="org/bouncycastle/crypto/*/*Test.java" />
                 <exclude name="org/bouncycastle/util/*Test.java" />
                 <exclude name="**/*.crl" />
                 <exclude name="org/bouncycastle/util/utiltest/**" />
                 <exclude name="org/bouncycastle/bcpg/**" />
                 <exclude name="org/bouncycastle/cert/**" />
                 <exclude name="org/bouncycastle/cms/**" />
                 <exclude name="org/bouncycastle/dvcs/**" />
                 <exclude name="org/bouncycastle/eac/**" />
                 <exclude name="org/bouncycastle/mail/**" />
                 <exclude name="org/bouncycastle/openpgp/**" />
                 <exclude name="org/bouncycastle/openssl/**" />
                 <exclude name="org/bouncycastle/mozilla/**" />
                 <exclude name="org/bouncycastle/operator/**" />
                 <exclude name="org/bouncycastle/pkcs/**" />
                 <exclude name="org/bouncycastle/tsp/**" />
                 <exclude name="org/bouncycastle/voms/**" />
             </fileset>
             <fileset dir="${src.dir}" includes="org/bouncycastle/util/test/*.java" />
        </copy>

        <compile target="${provider}">
            <jarFileSet>
                <include name="**/*.class"/>
                <exclude name="**/javax/crypto/**/*.class"/>
                <exclude name="**/NTRU*.class" />
                <exclude name="**/ntru/**/*.class" />
                <include name="**/*.properties"/>
            </jarFileSet>
            <manifestElements>
                <attribute name="Manifest-Version" value="1.0" />
                <attribute name="Extension-Name" value="org.bouncycastle.bcprovider" />
                <attribute name="Specification-Vendor" value="BouncyCastle.org" />
                <attribute name="Specification-Version" value="1.1" />
                <attribute name="Implementation-Vendor-Id" value="org.bouncycastle" />
                <attribute name="Implementation-Vendor" value="BouncyCastle.org" />
                <attribute name="Implementation-Version" value="${release.name}.0" />
                <attribute name="Application-Name" value="Bouncy Castle Provider" />
                <attribute name="Trusted-Library" value="true" />
                <attribute name="Permissions" value="all-permissions" />
                <attribute name="Codebase" value="*" />
                <attribute name="Application-Library-Allowable-Codebase" value="*" />
                <attribute name="Caller-Allowable-Codebase" value="*" />
            </manifestElements>
        </compile>

        <packJar jarbase="${artifacts.jars.dir}/${extprovider}">
            <manifest-element>
                <manifest>
                    <attribute name="Manifest-Version" value="1.0" />
                    <attribute name="Extension-Name" value="org.bouncycastle.bcproviderext" />
                    <attribute name="Specification-Vendor" value="BouncyCastle.org" />
                    <attribute name="Specification-Version" value="1.1" />
                    <attribute name="Implementation-Vendor-Id" value="org.bouncycastle" />
                    <attribute name="Implementation-Vendor" value="BouncyCastle.org" />
                    <attribute name="Implementation-Version" value="${release.version}.0" />
                    <attribute name="Application-Name" value="Bouncy Castle Provider" />
                    <attribute name="Trusted-Library" value="true" />
                    <attribute name="Permissions" value="all-permissions" />
                    <attribute name="Codebase" value="*" />
                    <attribute name="Application-Library-Allowable-Codebase" value="*" />
                    <attribute name="Caller-Allowable-Codebase" value="*" />
                </manifest>
            </manifest-element>
            <fileset-element>
                <fileset dir="${build.dir}/${provider}/classes">
                    <include name="**/*.class"/>
                    <exclude name="**/javax/crypto/**/*.class"/>
                    <include name="**/*.properties"/>
                </fileset>
            </fileset-element>
        </packJar>

    </target>

    <!--
          JCE
    -->
    <target name="build-jce" depends="initMacros">
        <property name="jce" value="jce-${target.name}" />
        <property name="extjce" value="jce-ext-${target.name}" />

        <mkdir dir="${artifacts.jars.dir}" />
        <delete dir="${jce.target.dir}" />
        <mkdir dir="${jce.target.dir}" />

        <copyStandardFiles toDir="${jce.target.dir}" />

        <copy todir="${jce.target.src.dir}">
             <fileset dir="${src.dir}">
                 <exclude name="PKITS/**" />
                 <exclude name="cmp/**" />
                 <exclude name="rfc4134/**" />
                 <exclude name="org/bouncycastle/**/AllTests.java" />
                 <exclude name="org/bouncycastle/**/test/**" />
                 <exclude name="org/bouncycastle/crypto/*/*Test.java" />
                 <exclude name="org/bouncycastle/util/*Test.java" />
                 <exclude name="**/*.crl" />
                 <exclude name="org/bouncycastle/**/test/*.crt" />
                 <exclude name="org/bouncycastle/**/test/*.cer" />
                 <exclude name="org/bouncycastle/**/test/*.csr" />
                 <exclude name="org/bouncycastle/**/test/*.cvcert" />
                 <exclude name="org/bouncycastle/**/test/*.eml" />
                 <exclude name="org/bouncycastle/**/test/*.sig" />
                 <exclude name="org/bouncycastle/**/test/*.data" />
                 <exclude name="org/bouncycastle/**/test/*.der" />
                 <exclude name="org/bouncycastle/**/test/*.properties" />
                 <exclude name="org/bouncycastle/util/utiltest/**" />
                 <exclude name="org/bouncycastle/mail/**" />
                 <exclude name="org/bouncycastle/cms/**" />
                 <exclude name="org/bouncycastle/dvcs/**" />
                 <exclude name="org/bouncycastle/eac/**" />
                 <exclude name="org/bouncycastle/cert/**" />
                 <exclude name="org/bouncycastle/pkcs/**" />
                 <exclude name="org/bouncycastle/operator/**" />
                 <exclude name="org/bouncycastle/sasn1/**" />
                 <exclude name="org/bouncycastle/tsp/**" />
                 <exclude name="org/bouncycastle/openpgp/**" />
                 <exclude name="org/bouncycastle/openssl/**" />
                 <exclude name="org/bouncycastle/mozilla/**" />
                 <exclude name="org/bouncycastle/bcpg/**" />
                 <exclude name="org/bouncycastle/voms/**" />
                 <exclude name="org/apache/**/*.java" />
             </fileset>
             <fileset dir="${src.dir}" includes="org/bouncycastle/util/test/*.java" />
        </copy>

        <compile target="${jce}">
            <jarFileSet>
                <include name="**/*.class"/>
                <exclude name="**/NTRU*.class" />
                <exclude name="**/ntru/**/*.class" />
                <include name="**/*.properties"/>
            </jarFileSet>
            <manifestElements>
                <attribute name="Manifest-Version" value="1.0" />
                <attribute name="Extension-Name" value="org.bouncycastle.bcjce" />
                <attribute name="Specification-Vendor" value="BouncyCastle.org" />
                <attribute name="Specification-Version" value="1.1" />
                <attribute name="Implementation-Vendor-Id" value="org.bouncycastle" />
                <attribute name="Implementation-Vendor" value="BouncyCastle.org" />
                <attribute name="Implementation-Version" value="${release.version}.0" />
                <attribute name="Application-Name" value="Bouncy Castle JCE and Provider" />
                <attribute name="Trusted-Library" value="true" /> 
                <attribute name="Permissions" value="all-permissions" />
                <attribute name="Codebase" value="*" />
                <attribute name="Application-Library-Allowable-Codebase" value="*" />
                <attribute name="Caller-Allowable-Codebase" value="*" />
            </manifestElements>
        </compile>

        <packJar jarbase="${artifacts.jars.dir}/${extjce}">
            <manifest-element>
                <manifest>
                    <attribute name="Manifest-Version" value="1.0" />
                    <attribute name="Extension-Name" value="org.bouncycastle.bcjceext" />
                    <attribute name="Specification-Vendor" value="BouncyCastle.org" />
                    <attribute name="Specification-Version" value="1.1" />
                    <attribute name="Implementation-Vendor-Id" value="org.bouncycastle" />
                    <attribute name="Implementation-Vendor" value="BouncyCastle.org" />
                    <attribute name="Implementation-Version" value="${release.version}.0" />
                    <attribute name="Application-Name" value="Bouncy Castle JCE and Provider" />
                    <attribute name="Trusted-Library" value="true" />
                    <attribute name="Permissions" value="all-permissions" />
                    <attribute name="Codebase" value="*" />
                    <attribute name="Application-Library-Allowable-Codebase" value="*" />
                    <attribute name="Caller-Allowable-Codebase" value="*" />
                </manifest>
            </manifest-element>
            <fileset-element>
                <fileset dir="${build.dir}/${jce}/classes">
                    <include name="**/*.class"/>
                    <include name="**/*.properties"/>
                </fileset>
            </fileset-element>
        </packJar>
    </target>

    <target name="build-libraries" depends="initMacros, build-pkix, build-pg, build-mail" />

    <!--
          SMIME
    -->
    <target name="build-mail" depends="initMacros">
        <mkdir dir="${mail.target.dir}" />

        <copyStandardFiles toDir="${mail.target.dir}" />

        <copy todir="${mail.target.src.dir}">
             <fileset dir="${src.dir}">
                 <include name="org/bouncycastle/mail/**/*.java" />
                 <include name="org/bouncycastle/mail/**/*.properties" />
                 <exclude name="**/*Test.java" />
                 <exclude name="**/*Tests.java" />
                 <exclude name="**/test/*.java" />
             </fileset>
        </copy>

        <compile target="${mail.target}">
            <jarFileSet>
                <include name="**/*.class"/>
                <include name="**/*.properties"/>
            </jarFileSet>
            <manifestElements>
                <attribute name="Manifest-Version" value="1.0" />
                <attribute name="Extension-Name" value="org.bouncycastle.bcmail" />
                <attribute name="Specification-Vendor" value="BouncyCastle.org" />
                <attribute name="Specification-Version" value="1.1" />
                <attribute name="Implementation-Vendor-Id" value="org.bouncycastle" />
                <attribute name="Implementation-Vendor" value="BouncyCastle.org" />
                <attribute name="Implementation-Version" value="${release.version}.0" />
                <attribute name="Application-Name" value="Bouncy Castle S/MIME API" />
                <attribute name="Trusted-Library" value="true" />
                <attribute name="Permissions" value="all-permissions" />
                <attribute name="Codebase" value="*" />
                <attribute name="Application-Library-Allowable-Codebase" value="*" />
                <attribute name="Caller-Allowable-Codebase" value="*" />
            </manifestElements>
        </compile>

    </target>

    <target name="build-pkix" depends="initMacros">
        <mkdir dir="${pkix.target.dir}" />

        <copyStandardFiles toDir="${pkix.target.dir}" />

        <copy todir="${pkix.target.src.dir}">
             <fileset dir="${src.dir}">
                 <include name="org/bouncycastle/cms/**/*.java" />
                 <include name="org/bouncycastle/dvcs/**/*.java" />
                 <include name="org/bouncycastle/eac/**/*.java" />
                 <include name="org/bouncycastle/cert/**/*.java" />
                 <include name="org/bouncycastle/mozilla/**/*.java" />
                 <include name="org/bouncycastle/openssl/**/*.java" />
                 <include name="org/bouncycastle/operator/**/*.java" />
                 <include name="org/bouncycastle/pkcs/**/*.java" />
                 <include name="org/bouncycastle/tsp/**/*.java" />
                 <include name="org/bouncycastle/voms/**/*.java" />
                 <exclude name="**/*Test.java" />
                 <exclude name="**/*Tests.java" />
                 <exclude name="**/test/*.*" />
                 <exclude name="**/test/**.*" />
             </fileset>
        </copy>

        <compile target="${pkix.target}">
            <jarFileSet>
                <include name="**/*.class"/>
                <include name="**/*.properties"/>
            </jarFileSet>
            <manifestElements>
                <attribute name="Manifest-Version" value="1.0" />
                <attribute name="Extension-Name" value="org.bouncycastle.bcpkix" />
                <attribute name="Specification-Vendor" value="BouncyCastle.org" />
                <attribute name="Specification-Version" value="1.1" />
                <attribute name="Implementation-Vendor-Id" value="org.bouncycastle" />
                <attribute name="Implementation-Vendor" value="BouncyCastle.org" />
                <attribute name="Implementation-Version" value="${release.version}.0" />
                <attribute name="Application-Name" value="Bouncy Castle PKIX API" />
                <attribute name="Trusted-Library" value="true" />
                <attribute name="Permissions" value="all-permissions" />
                <attribute name="Codebase" value="*" />
                <attribute name="Application-Library-Allowable-Codebase" value="*" />
                <attribute name="Caller-Allowable-Codebase" value="*" />
            </manifestElements>
        </compile>

    </target>

    <!--
          PG
    -->
    <target name="build-pg" depends="initMacros">
        <mkdir dir="${pg.target.dir}" />

        <filter token="RELEASE_NAME" value="${release.name}" />

        <copyStandardFiles toDir="${pg.target.dir}" />

        <copy todir="${pg.target.src.dir}" filtering="true">
             <fileset dir="${src.dir}" includes="org/bouncycastle/bcpg/**/*.java" />
        </copy>

        <copy todir="${pg.target.src.dir}">
             <fileset dir="${src.dir}">
                 <include name="org/bouncycastle/openpgp/**/*.java" />
                 <exclude name="**/*Test.java" />
                 <exclude name="**/*Tests.java" />
                 <exclude name="**/test/*.java" />
             </fileset>
        </copy>

        <compile target="${pg.target}">
            <jarFileSet>
                <include name="**/*.class"/>
                <include name="**/*.properties"/>
            </jarFileSet>
            <manifestElements>
                <attribute name="Manifest-Version" value="1.0" />
                <attribute name="Extension-Name" value="org.bouncycastle.bcpg" />
                <attribute name="Specification-Vendor" value="BouncyCastle.org" />
                <attribute name="Specification-Version" value="1.1" />
                <attribute name="Implementation-Vendor-Id" value="org.bouncycastle" />
                <attribute name="Implementation-Vendor" value="BouncyCastle.org" />
                <attribute name="Implementation-Version" value="${release.version}.0" />
                <attribute name="Application-Name" value="Bouncy Castle OpenPGP API" />
                <attribute name="Trusted-Library" value="true" /> 
                <attribute name="Permissions" value="all-permissions" />
                <attribute name="Codebase" value="*" />
                <attribute name="Application-Library-Allowable-Codebase" value="*" />
                <attribute name="Caller-Allowable-Codebase" value="*" />
            </manifestElements>
        </compile>

    </target>

    <!--
         Tests
    -->
    <target name="build-test" depends="initMacros">
        <property name="test.target" value="bctest-${target.name}" />

        <mkdir dir="${artifacts.jars.dir}" />

        <property name="test.target.dir" value="${artifacts.dir}/${test.target}" />
        <property name="test.target.src.dir" value="${test.target.dir}/src" />

        <mkdir dir="${test.target.dir}" />

        <copyStandardFiles toDir="${test.target.dir}" />

        <copy todir="${test.target.src.dir}">
             <fileset dir="${src.dir}" includes="**/*AllTests.java" />
             <fileset dir="${src.dir}" includes="**/math/**/*Test.java" />
             <fileset dir="${src.dir}" includes="**/crypto/*/*Test.java" />
             <fileset dir="${src.dir}" includes="**/utiltest/*Test.java" />
             <fileset dir="${src.dir}" includes="**/util/io/pem/*Test.java" />
             <fileset dir="${src.dir}" includes="**/test/*.java" />
             <fileset dir="${src.dir}" includes="**/test/*/*.java" />
             <fileset dir="${src.dir}" includes="**/*.asc" />
             <fileset dir="${src.dir}" includes="**/*.pem" />
             <fileset dir="${src.dir}" includes="**/*.p7m" />
             <fileset dir="${src.dir}" includes="**/*.eml" />
             <fileset dir="${src.dir}" includes="**/*.sig" />
             <fileset dir="${src.dir}" includes="**/*.data" />
             <fileset dir="${src.dir}" includes="**/*.der" />
             <fileset dir="${src.dir}" includes="**/*.crt" />
             <fileset dir="${src.dir}" includes="**/*.cer" />
             <fileset dir="${src.dir}" includes="**/*.crl" />
             <fileset dir="${src.dir}" includes="**/*.csr" />
             <fileset dir="${src.dir}" includes="**/*.txt" />
             <fileset dir="${src.dir}" includes="**/*.rsp" />
             <fileset dir="${src.dir}" includes="**/*.cvcert" />
             <fileset dir="${src.dir}" includes="**/*.properties" />
             <fileset dir="${src.dir}" includes="**/*.message" />
        </copy>

        <compile-test target="${test.target}">
            <manifestElements>
                <attribute name="Manifest-Version" value="1.0" />
                <attribute name="Extension-Name" value="org.bouncycastle.bctest" />
                <attribute name="Specification-Vendor" value="BouncyCastle.org" />
                <attribute name="Specification-Version" value="1.1" />
                <attribute name="Implementation-Vendor-Id" value="org.bouncycastle" />
                <attribute name="Implementation-Vendor" value="BouncyCastle.org" />
                <attribute name="Implementation-Version" value="${release.version}.0" />
                <attribute name="Application-Name" value="Bouncy Castle Test Classes" />
                <attribute name="Trusted-Library" value="true" />
                <attribute name="Permissions" value="all-permissions" />
                <attribute name="Codebase" value="*" />
                <attribute name="Application-Library-Allowable-Codebase" value="*" />
                <attribute name="Caller-Allowable-Codebase" value="*" />
            </manifestElements>
        </compile-test>
    </target>

    <target name="test">
        <mkdir dir="${basedir}/${build.dir}/${target.prefix}" />
        <junit fork="yes" dir="${basedir}/${build.dir}/${target.prefix}" failureProperty="test.failed">
            <classpath>
                <path refid="project.classpath" /> 
                <fileset dir="${artifacts.jars.dir}">
                    <include name="**/*.jar" />
                    <exclude name="**/bcprov-jdk*.jar" />
                </fileset>
            </classpath>
            <sysproperty key="bc.test.data.home" value="../../core/src/test/data" />

            <formatter type="xml" />
            <test name="${testcase}" todir="${artifacts.reports.xml.dir}" if="testcase" />
            <batchtest todir="${artifacts.reports.xml.dir}" unless="testcase">
                <fileset dir="${src.dir}">
                    <include name="**/AllTests.java" />
                    <include name="**/nist/Nist*Test.java" />
                    <include name="**/rsa3/RSA3CertTest.java" />
                </fileset>
            </batchtest>
        </junit>

        <junitreport todir="${artifacts.reports.xml.dir}">
            <fileset dir="${artifacts.reports.xml.dir}">
                <include name="TEST-*.xml" />
            </fileset>
            <report format="frames" todir="${artifacts.reports.html.dir}" />
        </junitreport>
    </target>

    <target name="test-lw">
        <junit fork="yes" dir="${basedir}/${build.dir}/${target.prefix}" failureProperty="test.failed">
            <classpath>
                <fileset dir="${artifacts.jars.dir}">
                    <include name="**/*.jar" />
                    <exclude name="**/bcprov-jdk*.jar" />
                </fileset>
            </classpath>

            <formatter type="xml" />
            <test name="${testcase}" todir="${artifacts.reports.xml.dir}" if="testcase" />
            <batchtest todir="${artifacts.reports.xml.dir}" unless="testcase">
                <fileset dir="${src.dir}">
                    <include name="**/crypto/test/AllTests.java" />
                    <include name="**/asn1/test/AllTests.java" />
                    <include name="**/encoders/test/AllTests.java" />
                    <include name="**/ntru/**/AllTests.java" />
                </fileset>
            </batchtest>
        </junit>

        <junitreport todir="${artifacts.reports.xml.dir}">
            <fileset dir="${artifacts.reports.xml.dir}">
                <include name="TEST-*.xml" />
            </fileset>
            <report format="frames" todir="${artifacts.reports.html.dir}" />
        </junitreport>
    </target>

    <target name="javadoc-libraries" depends="javadoc-pkix, javadoc-mail, javadoc-pg" />

    <!--
          Provider JavaDoc
    -->
    <target name="javadoc-provider" depends="initMacros">
        <copy todir="${provider.target.src.dir}">
             <fileset dir="${src.dir}">
                 <include name="org/bouncycastle/pqc/**/test/*.java" />
                 <include name="org/bouncycastle/jce/**/test/*.java" />
                 <include name="org/bouncycastle/jce/**/test/*/*.java" />
                 <include name="org/bouncycastle/x509/**/test/*.java" />
                 <include name="org/bouncycastle/ocsp/**/test/*.java" />
                 <include name="org/bouncycastle/crypto/**/test/*.java" />
                 <include name="org/bouncycastle/asn1/**/test/*.java" />
                 <include name="org/bouncycastle/crypto/**/*.html" />
                 <include name="org/bouncycastle/math/**/*.html" />
                 <include name="org/bouncycastle/asn1/**/*.html" />
                 <include name="org/bouncycastle/pqc/**/*.html" />
                 <include name="org/bouncycastle/util/**/*.html" />
             </fileset>
        </copy>

        <compile-doc srcDir="${provider.target.src.dir}" docsDir="${artifacts.docs.dir}/bcprov">
            <docElements>
                <package name="org.bouncycastle.asn1.*" />
                <package name="org.bouncycastle.crypto.*" />
                <package name="org.bouncycastle.jce.*" />
                <package name="org.bouncycastle.jcajce.*" />
                <package name="org.bouncycastle.math.*" />
                <package name="org.bouncycastle.pqc.*" />
                <package name="org.bouncycastle.util.*" />
                <group title="ASN.1 Support Packages" packages="org.bouncycastle.asn1*" />
                <group title="JCA/JCE Provider" packages="org.bouncycastle.jce.provider*,org.bouncycastle.jcajce.provider*" />
                <group title="JCA/JCE Utility and Extension Packages" packages="org.bouncycastle.jce*,org.bouncycastle.jcajce*" />
                <group title="Lightweight Crypto Packages" packages="org.bouncycastle.crypto*" />
                <group title="Math and Utility Packages" packages="org.bouncycastle.util*:org.bouncycastle.math*" />
                <group title="Test Packages" packages="org.bouncycastle.crypto.test*,org.bouncycastle.util.utiltest,org.bouncycastle.asn1.test*,org.bouncycastle.util.encoders.test*,org.bouncycastle.util.io.test*,org.bouncycastle.util.io.pem.test*,org.bouncycastle.math.ec.test*,org.bouncycastle.crypto.ec.test*,org.bouncycastle.crypto.prng.test*,org.bouncycastle.crypto.tls.test*,org.bouncycastle.crypto.agreement.test*,org.bouncycastle.jce.provider.test*" />
                <group title="Post-Quantum Lightweight Crypto Packages" packages="org.bouncycastle.pqc.crypto*" />
                <group title="Post-Quantum ASN.1 Packages" packages="org.bouncycastle.pqc.asn1*" />
                <group title="Post-Quantum Lightweight Math Packages" packages="org.bouncycastle.pqc.math*" />
                <group title="Post-Quantum Provider" packages="org.bouncycastle.pqc.jcajce.*" />
                <group title="Post-Quantum Test Packages" packages="org.bouncycastle.pqc.crypto.test*,org.bouncycastle.pqc.math.ntru.util.test*,org.bouncycastle.pqc.math.ntru.polynomial.test*,org.bouncycastle.pqc.jcajce.provider.test*,org.bouncycastle.pqc.math.ntru.euclid.test*" />
            </docElements>
        </compile-doc>

        <copy todir="${provider.target.docs.dir}">
             <fileset dir="${artifacts.docs.dir}/bcprov" />
        </copy>
    </target>

    <target name="javadoc-jce" depends="initMacros">
        <copy todir="${jce.target.src.dir}">
             <fileset dir="${src.dir}">
                 <include name="org/bouncycastle/jce/**/test/*.java" />
                 <include name="org/bouncycastle/jce/**/test/*/*.java" />
                 <include name="org/bouncycastle/x509/**/test/*.java" />
                 <include name="org/bouncycastle/ocsp/**/test/*.java" />
             </fileset>
        </copy>

        <compile-doc srcDir="${jce.target.src.dir}" docsDir="${artifacts.docs.dir}/jce">
            <docElements>
                <package name="org.bouncycastle.asn1.*" />
                <package name="org.bouncycastle.crypto.*" />
                <package name="org.bouncycastle.jce.*" />
                <package name="org.bouncycastle.jcajce.*" />
                <package name="org.bouncycastle.x509.*" />
                <package name="org.bouncycastle.ocsp.*" />
                <package name="org.bouncycastle.util.*" />
                <package name="javax.crypto.*" />
                <group title="JCE Package" packages="javax.crypto*" />
                <group title="JCE Utility and Extension Packages" packages="org.bouncycastle.jce*,org.bouncycastle.jcajce*" />
                <group title="OCSP Support Packages" packages="org.bouncycastle.ocsp*" />
                <group title="ASN.1 Support Packages" packages="org.bouncycastle.asn1*" />
                <group title="Lightweight Crypto Packages" packages="org.bouncycastle.crypto*" />
                <group title="Utility Packages" packages="org.bouncycastle.util*:org.bouncycastle.math*" />
                <group title="JCE Provider and Test Classes" packages="org.bouncycastle.jce.provider*,org.bouncycastle.jcajce.provider*" />
            </docElements>
        </compile-doc>

        <copy todir="${jce.target.docs.dir}">
             <fileset dir="${artifacts.docs.dir}/jce" />
        </copy>
    </target>

    <!--
          Mail JavaDoc
    -->
    <target name="javadoc-mail" depends="initMacros">
        <copy todir="${mail.target.src.dir}">
             <fileset dir="${src.dir}">
                 <include name="org/bouncycastle/mail/**/test/*.java" />
                 <include name="org/bouncycastle/mail/**/*.html" />
             </fileset>
        </copy>

        <compile-doc srcDir="${mail.target.src.dir}" docsDir="${artifacts.docs.dir}/bcmail">
            <docElements>
                <package name="org.bouncycastle.mail.*" />
                <group title="S/MIME Packages" packages="org.bouncycastle.mail.smime*" />
            </docElements>
        </compile-doc>

        <copy todir="${mail.target.docs.dir}">
             <fileset dir="${artifacts.docs.dir}/bcmail" />
        </copy>
    </target>

    <!--
          PKIX JavaDoc
    -->
    <target name="javadoc-pkix" depends="initMacros">
        <copy todir="${pkix.target.src.dir}">
             <fileset dir="${src.dir}">
                 <include name="org/bouncycastle/cms/**/test/*.java" />
                 <include name="org/bouncycastle/dvcs/**/test/*.java" />
                 <include name="org/bouncycastle/eac/**/test/*.java" />
                 <include name="org/bouncycastle/cert/**/test/*.java" />
                 <include name="org/bouncycastle/pkcs/**/test/*.java" />
                 <include name="org/bouncycastle/openssl/**/test/*.java" />
                 <include name="org/bouncycastle/mozilla/**/test/*.java" />
                 <include name="org/bouncycastle/operator/**/test/*.java" />
                 <include name="org/bouncycastle/cms/**/*.html" />
                 <include name="org/bouncycastle/dvcs/**/*.html" />
                 <include name="org/bouncycastle/eac/**/*.html" />
                 <include name="org/bouncycastle/cert/**/*.html" />
                 <include name="org/bouncycastle/pkcs/**/*.html" />
                 <include name="org/bouncycastle/openssl/**/*.html" />
                 <include name="org/bouncycastle/operator/**/*.html" />
                 <include name="org/bouncycastle/mozilla/**/*.html" />
                 <include name="org/bouncycastle/tsp/**/test/*.java" />
                 <include name="org/bouncycastle/tsp/**/*.html" />
             </fileset>
        </copy>

        <compile-doc srcDir="${pkix.target.src.dir}" docsDir="${artifacts.docs.dir}/bcpkix">
            <docElements>
                <package name="org.bouncycastle.cms.*" />
                <package name="org.bouncycastle.dvcs.*" />
                <package name="org.bouncycastle.eac.*" />
                <package name="org.bouncycastle.cert.*" />
                <package name="org.bouncycastle.pkcs.*" />
                <package name="org.bouncycastle.openssl.*" />
                <package name="org.bouncycastle.operator.*" />
                <package name="org.bouncycastle.mozilla.*" />
                <package name="org.bouncycastle.tsp.*" />
                <group title="Certificate Packages" packages="org.bouncycastle.cert*,org.bouncycastle.mozilla*" />
                <group title="Cryptographic Operators" packages="org.bouncycastle.operator*" />
                <group title="CMS Packages" packages="org.bouncycastle.cms*" />
                <group title="DVCS Packages" packages="org.bouncycastle.dvcs*" />
                <group title="Extended Access Control Packages" packages="org.bouncycastle.eac*" />
                <group title="PKCS Packages" packages="org.bouncycastle.pkcs*" />
                <group title="OpenSSL and PEM Support Packages" packages="org.bouncycastle.openssl*" />
                <group title="TSP Packages" packages="org.bouncycastle.tsp*" />
                <group title="Test and Example Packages" packages="org.bouncycastle.openssl.test*,org.bouncycastle.mozilla.test*,org.bouncycastle.pkcs.test*,org.bouncycastle.cert.test*,org.bouncycastle.cert.path.test*,org.bouncycastle.cert.ocsp.test*,org.bouncycastle.cert.crmf.test*,org.bouncycastle.cert.cmp.test*,org.bouncycastle.eac.test*,org.bouncycastle.dvcs.test*,org.bouncycastle.cms.test*,org.bouncycastle.tsp.test*" />
            </docElements>
        </compile-doc>

        <copy todir="${pkix.target.docs.dir}">
             <fileset dir="${artifacts.docs.dir}/bcpkix" />
        </copy>
    </target>

    <!--
          PG JavaDoc
    -->
    <target name="javadoc-pg" depends="initMacros">
        <copy todir="${pg.target.src.dir}">
             <fileset dir="${src.dir}">
                 <include name="org/bouncycastle/openpgp/**/test/*.java" />
                 <include name="org/bouncycastle/bcpg/**/test/*.java" />
                 <include name="org/bouncycastle/openpgp/**/*.html" />
                 <include name="org/bouncycastle/bcpg/**/*.html" />
             </fileset>
        </copy>

        <compile-doc srcDir="${pg.target.src.dir}" docsDir="${artifacts.docs.dir}/bcpg">
            <docElements>
                <package name="org.bouncycastle.openpgp.*" />
                <package name="org.bouncycastle.bcpg.*" />
                <group title="BCPG Support Packages" packages="org.bouncycastle.bcpg*" />
                <group title="OpenPGP Packages" packages="org.bouncycastle.openpgp*" />
                <group title="OpenPGP Test and Example Packages" packages="org.bouncycastle.openpgp.test*,org.bouncycastle.openpgp.examples*" />
            </docElements>
        </compile-doc>

        <copy todir="${pg.target.docs.dir}">
             <fileset dir="${artifacts.docs.dir}/bcpg" />
       </copy>
    </target>

    <!--
          Light Weight JavaDoc
    -->
    <target name="javadoc-lw" depends="initMacros">
        <copy todir="${lcrypto.target.src.dir}">
             <fileset dir="${src.dir}">
                 <include name="org/bouncycastle/crypto/**/test/*.java" />
                 <include name="org/bouncycastle/asn1/**/test/*.java" />
                 <include name="org/bouncycastle/crypto/**/*.html" />
                 <include name="org/bouncycastle/math/**/*.html" />
                 <include name="org/bouncycastle/asn1/**/*.html" />
                 <include name="org/bouncycastle/pqc/**/*.html" />
                 <include name="org/bouncycastle/util/**/*.html" />
             </fileset>
        </copy>

        <compile-doc srcDir="${lcrypto.target.src.dir}" docsDir="${artifacts.docs.dir}/lcrypto">
            <docElements>
                <package name="org.bouncycastle.asn1.*" />
                <package name="org.bouncycastle.crypto.*" />
                <package name="org.bouncycastle.pqc.math.*" />
                <package name="org.bouncycastle.pqc.crypto.*" />
                <package name="org.bouncycastle.pqc.asn1.*" />
                <package name="org.bouncycastle.math.*" />
                <package name="org.bouncycastle.util.*" />
                <group title="Lightweight Crypto Packages" packages="org.bouncycastle.crypto*" />
                <group title="ASN.1 Support Packages" packages="org.bouncycastle.asn1*" />
                <group title="Utility Packages" packages="org.bouncycastle.util*:org.bouncycastle.math*" />
                <group title="Test Packages" packages="org.bouncycastle.crypto.test*,org.bouncycastle.util.utiltest,org.bouncycastle.asn1.test*,org.bouncycastle.util.encoders.test*,org.bouncycastle.util.io.test*,org.bouncycastle.util.io.pem.test*,org.bouncycastle.math.ec.test*,org.bouncycastle.crypto.ec.test*,org.bouncycastle.crypto.prng.test*,org.bouncycastle.crypto.tls.test*,org.bouncycastle.crypto.agreement.test*" />
                <group title="Post-Quantum Lightweight Crypto Packages" packages="org.bouncycastle.pqc.crypto*" />
                <group title="Post-Quantum Lightweight Math Packages" packages="org.bouncycastle.pqc.math*" />
                <group title="Post-Quantum ASN.1 Packages" packages="org.bouncycastle.pqc.asn1*" />
                <group title="Post-Quantum Test Packages" packages="org.bouncycastle.pqc.crypto.test*,org.bouncycastle.pqc.math.ntru.util.test*,org.bouncycastle.pqc.math.ntru.polynomial.test*,org.bouncycastle.pqc.math.ntru.euclid.test*" />
            </docElements>
        </compile-doc>

        <copy todir="${lcrypto.target.docs.dir}">
             <fileset dir="${artifacts.docs.dir}/lcrypto" />
       </copy>
    </target>

    <!--
        jar up the source directories
    -->
    <target name="zip-src" depends="zip-src-check, zip-src-jce, zip-src-jce-ext, zip-src-provider, zip-src-provider-ext">
        <zip basedir="${mail.target.src.dir}" destfile="${mail.target.src.zip}" />
        <delete dir="${mail.target.src.dir}" />
        <zip basedir="${pkix.target.src.dir}" destfile="${pkix.target.src.zip}" />
        <delete dir="${pkix.target.src.dir}" />
        <zip basedir="${pg.target.src.dir}" destfile="${pg.target.src.zip}" />
        <delete dir="${pg.target.src.dir}" />
    </target>

    <target name="zip-src-jce" if="jce.present">
        <zip basedir="${jce.target.src.dir}" destfile="${jce.target.src.zip}">
            <exclude name="**/NTRU*.java" />
            <exclude name="**/ntru/**/*.java" />
        </zip>
    </target>

    <target name="zip-src-provider" if="provider.present">
        <zip basedir="${provider.target.src.dir}" destfile="${provider.target.src.zip}">
            <exclude name="**/javax/crypto/**/*.java"/>
            <exclude name="**/NTRU*.java" />
            <exclude name="**/ntru/**/*.java" />
        </zip>
    </target>

    <target name="zip-src-jce-ext" if="jce.present">
        <zip basedir="${jce.target.src.dir}" destfile="${jce.target.src.zip}">
        </zip>
        <delete dir="${jce.target.src.dir}" />
    </target>

    <target name="zip-src-provider-ext" if="provider.present">
        <zip basedir="${provider.target.src.dir}" destfile="${provider.target.src.zip}">
                <exclude name="**/javax/crypto/**/*.java"/>
        </zip>
        <delete dir="${provider.target.src.dir}" />
    </target>

    <target name="zip-src-check">
        <available property="jce.present" file="${jce.target.src.dir}" />
        <available property="provider.present" file="${provider.target.src.dir}" />
    </target>
</project>

