<?xml version="1.0"?>
<!--

  Licensed to the Apache Software Foundation (ASF) under one or more
  contributor license agreements.  See the NOTICE file distributed with
  this work for additional information regarding copyright ownership.
  The ASF licenses this file to You under the Apache License, Version 2.0
  (the "License"); you may not use this file except in compliance with
  the License.  You may obtain a copy of the License at

      http://www.apache.org/licenses/LICENSE-2.0

  Unless required by applicable law or agreed to in writing, software
  distributed under the License is distributed on an "AS IS" BASIS,
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  See the License for the specific language governing permissions and
  limitations under the License.

-->

<project name="sdk" default="main" basedir=".">

    <property name="FLEX_HOME" location="${basedir}"/>
    
    <!-- Required for OSX 10.6 / Snow Leopard Performance. -->
    <!-- Java 7 on Mac requires OSX 10.7.3 or higher and is 64-bit only -->
    <!-- local.d32 is set/used in build.properties so this needs to be done first. -->
    <condition property="local.d32" value="-d32">
        <and>
            <os family="windows"/>
            <equals arg1="${sun.arch.data.model}" arg2="64"/>
            <equals arg1="${os.arch}" arg2="x86_64"/>
            <equals arg1="${ant.java.version}" arg2="1.6"/>
        </and>
    </condition>

    <property file="${FLEX_HOME}/env.properties"/>
    <property environment="env"/>
    <property file="${FLEX_HOME}/local.properties"/>
    <property file="${FLEX_HOME}/build.properties"/>

    <property name="debug" value="true"/>
    <property name="strict" value="true"/>
    <property name="javac.src" value="1.6"/>
    
    <property name="kit.prefix" value="feathers-sdk-${release.version.feathers}"/>
    <property name="source.kit" value="${kit.prefix}-src"/>
    <property name="binary.kit" value="${kit.prefix}-bin"/>

    <tstamp>
        <format property="build.number.date" pattern="yyyyMMdd" />
    </tstamp>
    <property name="build.version" value="${release.version.flex}.${build.number.date}" />
    
    <!--
        Notes: If you're running the main target, then there is no need to call clean first.
        Each of the main targets for the modules will call clean themselves before proceeding.
    -->

    <target name="main" depends="prebuild,modules,frameworks,post-build" description="Full build">
        <tstamp>
        	<format property="build.datetime" pattern="MM/dd/yyyy hh:mm:ss aa" />
        </tstamp>
        <echo>ant main target completed on ${build.datetime}</echo>
    </target>

    <target name="dev" depends="modules-dev" description="Runs src.depend build for development"/>

    <!-- 
        Can set build.additional-packages to build additional-packages as part of a release.
        This does not build the docs.  Use doc-packages or asdoc-packages.
    -->    
    <target name="release" 
        depends="check-compile-env,check-runtime-env,source-release,binary-release"
        description="Creates source and binary kits for Apache Flex."/>
        
    <target name="source-release"
        depends="super-clean,create-description,create-config,source-package" 
        description="Packages the source release kit which is the official Apache release."/>
        
    <target name="binary-release" 
        depends="setup-binary-release,main,doc,other.locales,binary-package,additional-packages" 
        description="Builds and packages the binary kit which is provided as a convenience."/>    

    <target name="source-release-noclean" 
        depends="create-description,create-config,source-package" 
        description="Packages the source release kit which is the official Apache release."/>
        
    <target name="binary-release-noclean" 
        depends="main,doc,other.locales,binary-package,additional-packages" 
        description="Builds and packages the binary kit which is provided as a convenience."/>    

    <target name="doc-packages" 
        depends="asdoc-package,javadocs"
        description="Build and package the asdocs for the framework clases and the javadocs."/>
                
    <target name="additional-packages"
        depends="antTasks-package" 
        description="Package antTasks."/>

    <target name="help">
        <echo message="run ant -projecthelp to see the available targets"/>
    </target>
    
    <!-- 
       To clean these you must call thirdparty-clean or super-clean to clean everything.  
       clean does not remove these since they don't change often and the downloads take time.
    -->
    <target name="thirdparty-downloads" description="Downloads all the required thirdparty code.">
        <ant dir="${basedir}/frameworks" target="thirdparty-downloads"/>        
        <ant dir="${basedir}/modules" target="thirdparty-downloads"/>
        <!-- don't ask again about these since we just did if these weren't already set -->	    
	    <property name="build.noprompt" value="set" />
    </target>

    <target name="prebuild" depends="check-compile-env,thirdparty-downloads,create-description" 
        description="Stuff that needs to be done before any builds." />

    <target name="check-compile-env" depends="check-playerglobal-home,check-air-home"
        description="Check for the required environment variables for compilation.">
            <echo>OS: ${os.name} / ${os.version} / ${os.arch}</echo>
            <echo>VM: ${java.vm.name} / ${java.vm.version}</echo>
            <echo>Java: ${java.version}</echo>
            <echo>Ant: ${ant.version} Ant Java Version: ${ant.java.version}</echo>
    </target>

    <target name="check-playerglobal-home" unless="playerglobal.swc.exists"
        description="Check PLAYERGLOBAL_HOME for both a directory and a swc file">

        <echo message="PLAYERGLOBAL_HOME is ${env.PLAYERGLOBAL_HOME}"/>
        <echo message="playerglobal.version is ${playerglobal.version}"/>

        <available file="${env.PLAYERGLOBAL_HOME}" 
            type="dir" 
            property="PLAYERGLOBAL_HOME.set"/>

        <fail message="The environment variable PLAYERGLOBAL_HOME is not set to a directory" 
            unless="PLAYERGLOBAL_HOME.set"/>

        <property name="playerglobal.swc" 
            value="${env.PLAYERGLOBAL_HOME}/${playerglobal.version}/playerglobal.swc"/>

        <available file="${playerglobal.swc}" 
            type="file" 
            property="playerglobal.swc.exists"/>
        
        <fail message="The file ${playerglobal.swc} does not exist" 
            unless="playerglobal.swc.exists"/>
            
        <echo message="playerglobal.swc is ${playerglobal.swc}"/>
    </target>
    
    <target name="check-air-home" unless="AIR_HOME.set"
        description="Check that AIR_HOME is a directory">
        
        <echo message="AIR_HOME is ${env.AIR_HOME}"/>

        <condition property="AIR_HOME.set">
            <and>
                <length string="${env.AIR_HOME}" when="greater" length="0" />
                <available file="${env.AIR_HOME}" type="dir"/>
                <!--available file="${env.AIR_HOME}/bin/adt" type="file"/-->
            </and>
        </condition>
        
        <fail message="The environment variable AIR_HOME must be set to the AIR SDK Kit directory" 
            unless="AIR_HOME.set"/>
    </target>

    <target name="create-description" description="Generate flex-sdk-description.xml">
        <echo message="build.number is ${build.number.date}"/>
        <echo file="${basedir}/flex-sdk-description.xml">&lt;?xml version="1.0"?&gt;
&lt;!--

  Licensed to the Apache Software Foundation (ASF) under one or more
  contributor license agreements.  See the NOTICE file distributed with
  this work for additional information regarding copyright ownership.
  The ASF licenses this file to You under the Apache License, Version 2.0
  (the "License"); you may not use this file except in compliance with
  the License.  You may obtain a copy of the License at

      http://www.apache.org/licenses/LICENSE-2.0

  Unless required by applicable law or agreed to in writing, software
  distributed under the License is distributed on an "AS IS" BASIS,
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  See the License for the specific language governing permissions and
  limitations under the License.

--&gt;
&lt;flex-sdk-description&gt;
&lt;name&gt;${release} FP${playerglobal.version} AIR${air.version} ${locale}&lt;/name&gt;
&lt;!-- for compatibility with Flash Builder, the version element needs to show
the version of Apache Flex that this SDK was forked from --&gt;
&lt;version&gt;${release.version.flex}&lt;/version&gt;
&lt;build&gt;${build.number.date}&lt;/build&gt;
&lt;/flex-sdk-description&gt;
        </echo>
    </target>
	
    <target name="create-config" description="Create flex config file">
        <ant dir="${basedir}/frameworks" target="flex-config" />
    </target>
	
    <target name="setup-binary-release" depends="thirdparty-clean"
        description="Set properties needed to turn on features for release sdk">       
	    <!-- 
	        For a release build, download everything fresh.  
	        Build changes to the downloads, might not be caught by the refresh logic.
	        thirdparty-clean should leave this directory empty but just in case...  
	    -->
	    <delete dir="${basedir}/in" failonerror="false" includeEmptyDirs="true" />
        
        <!-- generate localized compiler message jars -->
	    <property name="localized.jars" value="true" />
    </target>
    
    <!--
        Cleanup
    -->
    
    <target name="super-clean" depends="thirdparty-clean,clean" description="Cleans everything including thirdparty downloads."/>

    <target name="thirdparty-clean" description="Removes all thirdparty downloads.">
        <ant dir="${basedir}/modules" target="thirdparty-clean"/>
        <ant dir="${basedir}/frameworks" target="thirdparty-clean"/>
        <delete dir="${basedir}/in"/>
        <delete dir="${basedir}/lib"/>
    </target>

    <target name="clean" depends="modules-clean,frameworks-clean,frameworks-clean,package-clean" 
        description="Full clean excluding thirdparty downloads">
        
        <delete file="${basedir}/flex-sdk-description.xml" failonerror="false"/>
        <delete file="${basedir}/rat*.report" failonerror="false"/>

        <!-- These directory would exist if the AIR SDK was merged in. -->
        <delete dir="${basedir}/lib" failonerror="false" includeEmptyDirs="true">
            <include name="aot/**"/>
            <include name="nai/**"/>
            <include name="win/**"/>
        </delete>
        <delete dir="${basedir}/out" failonerror="false" includeEmptyDirs="true"/>
        <delete dir="${basedir}/temp" failonerror="false" includeEmptyDirs="true"/>
        <delete dir="${basedir}/tempDoc" failonerror="false" includeEmptyDirs="true"/>
        <ant dir="${basedir}/asdoc" target="clean" />
        <ant dir="${basedir}/ide/flashbuilder" target="clean" />
    </target>

    <target name="modules-clean">
        <ant dir="${basedir}/modules" target="clean"/>
    </target>

    <target name="frameworks-clean">
        <ant dir="${basedir}/frameworks" target="clean"/>
    </target>

    <target name="package-clean">
        <delete dir="${basedir}/out" failonerror="false" includeEmptyDirs="true"/>
        <antcall target="clean-temp"/>
    </target>

    <target name="player-clean">
        <delete dir="${basedir}/in/player" failonerror="false" includeEmptyDirs="true"/>
    </target>

    <!--
        Build Java module JARs
    -->

    <target name="modules" description="Full build of all JARs">
        <ant dir="${basedir}/modules"/>
    </target>

    <target name="modules-dev" description="Build src.depend JARs">
        <ant dir="${basedir}/modules" target="dev"/>
    </target>

    <target name="antTasks" description="Full build of antTasks" unless="antTasks.compiled" >
        <ant dir="${basedir}/modules/antTasks"/>
        <property name="antTasks.compiled" value="true"/>
    </target>

    <!--
        Build framework SWCs
    -->

    <target name="frameworks" description="Full build of all framework SWCs, including resource bundles and themes">
        <ant dir="${basedir}/frameworks">
            <property name="locale" value="${locale}"/>
        </ant>
    </target>

    <target name="framework-compile" description="Recompile framework.swc">
        <ant dir="${basedir}/frameworks/projects/framework" target="compile">
            <property name="locale" value="${locale}"/>
        </ant>
    </target>

    <target name="other.locales" description="Build resource SWCs for additional locales">
        <ant dir="${basedir}/frameworks" target="other.locales"/>
    </target>

    <target name="javadocs"
        description="Build javadoc for compiler oem interface">
        <javadoc destdir="${basedir}/javadoc" useexternalfile="yes" maxmemory="128m">
            <classpath>
                <fileset dir="${basedir}/lib">
                    <include name="flex-compiler-oem.jar"/>
                </fileset>
            </classpath>
            <fileset dir="${basedir}/modules/compiler/src/java/flex2/tools/oem">
                <include name="*.java"/>
                <exclude name="**/*.properties"/>
            </fileset>
        </javadoc>
        <mkdir dir="${basedir}/out"/>
        <zip destfile="${basedir}/out/${kit.prefix}-compiler-api-javadocs.zip" basedir="${FLEX_HOME}/javadoc"/>
        <delete dir="${basedir}/javadoc" failonerror="false" includeEmptyDirs="true"/>
    </target>

	<target name="ide" description="Build any ide specific files">
        <ant dir="${basedir}/ide/flashbuilder" />
    </target>
    
    <target name="post-build" depends="ide" description="Handle post-build activities" />

    <!--
        Build the ASDoc html pages.
    -->
    <target name="asdoc" description="asdoc">
        <ant dir="${basedir}/asdoc" />
    </target>

    <!--
        Package up the Apache Flex sources.  Do not include empty directories.
        
        Note: even if cleaned, this will package up unversioned files that happen
        to be in the tree.
        
        FixMe: clean needs to clean - add code to detect unversioned files
    -->
    <target name="source-package" depends="stage-source,source-package-zip,source-package-tgz"
        description="Package source files required to build in zip and tar-gzip file">
    </target>
    
    <!--
        Packages the source distribution with ZIP.
    -->
    <target name="source-package-zip" unless="no.zip">
        <mkdir dir="${basedir}/out"/>
        <zip destfile="${basedir}/out/${source.kit}.zip" basedir="${basedir}/temp"/>
    </target>

    <!-- 
        Packages the source distribution with TAR-GZIP.
    -->
    <target name="source-package-tgz" unless="no.zip">
        <tar-gzip name="${source.kit}" />
    </target>

    <target name="stage-source"
        description="Package source files required to build in zip file">

        <antcall target="clean-temp"/>
        
        <copy todir="${basedir}/temp" includeEmptyDirs="false">
            <fileset dir="${basedir}">
                <include name="build.xml"/>
                <include name="build.properties"/>
				<include name="env-template.properties"/>
                <include name="flex-sdk-description.xml"/>
                <include name="installer.xml"/>
                <include name="installer.properties/**"/>
                <include name="CHANGES"/>
                <include name="LICENSE"/>
                <include name="LICENSE.base"/>
                <include name="LICENSE.bin"/>
                <include name="NOTICE"/>
                <include name="NOTICE.asc"/>
                <include name="NOTICE.base"/>
                <include name="NOTICE.bin"/>
                <include name="README"/>
                <include name="RELEASE_NOTES"/>
            	<include name="CONTRIBUTING"/>
                <include name="CONTRIBUTORS"/>
            </fileset>
        </copy>
         
        <!-- bin -->
        <antcall target="stage-bin"/>

        <!-- frameworks -->
        <antcall target="stage-frameworks"/>

        <!-- modules -->
        <antcall target="stage-modules"/>

        <!-- examples -->
        <antcall target="stage-examples"/>
        
        <!-- asdoc -->
        <copy todir="${basedir}/temp/asdoc" includeEmptyDirs="false">
            <fileset dir="${basedir}/asdoc">
            	<exclude name="test/**" />
            </fileset>
        </copy>  

        <!-- ide -->
        <copy todir="${basedir}/temp/ide">
            <fileset dir="${basedir}/ide" >
            	<include name="flashbuilder/**"/>
            	<include name="*.sh"/>
            	<include name="*.bat"/>
                <include name="vscode-nextgenas/**"/>
            </fileset>
        </copy>
        
        <!-- templates -->
        <copy todir="${basedir}/temp/templates">
            <fileset dir="${basedir}/templates" >
                <include name="automation-runtimeloading-files/**"/>
                <include name="swfobject/**"/>
            </fileset>
        </copy>
        
        <!-- 
             Source files have Windows line endings.  Most UNIX editors can handle
             either type of line endings but the converse is often not true.             
             The bin directory is handled in stage-bin.
        -->
        <fixcrlf srcdir="${basedir}/temp" eol="crlf" fixlast="false">
            <exclude name="bin/**"/>
            <exclude name="**/assets/**"/>
            <exclude name="**/*.fla"/>
            <exclude name="**/*.flv"/>
            <exclude name="**/*.gif"/>
            <exclude name="**/*.mp3"/>
            <exclude name="**/*.jpg"/>
            <exclude name="**/*.pbj"/>
            <exclude name="**/*.png"/>
            <exclude name="**/*.sh"/>
            <exclude name="**/*.swf"/>
        </fixcrlf>
               
        <!-- 
            Unix shell scripts need the correct line endings. 
            The bin directory is handled in stage-bin.
        -->      
        <fixcrlf srcdir="${basedir}/temp" eol="unix" fixlast="false">  
            <include name="**.sh"/>
            <exclude name="bin/**"/>
        </fixcrlf>
    </target>

    <!-- examples -->
    <target name="stage-examples">
        <copy todir="${basedir}/temp/examples" includeEmptyDirs="false">
            <fileset dir="${basedir}/examples">
                <include name="**"/>
                <exclude name="**/libs/**"/>
                <exclude name="**/*.swc"/>
                <exclude name="**/*.swf"/>
                <exclude name="**/out/**"/>
                <exclude name="**/bin/**"/>
                <exclude name="**/bin-debug/**"/>
                <exclude name="**/bin-release/**"/>
                <exclude name="**/.idea/**"/>
                <exclude name="**/.settings/**"/>
                <exclude name="**/*.iml"/>
            </fileset>
        </copy>
    </target>

    <!-- frameworks -->
    <!-- test directories follow -->
    <target name="stage-frameworks">
        <copy todir="${basedir}/temp/frameworks" includeEmptyDirs="false">
            <fileset dir="${basedir}/frameworks">
                <include name="**"/>
                <exclude name="**/libs/**"/>
                <exclude name="**/*.swc"/>
                <exclude name="**/*.pbj"/>
                <exclude name="**/*.swf"/>
                <exclude name="**/*.mxp"/>
                <exclude name="test*/**"/>
                <exclude name="projects/air/**"/>
                <exclude name="projects/spark/manifest.xml"/>
                <exclude name="projects/*/bundles.properties"/>
                <exclude name="projects/*/.settings/**"/>
            </fileset>
        </copy>
        
        <!-- frameworks/tests -->
        <antcall target="stage-frameworks-tests"/>
    </target>
    
    <target name="stage-frameworks-tests" unless="no.tests">
        <!-- frameworks -->
        <copy todir="${basedir}/temp/frameworks" includeEmptyDirs="false">
            <fileset dir="${basedir}/frameworks">
                <include name="test*/**"/>
            </fileset>
        </copy>
    </target>
    
    <target name="stage-bin">
        <copy todir="${basedir}/temp/bin" includeEmptyDirs="false">
            <fileset dir="${basedir}/bin">
                <include name="*"/>
                <exclude name="adl*"/>
                <exclude name="adt*"/>
            </fileset>
        </copy>
        
        <fixcrlf srcdir="${basedir}/temp/bin" eol="crlf" fixlast="false">
            <include name="**/*.bat"/>
        </fixcrlf>
  
          <!-- Unix shell scripts need the correct line endings. -->      
        <fixcrlf srcdir="${basedir}/temp/bin" eol="unix" fixlast="false">  
            <exclude name="**/*.bat"/>
        </fixcrlf>
    </target>
        
    <target name="stage-modules" unless="no.modules">
        <!-- modules -->
        <copy todir="${basedir}/temp/modules" includeEmptyDirs="false">
            <fileset dir="${basedir}/modules">
                <include name="**"/>
                <exclude name="thirdparty/**"/>
                <exclude name=".metadata/**"/>
                <exclude name="**/*.jar"/>
                <exclude name="**/*.vms"/>
                <exclude name="*/test/**"/>
                <exclude name="compiler/src/java/velocity.log"/>
                <exclude name="compiler/**/ParseException.java"/>
                <exclude name="compiler/**/Parser.java"/>
                <exclude name="compiler/**/ParserConstants.java"/>
                <exclude name="compiler/**/Token.java"/>
                <exclude name="compiler/**/TokenManager.java"/>
                <exclude name="compiler/**/TokenMgrError.java"/>
                <exclude name="**/classes/**"/>
                <exclude name="**/.classpath"/>
                <exclude name="**/.project"/>
            </fileset>
        </copy>  

        <!-- modules/thirdparty -->
        <copy todir="${basedir}/temp/modules/thirdparty" includeEmptyDirs="true">
            <fileset dir="${basedir}/modules/thirdparty">
                <include name="**"/>
                <exclude name="**/classes/**"/>
                <exclude name="**/.classpath"/>
                <exclude name="**/.project"/>
                <exclude name="*/test*/**"/>
            </fileset>
        </copy>  
    </target>

    <target name="binary-package"
        description="Package binary files in zip and tar-gzip file.">

        <!-- don't include modules directory in stage-source -->
        <property name="no.modules" value="set" />
        
        <!-- don't include mustella or frameworks/tests in stage-source -->
        <property name="no.tests" value="set" />
        
        <antcall target="stage-source"/>
        
        <!--
            Some, but not all framework sources are included.
            Need to include the sources required for build_framework.xml.
        -->
        <delete dir="${basedir}/temp/frameworks" includeemptydirs="true">
            <include name="build_framework.xml"/>
            <include name="projects/*/.*/**"/>
            <include name="projects/*/asdoc/**"/>
            <include name="projects/*/bundles/*/docs/**"/>
            <include name="projects/flash-integration/**"/>
            <include name="projects/playerglobal/**"/>
            <exclude name="projects/flash-integration/src/**"/>
            <exclude name="projects/flash-integration/manifest.xml"/>
        </delete>
        
        <!-- remove some of the themes and all the src for the themes -->
        <delete dir="${basedir}/temp/frameworks/themes" includeemptydirs="true">
            <include name="Ice/**"/>
            <include name="Institutional/**"/>
            <include name="Smoke/**"/>
            <include name="Wooden/**"/>
            <include name="**/src/**"/>
        </delete>
        
        <!-- delete any left-over empty directories -->
        <delete includeemptydirs="true">
            <fileset dir="${basedir}/temp/frameworks">
                <and>
                    <size value="0"/>
                    <type type="dir"/>
                </and>
            </fileset>
        </delete>

        <!-- these files are in addition to the remaining source files -->
        
        <!-- concat the license file with the binary license file for the 3rd party deps -->
        <concat destfile="${basedir}/temp/LICENSE">
            <filelist dir="${FLEX_HOME}" files="LICENSE,LICENSE.bin"/>
        </concat>
        <!-- concat the license file with the binary license file for the 3rd party deps -->
        <concat destfile="${basedir}/temp/NOTICE">
            <filelist dir="${FLEX_HOME}" files="NOTICE,NOTICE.bin"/>
        </concat>
        
        <!-- use this to build frameworks -->
        <copy file="${basedir}/frameworks/build_framework.xml" 
            tofile="${basedir}/temp/frameworks/build.xml" failonerror="true" verbose="true"/>

        <!-- ant is pre-built and in FLEX_HOME/ant rather than modules/antTasks -->
        <antcall target="stage-antTasks"/>
        
        <!-- locales -->
        <antcall target="stage-locales"/>

        <!-- generated files in frameworks excepts libs -->
        <copy todir="${basedir}/temp/frameworks">
            <fileset dir="${basedir}/frameworks">
                <include name="projects/*/bundles.properties"/>
                <include name="projects/spark/manifest.xml"/>
                <include name="**/*.pbj"/>
                <include name="**/*.swc"/>
                <include name="**/*.swf"/>
                <exclude name="libs/**"/>
                <exclude name="tests/**"/>
            </fileset>
        </copy>

        <!-- frameworks/libs -->
        <copy todir="${basedir}/temp/frameworks/libs">
            <fileset dir="${basedir}/frameworks/libs">
                <include name="authoringsupport.swc"/>
                <include name="core.swc"/>
                <include name="framework.swc"/>
                <include name="starling.swc"/>
                <include name="feathers.swc"/>
                <include name="feathers-mxml.swc"/>
            </fileset>
        </copy>

        <!-- frameworks/rsls -->
        <!-- this folder is required by Flash Builder, even if it's not used -->
        <mkdir dir="${basedir}/temp/frameworks/rsls"/>
        
        <!-- the jar files -->
        <antcall target="stage-lib"/>

        <!-- locale swcs -->
        <copy todir="${basedir}/temp/frameworks/locale">
            <fileset dir="${basedir}/frameworks/locale">
                <include name="**/*.swc"/>
            </fileset>
        </copy>

        <!-- ide -->
        <copy todir="${basedir}/temp/ide">
            <fileset dir="${basedir}/ide" >
                <include name="flashbuilder/config"/>
            </fileset>
        </copy>

        <!-- swfobject templates except for downloaded files -->
        <copy todir="${basedir}/temp/templates/swfobject">
            <fileset dir="${basedir}/templates/swfobject"/>
        </copy>
                
        <!-- now that config xml files are in temp, fix them up for release. -->
        <echo message="Updating config file air-config.xml with version ${build.version}"/>
        <fix-config-file file="${basedir}/temp/frameworks/air-config.xml" version="${build.version}" />
        <echo message="Updating config file flex-config.xml with version ${build.version}"/>
        <fix-config-file file="${basedir}/temp/frameworks/flex-config.xml" version="${build.version}" />

        <antcall target="binary-package-zip"/>
        <antcall target="binary-package-tgz"/>
    </target>
        
    <target name="stage-lib">
        <!-- 
            lib - Do not include any jars which we prompted to download because of
            conflicting licenses.  These are all in lib/external/optional.
        -->
        <copy todir="${basedir}/temp/lib">
            <fileset dir="${basedir}/lib">
                <include name="asc.jar"/>
                <include name="asdoc.jar"/>
                <include name="batik-all-flex.jar"/>
                <include name="compc.jar"/>
                <include name="copylocale.jar"/>
                <include name="digest.jar"/>
                <include name="fdb.jar"/>
                <include name="fcsh.jar"/>
                <include name="flex-compiler-oem.jar"/>
                <include name="flex-messaging-common.jar"/>
                <include name="mxmlc.jar"/>
                <include name="optimizer.jar"/>
                <include name="swcdepends.jar"/>
                <include name="swfdump.jar"/>
                <include name="swfutils.jar"/>
                <include name="fxgutils.jar"/>
                <include name="velocity-dep-1.4-flex.jar"/>
                <include name="flex-tool-api.jar"/>
                <exclude name="external/optional/**"/>
            </fileset>
        </copy>

        <!-- 
            external libraries
            We don't have the sources to build them but they have compatible licenses.
        -->
        <copy todir="${basedir}/temp/lib/external">
            <fileset dir="${basedir}/lib/external">
                <!-- required license and notice files -->
                <include name="*LICENSE*/**"/>
                <include name="*NOTICE*/**"/>
                <include name="*README*"/>
                <!-- jar files -->
                <include name="commons-collections.jar"/>
                <include name="commons-discovery.jar"/>
                <include name="commons-logging.jar"/>
                <include name="javacc.jar"/>
                <include name="saxon9.jar"/>
                <include name="xalan.jar"/>
                <include name="xercesImpl.jar"/>
                <include name="xercesPatch.jar"/>
                <include name="xml-apis-ext.jar"/>
                <include name="xml-apis.jar"/>
                <exclude name="optional/**"/>
            </fileset>
        </copy>
    </target>
    
    <!-- 
        Packages the binary distribution with ZIP. 
    -->
    <target name="binary-package-zip" unless="no.zip"
        description="Zips up the files in the temp directory into the binary zipfile.">
        
        <mkdir dir="${basedir}/out"/>
        <zip destfile="${basedir}/out/${binary.kit}.zip" basedir="${basedir}/temp"/>
    </target>
    
    <!-- 
        Packages the binary distribution with TAR-GZIP.         
    -->
    <target name="binary-package-tgz" unless="no.zip"
        description="Tar-Gzip up the files in the temp directory into the binary tgz file.">
        
        <tar-gzip name="${binary.kit}" />
    </target>
    
    <macrodef name="fix-config-file">
        <attribute name="file"/>
        <attribute name="version"/>
            <sequential>
                <replace file="@{file}">
                    <replacefilter
                        token="&lt;warn-no-explicit-super-call-in-constructor&gt;true"
                        value="&lt;warn-no-explicit-super-call-in-constructor&gt;false"/>
                    <replacefilter
                        token="$${build.number}"
                        value="@{version}"/>
                </replace>
        </sequential>
    </macrodef>

    <!--
        tar with gzip compression, the temp directory and put it in the out directory.  
        The shell scripts in the bin directory (no extension) and other .sh files have 
        mode set to execute.
        
        name - the basename name of the kit in out directory, without the .tar.gz extension
    -->
    <macrodef name="tar-gzip">
        <attribute name="name"/>
            <sequential>
                <mkdir dir="${basedir}/out"/>        
                <tar destfile="${basedir}/out/@{name}.tar.gz" 
                    compression="gzip"
                    longfile="gnu">
                    <tarfileset dir="${basedir}/temp" prefix="@{name}">
                        <include name="**" />
                        <exclude name="bin/**" />
                        <exclude name="**/*.sh" />
                    </tarfileset>
                    <tarfileset dir="${basedir}/temp" prefix="@{name}">
                        <include name="bin/*.bat" />
                    </tarfileset>
                    <tarfileset dir="${basedir}/temp" prefix="@{name}" mode="755">
                        <include name="bin/*" />
                        <include name="**/*.sh" />
                        <exclude name="bin/*.bat" />
                    </tarfileset>
                </tar>
        </sequential>
    </macrodef>	   

    <target name="stage-locales"
        description="Stage all the locale swc's built">
        
        <copy todir="${basedir}/temp/frameworks/locale" includeEmptyDirs="false">
            <fileset dir="${basedir}/frameworks/locale">
                <include name="**/*.swc"/>
            </fileset>
        </copy>

        <!-- frameworks/projects -->
        <!--
            Remove these files from the binary kit.
            
            copylocale looks for bundles and then uses default locale so if there is
            not a locale sub-directory don't include the bundles directory.
        -->
        <delete dir="${basedir}/temp/frameworks/projects" includeEmptyDirs="false">
            <include name="airspark/bundles/**"/>
            <include name="automation_air/bundles/**"/>
            <include name="automation_dmv/bundles/**"/>
            <include name="automation_flashflexkit/bundles/**"/>
            <include name="automation_spark/bundles/**"/>
            <include name="*/bundles/**/empty.properties"/>
            <include name="*/bundles/**/docs/**"/>
            <include name="*/bundles/*/*.xml"/>
            <include name="*/bundles/*/packages.dita"/>
            <exclude name="*/bundles/${locale}"/>
        </delete>
        

        <!-- lib -->
        <!-- these are built when the compiler is built with localized.jars set -->
        <copy todir="${basedir}/temp/lib">
            <fileset dir="${basedir}/lib">
                <include name="mxmlc_da.jar"/>
                <include name="mxmlc_de.jar"/>
                <include name="mxmlc_es.jar"/>
                <include name="mxmlc_fi.jar"/>
                <include name="mxmlc_fr.jar"/>
                <include name="mxmlc_it.jar"/>
                <include name="mxmlc_ja.jar"/>
                <include name="mxmlc_ko.jar"/>
                <include name="mxmlc_nb.jar"/>
                <include name="mxmlc_nl.jar"/>
                <include name="mxmlc_pt.jar"/>
                <include name="mxmlc_ru.jar"/>
                <include name="mxmlc_sv.jar"/>
                <include name="mxmlc_zh_CN.jar"/>
                <include name="mxmlc_zh_TW.jar"/>
            </fileset>
        </copy>
        
        <!-- FixMe: Apache is missing all these language jars. -->
        <copy todir="${basedir}/temp/lib">
            <fileset dir="${basedir}/lib">
                <include name="batik_da.jar"/>
                <include name="batik_de.jar"/>
                <include name="batik_es.jar"/>
                <include name="batik_fi.jar"/>
                <include name="batik_fr.jar"/>
                <include name="batik_it.jar"/>
                <include name="batik_ko.jar"/>
                <include name="batik_ja.jar"/>
                <include name="batik_nb.jar"/>
                <include name="batik_nl.jar"/>
                <include name="batik_pt.jar"/>
                <include name="batik_ru.jar"/>
                <include name="batik_sv.jar"/>
                <include name="batik_zh_CN.jar"/>
                <include name="batik_zh_TW.jar"/>
                <include name="xercesImpl_da.jar"/>
                <include name="xercesImpl_de.jar"/>
                <include name="xercesImpl_es.jar"/>
                <include name="xercesImpl_fi.jar"/>
                <include name="xercesImpl_fr.jar"/>
                <include name="xercesImpl_it.jar"/>
                <include name="xercesImpl_ko.jar"/>
                <include name="xercesImpl_ja.jar"/>
                <include name="xercesImpl_nb.jar"/>
                <include name="xercesImpl_nl.jar"/>
                <include name="xercesImpl_pt.jar"/>
                <include name="xercesImpl_ru.jar"/>
                <include name="xercesImpl_sv.jar"/>
                <include name="xercesImpl_zh_CN.jar"/>
                <include name="xercesImpl_zh_TW.jar"/>
            </fileset>
        </copy>
    </target>
 
    <target name="antTasks-package" if="build.additional-packages">

        <antcall target="antTasks"/>
        <antcall target="clean-temp"/>
        
        <antcall target="stage-antTasks"/>

        <!-- templates -->
        <copy todir="${basedir}/temp/templates">
            <fileset dir="${basedir}/templates" >
                <include name="**/*"/>
                <exclude name="build.*"/>
                <exclude name="swfobject/readme.txt"/>
                <exclude name="metadata/**"/>
            </fileset>
        </copy>

        <mkdir dir="${basedir}/out"/>
        <zip file="${basedir}/out/${kit.prefix}-flexTasks.zip" basedir="${basedir}/temp"/>
        <antcall target="clean-temp"/>
    </target>

    <target name="stage-antTasks" description="Stage antTask binaries.">
        
        <copy file="${basedir}/modules/antTasks/build.xml-distro"
              tofile="${basedir}/temp/ant/build.xml"/>
        <copy file="${basedir}/modules/antTasks/README.txt"
              tofile="${basedir}/temp/ant/README.txt"/>
        <copy file="${basedir}/modules/antTasks/flexTasks.tasks"
              todir="${basedir}/temp/ant"/>

        <!-- lib -->
        <copy todir="${basedir}/temp/ant/lib">
            <fileset dir="${basedir}/lib" includes="flexTasks.jar"/>
        </copy>

        <!-- src -->
        <copy todir="${basedir}/temp/ant/src">
            <fileset dir="${basedir}/modules/antTasks/src/">
                 <include name="flex/**/*.java"/>
            </fileset>
        </copy>
    </target>
    
    <target name="asdoc-package" description="Package the asdocs">      
        <antcall target="clean-temp"/>
        <antcall target="asdoc"/>
        
        <copy todir="${basedir}/temp/asdoc">
            <fileset dir="${basedir}/asdoc-output"/>
        </copy>
        <copy todir="${basedir}/temp/asdoc">
            <fileset dir="${basedir}">
                <include name="LICENSE" />
                <include name="NOTICE" />
            </fileset>
        </copy>
        <zip file="${basedir}/out/${kit.prefix}-asdocs.zip" basedir="${basedir}/temp"/>
        <antcall target="clean-temp"/>
    </target>

    <target name="clean-temp" unless="noclean.temp">
        <delete dir="${basedir}/temp" failonerror="false" includeEmptyDirs="true"/>
    </target>

    <!-- Builds fat swcs. -->
    <target name="doc">
        <ant dir="${basedir}/frameworks" target="doc" />
    </target>


    <!-- To run the checkintests as well as any mustella tests need AIR for the adl and
         a flash player content debugger.
    -->
    <target name="check-runtime-env" depends="check-air-home"
        description="Check for the required runtime environment variables for the checkintests">
        
        <available file="${env.FLASHPLAYER_DEBUGGER}" property="FLASHPLAYER_DEBUGGER.set"/>
        <fail message="FLASHPLAYER_DEBUGGER is ${env.FLASHPLAYER_DEBUGGER} which is not an Adobe Flash Player content debugger" 
            unless="FLASHPLAYER_DEBUGGER.set"/>
    </target>
    
    <target name="runtime-setup" depends="check-runtime-env" unless="runtime.setup"
        description="Set flash.player and adl properties"> 
        
        <!-- Paths to the debug standalone flashplayer. -->
        <!-- (windows) path to FlashPlayerDebugger.exe -->
        <!-- (mac) path to Flash Player Debugger.app/Contents/MacOS/Flash Player Debugger -->
        <!-- (linux) path to flashplayerdebugger -->
        <property name="flash.player" value="${env.FLASHPLAYER_DEBUGGER}"/>
    
        <!-- Paths to the adl. -->
        <condition property="adl" value="${env.AIR_HOME}/bin/adl.exe">
            <os family="windows"/>
        </condition>
        <condition property="adl" value="${env.AIR_HOME}/bin/adl">
            <os family="mac"/>
        </condition>
        <condition property="adl" value="${env.AIR_HOME}/bin/adl">
            <os family="unix"/>
        </condition>
        
        <property name="runtime.setup" value="done"/>
    </target>

    <target name="load-task" depends="runtime-setup">
        <!-- load the <mxmlc> task; we can't do this at the <project> level -->
        <!-- because targets that run before flexTasks.jar gets built would fail -->
        <taskdef resource="flexTasks.tasks" classpath="${basedir}/lib/flexTasks.jar"/>
    </target>

  <!--
      Run FlexUnit tests
  -->

  <target name="test" description="Run all framework projects' FlexUnit tests">
      <ant dir="${basedir}/frameworks" target="test"/>
  </target>

</project>
