<!--
   Build script for the project "Crypto.RSA".

   This script is an Ant script using Ivy extension to resolve dependencies.
   You will need both Ant (http://ant.apache.org/) and Ivy (http://ant.apache.org/ivy) to use it.
-->
<project name="crypto.rsa" default="package" xmlns:ivy="antlib:org.apache.ivy.ant">

    <!-- ==================== -->
    <!-- Settings -->
    <!-- ==================== -->

    <!-- default properties, specific to this project -->
    <property file="local.properties"/>
    <property file="build.properties"/>
    <!-- properties common to all projects -->
    <property file="../../local.properties"/>
    <property file="../../common.properties"/>


    <!-- ==================== -->
    <!-- Main targets : they are greatly inspired from the Maven build lifecycle -->
    <!-- ==================== -->

    <target name="validate" description="Validates the project is correct and all necessary information is available.">
        <!-- Retreives dependencies with ivy -->
        <ivy:retrieve/>
        <!-- Creates necessary directories -->
        <mkdir dir="${target.dir}" />
    </target>
    
    <target name="compile" depends="validate" description="Compiles the source code of the project.">
        <!-- nothing to do -->
    </target>
    
    <target name="test" depends="compile" description="Tests the compiled source code using a suitable unit testing framework. These tests should not require the code be packaged or deployed.">
        <!-- nothing to do -->
    </target>
    
    <target name="package" depends="test, doc, build-default, build-compressed" description="Takes the compiled code and package it in its distributable format, such as a JAR.">
        <!-- nothing more to do -->
    </target>
    
    <target name="integration-test" depends="package" description="Processes and deploys the package if necessary into an environment where integration tests can be run.">
        <!-- nothing to do -->
    </target>
    
    <target name="verify" depends="integration-test" description="Runs any checks to verify the package is valid and meets quality criteria.">
        <!-- nothing to do -->
    </target>
    
    <target name="install" depends="verify" description="Installs the package into the local repository, for use as a dependency in other projects locally.">
        <ivy:publish resolver="local" artifactspattern="${lib.dir}/[artifact]-[revision].[ext]" overwrite="true" />
    </target>
    
    <target name="deploy" depends="verify" description="Done in an integration or release environment, copies the final package to the remote repository for sharing with other developers and projects.">
        <!-- nothing to do -->
    </target>
    

    <!-- ==================== -->
    <!-- Some more specific targets -->
    <!-- ==================== -->

    <target name="doc" depends="validate" description="Generates developer documentation.">
        <!-- Generates a report of dependencies -->
        <ivy:report todir="${doc.dir}"/>
        <!-- Generates the API doc -->
        <exec command="${jsdoc}" failonerror="true">
            <arg value="-d"/> <arg value="${doc.dir}"/>
            <arg value="--no-lexical-privates"/>
            <arg value="--package-naming"/>
            <arg value="--nested-file-naming"/>
            <arg line="--project-name Crypto.RSA"/>
            <arg value="${src.dir}"/>
        </exec>
    </target>

    <target name="build-default" depends="validate" description="Builds the default package.">
        <copy file="${src.dir}/rsa.js" tofile="${lib.dir}/rsa-${ivy.revision}.js" />
    </target>

    <target name="build-compressed" depends="validate" description="Builds the compressed version of the package.">
        <java jar="${yuicompressor.jar}" fork="true" output="${lib.dir}/rsa-compressed-${ivy.revision}.js" failonerror="true">
            <arg line="--type js" />
            <arg file="${src.dir}/rsa.js"/>
        </java>
    </target>

    <target name="clean" description="Cleans this project.">
        <delete includeemptydirs="true" dir="${target.dir}"/>
    </target>


    <!-- ==================== -->
    <!-- CruiseControl targets -->
    <!-- ==================== -->
    
    <target name="cruisecontrol-build" depends="verify">
    </target>

</project>
