<!-- Flex Library Project ASDocs -->

<project name="AS3SDKCompile" default="compile" basedir=".">

    <!-- import our build properties file -->
    <property file="./build.properties"/>
    <property environment="env"/>
    <property name="FLEX_HOME" value="${FLEX4_SDK_HOME}"/>
    <property name="FLEX4_HOME" value="${FLEX4_SDK_HOME}"/>

    <!--<property name="flexunit.swc" value="../lib/ext/flexunit-4.1.0_RC2-28-flex_3.5.0.12683.swc" />
    <property name="flexunit-uilistener.swc" value="../lib/ext/flexunit-uilistener-4.1.0_RC2-28-flex_3.5.0.12683.swc" />
    <property name="flexunit-cilistener.swc" value="../lib/ext/flexunit-cilistener-4.1.0_RC2-28-flex_3.5.0.12683.swc" />-->

    <!-- Flex Ant Tasks used to perform compc and mxml compiling more info at http://labs.adobe.com/wiki/index.php/Flex_Ant_Tasks -->
    <taskdef resource="flexTasks.tasks" classpath="${FLEX_HOME}/ant/lib/flexTasks.jar"/>

    <target name="setup" description="perform an setup operations"/>

    <!-- Execute the ASDoc Compile wich runs 3 seperate tasks in a series -->
    <target name="compile" description="series of tasks to create docs and swc">

        <!--<antcall target="cleanDir" description="clean the docs directory"/>-->

        <!--<antcall target="asDocs" description="full build of asdocs"/>-->

        <antcall target="buildSWC" description="build the SWC file"/>

    </target>

    <target name="deploy" description="perform an deployment operations"/>

    <target name="install" description="perform an installation operations"/>

    <!--

    DELETE the existing output folder and files and then re-generate the output folder

    -->

    <target name="clean"
            description="DELETE the existing output folder and files and then re-generate the output folder">

        <delete dir="${basedir}/${docsoutputfolder}" failonerror="true" includeemptydirs="true"/>
        <delete file="${basedir}/${liboutputfolder}/${liboutputfile}"/>
        <delete dir="${basedir}/dist" failonerror="true" includeemptydirs="true"/>

        <mkdir dir="${basedir}/${docsoutputfolder}"/>

    </target>

    <!--

    Run the ASDoc executable and generate the ASDocs to the new output folder

    -->

    <target name="docs" description="Run the ASDoc executable and generate the ASDocs to the new output folder">

        <exec executable="${FLEX_HOME}/bin/asdoc" failonerror="true">

            <arg line="-doc-sources ${sourcepath}"/>
            <arg line="-source-path ${sourcepath}"/>
            <arg line="-footer 'Copyright Wordnik'"/>
            <arg line="-package io.swagger.api 'Contains the apis which are used by clients to make calls to the services deployed'"/>
            <arg line="-package io.swagger.codegen.model 'Contains common classes which encapsulate data elements required'"/>
            <arg line="-package io.swagger.common 'Contains classes which are used by the api classes to invoke the deployed api like SwaggerApi - a base class, ApiUserCredentials, etc.'"/>
            <arg line="-package io.swagger.event 'Results of calls made to Wordnik are returned via dispatched events. This package contains such event classes. Right now thats just ApiClientEvent and Response.'"/>
            <arg line="-package io.swagger.exception 'Contains classes that encapsulate the errors generated'"/>

            <arg value="-window-title"/>
            <arg value="${title}"/>

            <arg value="-main-title"/>
            <arg value="${title}"/>

            <arg value="-output"/>
            <arg value="${basedir}/${docsoutputfolder}"/>

            <arg value="-external-library-path"/>
            <arg value="${basedir}/${libpath}"/>

        </exec>

        <echo>docs created</echo>

    </target>

    <!--

    Compile the  SWC file library including lib folder and the path to our classes, we use compc for library,
     check the docs for Flex Ant Tasks, http://labs.adobe.com/wiki/index.php/Flex_Ant_Tasks.

    -->

    <target name="buildSWC" description="Compile the SWC file for the Librayr Project">

        <compc output="${basedir}/${liboutputfolder}/${liboutputfile}">

            <!--
                   Include the path to any external SWC files used in the sdk, you may have to place name of SWC (ASAXB-0.1.1.swc) at end of path.
                   So file path would be file="${basedir}/${libpath}/ASAXB-0.1.1.swc"
                -->
            <include-libraries file="${basedir}/${libpath}/"/>

            <source-path path-element="${sourcepath}"/>

            <keep-as3-metadata name="XmlRootNode"/>
            <keep-as3-metadata name="XmlElement"/>
            <keep-as3-metadata name="XmlElements"/>

            <!-- include our Class packages into the build (com folder) -->
            <include-sources dir="${sourcepath}" includes="*"/>

        </compc>

        <echo>SWC created</echo>

    </target>

    <target name="dist" depends="clean, buildSWC, docs">
        <mkdir dir="${basedir}/dist/lib"/>
        <mkdir dir="${basedir}/dist/docs"/>
        <mkdir dir="${basedir}/dist/sample"/>

        <copy file="${basedir}/${liboutputfolder}/${liboutputfile}" todir="${basedir}/dist/lib/">
        </copy>
        <copy todir="${basedir}/dist/docs/">
            <fileset dir="${basedir}/asdoc"/>
        </copy>


        <zip destfile="sample-as3-sdk.zip" basedir="${basedir}/dist"/>
    </target>

    <!-- Compiles and creates a test app that can be run using the adl - AIR Debug Launcher from command line
        Note: For the output file to be executed an xml file is needed which points to this output swf - this is not
        generated here
    -->
    <target name="compile-test" depends="buildSWC">
        <property name="FLEX_HOME" value="${FLEX4_SDK_HOME}"/>
        <mxmlc
                static-rsls="false"
                fork="true"
                maxmemory="512m"
                file="${testsourcepath}/AirExecutorApp.mxml"
                output="${basedir}/${liboutputfolder}/AirExecutorApp.swf"
                warnings="false"
                configname="air"
                locale="en_US">
            <load-config filename="${FLEX4_HOME}/frameworks/air-config.xml"/>
            <source-path path-element="${FLEX_HOME}/frameworks"/>

            <compiler.debug>true</compiler.debug>


            <source-path path-element="${testsourcepath}"/>
            <!--<source-path path-element="${APP_ROOT}/locale/{locale}" />-->

            <library-path dir="${FLEX_HOME}/frameworks/libs" append="true">
                <include name="*.swc"/>
            </library-path>
            <library-path dir="${FLEX_HOME}/frameworks/libs/air" append="true">
                <include name="*.swc"/>
            </library-path>
            <library-path dir="${FLEX_HOME}/frameworks/locale" append="true">
                <include name="{locale}"/>
            </library-path>
            <library-path dir="${basedir}/${libpath}" append="true">
                <include name="*.swc"/>
            </library-path>
            <library-path dir="${basedir}/${liboutputfolder}" append="true">
                <include name="*.swc"/>
            </library-path>
            <library-path dir="${basedir}/${libpath}/ext" append="true">
                <include name="*.swc"/>
            </library-path>

            <verbose-stacktraces>true</verbose-stacktraces>
        </mxmlc>
    </target>

    <target name="do-test">
        <exec executable="${FLEX_HOME}/bin/adl" failonerror="true">
            <arg value="${basedir}/bin/AirExecutorApp-app.xml"/>
        </exec>
    </target>

    <target name="test" depends="compile-test, do-test">
    </target>

</project>