<?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="asjs" default="main" basedir=".">

    <property name="ROYALE_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="${ROYALE_HOME}/env.properties"/>
    <property environment="env"/>
    <property file="${ROYALE_HOME}/local.properties"/>
    <property file="${ROYALE_HOME}/build.properties"/>
    <condition property="swf.distribution">
        <isset property="env.AIR_HOME" />
    </condition>
    <condition property="AIR_HOME" value="${env.AIR_HOME}">
        <isset property="env.AIR_HOME" />
    </condition>
    <property name="AIR_HOME" value="${ROYALE_HOME}"/>
    <condition property="PLAYERGLOBAL_HOME" value="${env.PLAYERGLOBAL_HOME}">
        <isset property="env.PLAYERGLOBAL_HOME" />
    </condition>
    <property name="PLAYERGLOBAL_HOME" value="${ROYALE_HOME}/frameworks/libs/player"/>

    <property name="debug" value="true"/>
    <property name="strict" value="true"/>
    <property name="javac.src" value="11"/>
    
    <property name="kit.prefix" value="apache-royale-${release.version}"/>
    <property name="source.kit" value="${kit.prefix}-src"/>
    <condition property="binary.kit" value="${kit.prefix}-bin-js">
        <not>
            <isset property="swf.distribution" />
        </not>
    </condition>
    <property name="binary.kit" value="${kit.prefix}-bin-js-swf"/>
    <property name="binary-js.kit" value="${kit.prefix}-bin-js"/>
    <property name="staging-dir" value="${basedir}/temp/royale-asjs" />
    
    <condition property="isMac" value="mac">
        <os family="mac" />
    </condition>
    <condition property="isWindows" value="windows">
        <os family="windows" />
    </condition>
    <condition property="isLinux" value="linux">
        <and>
            <os family="unix" />
            <not>
                <isset property="isMac" />
            </not>
        </and>
    </condition>
    <!-- turn off SWF portion of checkintest if no swf.distribution -->
    <condition property="runtime.setup">
        <not>
            <isset property="swf.distribution" />
        </not>
    </condition>
    <condition property="mxmlc.jar.exists">
        <not>
            <isset property="swf.distribution" />
        </not>
    </condition>
    
    <!--
        Optional jars but should be in place for a real release build.
        
        For <grep> put AntelopeTasks_*.jar in this path.
        See version-update.

        For <rat> apache-rat-0.8.jar and apache-rat-tasks-0.8.jar should be in classpath.
        See rat-check.
    -->
    <path id="anttask.classpath">
        <fileset dir="${env.ANT_HOME}/lib">
           <include name="**/AntelopeTasks_*.jar"/>
           <include name="**/apache-rat*.jar"/>
        </fileset>
        <fileset dir="${user.home}">
           <include name=".ant/lib/**/AntelopeTasks_*.jar"/>
           <include name=".ant/lib/**/apache-rat*.jar"/>
        </fileset>
    </path>
    
    <!--
        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="check-if-ide,prebuild,frameworks,post-build,last-message-if-airsdk" description="Full build" unless="airsdk.found">
        <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="main-jenkins" depends="dump-config,prebuild,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="dump-config" unless="airsdk.found" >
        <property name="is.jenkins" value="true" />
        <echo>env.USERNAME is: ${env.USERNAME}</echo>
        <condition property="FLASHLOG"
            value="c:/Documents and Settings/${env.USERNAME}/Application Data/Macromedia/Flash Player/Logs/flashlog.txt">
            <available file="c:/Documents and Settings/${env.USERNAME}/Application Data/Macromedia/Flash Player/Logs/flashlog.txt"
                type="file"/>
        </condition>
        <condition property="FLASHLOG"
            value="c:/Users/${env.USERNAME}/AppData/Roaming/Macromedia/Flash Player/Logs/flashlog.txt">
            <available file="c:/Users/${env.USERNAME}/AppData/Roaming/Macromedia/Flash Player/Logs/flashlog.txt"
                type="file"/>
        </condition>
        <!-- Check the system user profile -->
        <condition property="FLASHLOG"
                   value="C:/Windows/system32/config/systemprofile/AppData/Roaming/Macromedia/Flash Player/Logs/flashlog.txt">
            <available file="C:/Windows/system32/config/systemprofile/AppData/Roaming/Macromedia/Flash Player/Logs/flashlog.txt"
                       type="file"/>
        </condition>
        <antcall target="copy-flashlog"/>
    </target>
    <target name="copy-flashlog" if="FLASHLOG">
        <echo>copying last flashlog.txt from ${FLASHLOG}</echo>
        <copy file="${FLASHLOG}" tofile="${basedir}/lastflashlog.txt" />
    </target>
    
    <target name="block-flat-fonts">
        <property name="flat.donot.ask" value="true" />
    </target>
    
    <target name="release"
        depends="block-flat-fonts,check-compiler-home,check-typedefs-home,source-release,binary-release,rat-check"
        description="Creates source and binary kits for Apache Royale."/>
        
    <target name="release-jenkins" 
        depends="check-compile-env,check-runtime-env,check-compiler-home,source-release,binary-release-jenkins,rat-check"
        description="Creates source and binary kits for Apache Royale."/>
  
    <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,set.base.folder,build-all,main,sample-themes,checkintests,check-goog-home,binary-package,jsonly-package"
        description="Builds and packages the binary kit which is provided as a convenience."/>    

    <target name="binary-release-jenkins" 
        depends="setup-binary-release,main-jenkins,sample-themes,binary-package"
        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,sample-themes,checkintests,binary-package"
        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="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." unless="airsdk.found">
        <ant dir="${basedir}/frameworks" target="thirdparty-downloads"/>
        <condition property="env.GOOG_HOME" value="${basedir}/js/lib/google/closure-library">
            <not>
                <isset property="env.GOOG_HOME" />
            </not>
        </condition>
        <!-- <ant dir="${basedir}/frameworks/js" 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" />
        <!-- this flag is used by frameworks/build.xml to prevent a second download -->
        <property name="no.thirdparty-downloads" value="set" />
    </target>

    <target name="prebuild" depends="check-compile-env,thirdparty-downloads,create-description,copy-externs,copy-playerglobal,copy-airglobal,copy-compiler,create-config"
        description="Stuff that needs to be done before any builds." unless="airsdk.found"/>

    <target name="check-compile-env" depends="check-playerglobal-home,check-air-home,check-compiler-home" unless="airsdk.found"
        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" if="env.PLAYERGLOBAL_HOME"
        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" if="env.AIR_HOME"
        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="check-goog-home" unless="GOOG_HOME"
        description="Check that GOOG_HOME is a directory">
        
        <echo message="GOOG_HOME is ${env.GOOG_HOME}"/>

        <available file="${env.GOOG_HOME}" 
            type="dir" 
            property="GOOG_HOME"
            value="${env.GOOG_HOME}" />
    </target>
    
    <target name="check-compiler-home" unless="ROYALE_COMPILER_REPO"
        description="Check ROYALE_COMPILER_REPO is a directory.">
        
        <echo message="env.ROYALE_COMPILER_REPO is ${env.ROYALE_COMPILER_REPO}"/>

        <available file="${env.ROYALE_COMPILER_REPO}/compiler/lib/compiler-mxmlc.jar"
            type="file" 
            property="ROYALE_COMPILER_REPO"
            value="${env.ROYALE_COMPILER_REPO}"/>
            
        <echo message="ROYALE_COMPILER_REPO is ${ROYALE_COMPILER_REPO}"/>

        <condition property="ROYALE_COMPILER_REPO" value="${basedir}/../royale-compiler">
            <and>
                <available file="${basedir}/../royale-compiler/compiler/lib/compiler-mxmlc.jar" type="file" />
                <not>
                    <isset property="ROYALE_COMPILER_REPO" />
                </not>
            </and>
        </condition>

        <echo message="ROYALE_COMPILER_REPO is ${ROYALE_COMPILER_REPO}"/>
        
        <fail message="ROYALE_COMPILER_REPO must be set to a folder with a compiler/lib sub-folder containing compiler-mxmlc.jar such as the top-level folder in royale-compiler repo"
            unless="ROYALE_COMPILER_REPO"/>
    </target>

    <target name="check-typedefs-home" unless="ROYALE_TYPEDEFS_HOME"
        description="Check ROYALE_TYPEDEFS_HOME is a directory.">
        
        <echo message="ROYALE_TYPEDEFS_HOME is ${env.ROYALE_TYPEDEFS_HOME}"/>
        
        <available file="${env.ROYALE_TYPEDEFS_HOME}/js/target/js.swc"
        type="file"
        property="ROYALE_TYPEDEFS_HOME"
        value="${env.ROYALE_TYPEDEFS_HOME}"/>
        
        <available file="${basedir}/../royale-typedefs/js/target/js.swc"
        type="file"
        property="ROYALE_TYPEDEFS_HOME"
        value="${basedir}/../royale-typedefs"/>
        
        <available file="${basedir}/js/target/js.swc"
        type="file"
        property="ROYALE_TYPEDEFS_HOME"
        value="${basedir}"/>
        
        <echo>basedir is ${basedir}</echo>
        
        <fail message="ROYALE_TYPEDEFS_HOME must be set to a folder containing js/target/js.swc such as the royale-typedefs repo"
        unless="ROYALE_TYPEDEFS_HOME"/>
    </target>

    <target name="swf-js-output-royale-description" if="env.PLAYERGLOBAL_HOME">
        <echo file="${basedir}/royale-sdk-description.xml" append="true">
&lt;output-targets&gt;
    &lt;output-target name="js" version="Ecma5Strict" /&gt;
    &lt;output-target name="swf" version="AS3" AIR="${air.version}" Flash="${playerglobal.version}" /&gt;
&lt;/output-targets&gt;
&lt;/royale-sdk-description&gt;
        </echo>
    </target>

    <target name="js-output-royale-description" unless="env.PLAYERGLOBAL_HOME">
        <echo file="${basedir}/royale-sdk-description.xml" append="true">
&lt;output-targets&gt;
    &lt;output-target name="js" version="Ecma5Strict" /&gt;
&lt;/output-targets&gt;
&lt;/royale-sdk-description&gt;
        </echo>
    </target>

    <target name="create-jsonly-description">
        <tstamp>
            <format property="build.number.date" pattern="yyyyMMdd" />
        </tstamp>
        <echo message="build.number is ${build.number.date}"/>
        <echo file="${basedir}/temp/royale-asjs/royale-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;royale-sdk-description&gt;
    &lt;name&gt;${release.name}&lt;/name&gt;
    &lt;version&gt;${release.version}&lt;/version&gt;
    &lt;build&gt;${build.number.date}&lt;/build&gt;
    &lt;output-targets&gt;
        &lt;output-target name="js" version="Ecma5Strict" /&gt;
    &lt;/output-targets&gt;
&lt;/royale-sdk-description&gt;
        </echo>
    </target>

    <target name="create-description" description="Generate flex-sdk-description.xml" unless="airsdk.found">
        <tstamp>
        	<format property="build.number.date" pattern="yyyyMMdd" />
        </tstamp>
        <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.name} ${release.version} FP${playerglobal.version} AIR${air.version} ${locale}&lt;/name&gt;
&lt;version&gt;${fb.release.version}&lt;/version&gt;
&lt;build&gt;${build.number.date}&lt;/build&gt;
&lt;/flex-sdk-description&gt;
        </echo>
        <echo file="${basedir}/royale-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;royale-sdk-description&gt;
&lt;name&gt;${release.name}&lt;/name&gt;
&lt;version&gt;${release.version}&lt;/version&gt;
&lt;build&gt;${build.number.date}&lt;/build&gt;
        </echo>

        <antcall target="js-output-royale-description" />
        <antcall target="swf-js-output-royale-description" />
    </target>
	
    <target name="create-config" description="Create config files" unless="airsdk.found">
        <ant dir="${basedir}/frameworks" target="create-config">
            <property name="configname" value="royale" />
        </ant>
        <antcall target="tweak-for-jsonly" />
        <ant dir="${basedir}/frameworks" target="create-config">
            <property name="configname" value="air" />
        </ant>
        <ant dir="${basedir}/frameworks" target="create-config">
            <property name="configname" value="js" />
        </ant>
	<ant dir="${basedir}/frameworks" target="create-config">
		<property name="configname" value="ace" />
	</ant>
        <ant dir="${basedir}/frameworks" target="create-config">
            <property name="configname" value="jquery" />
        </ant>
        <ant dir="${basedir}/frameworks" target="create-config">
            <property name="configname" value="createjs" />
        </ant>
        <ant dir="${basedir}/frameworks" target="create-config">
            <property name="configname" value="node" />
        </ant>
        <ant dir="${basedir}/frameworks" target="create-config">
            <property name="configname" value="flex" />
        </ant>
        <!-- hack to keep compiler happy -->
        <mkdir dir="${ROYALE_HOME}/frameworks/themes/Spark" />
        <echo file="${ROYALE_HOME}/frameworks/themes/Spark/spark.css">/*
 * 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.
 *
 */
 /* generated by build script */
</echo>
    </target>
	
    <target name="copy-externs" depends="check-typedefs-home" description="Copy extern swcs into this folder">
        <mkdir dir="${basedir}/js/libs" />
        <copy todir="${basedir}/js/libs" flatten="true">
            <fileset dir="${ROYALE_TYPEDEFS_HOME}">
                <include name="**/*.swc"/>
                <exclude name="airglobal/**/*.swc"/>
                <exclude name="playerglobal/**/*.swc"/>
            </fileset>
        </copy>
        <antcall target="rename_jquery" />
    </target>
    
    <target name="copy-playerglobal" depends="check-typedefs-home" unless="env.PLAYERGLOBAL_HOME">
        <copy todir="${basedir}/frameworks/libs/player/${playerglobal.version}" flatten="true" overwrite="true" failonerror="true">
            <fileset dir="${ROYALE_TYPEDEFS_HOME}/playerglobal/target">
                <include name="playerglobal.swc"/>
            </fileset>
        </copy>
    </target>
    
    <target name="copy-airglobal" depends="check-typedefs-home" unless="env.AIR_HOME">
        <copy todir="${basedir}/frameworks/libs/air" flatten="true" overwrite="true" failonerror="true">
            <fileset dir="${ROYALE_TYPEDEFS_HOME}/airglobal/target">
                <include name="airglobal.swc"/>
            </fileset>
        </copy>
    </target>
    
    <target name="copy-compiler" depends="check-compiler-home" description="Copy compiler jars to where they are supposed to go">
        <mkdir dir="${basedir}/lib" />
        <echo>Copying Compiler from ${ROYALE_COMPILER_REPO}</echo>
        <copy todir="${basedir}/lib">
            <fileset dir="${ROYALE_COMPILER_REPO}/compiler/lib">
                <include name="**"/>
                <exclude name="external/jburg.jar"/>
                <exclude name="external/jflex*"/>
                <exclude name="external/junit*"/>
            </fileset>
        </copy>
        <mkdir dir="${basedir}/bin" />
        <copy todir="${basedir}/bin">
            <fileset dir="${ROYALE_COMPILER_REPO}/compiler/src/assembly/scripts">
                <include name="**"/>
            </fileset>
        </copy>
        <!--
            compiler-jx has some optional scripts that override the ones from
            compiler. the core SWF compiler doesn't understand our
            royale-config.xml because it sets a number of JS-related compiler
            options, so its original scripts will fail when executed and report
            unknown tag errors. the override scripts call compiler-jx with
            -targets=SWF to preserve the original behavior while handling the
            extended options included in royale-config.xml.
        -->
        <copy todir="${basedir}/bin" overwrite="true">
            <fileset dir="${ROYALE_COMPILER_REPO}/compiler-jx/src/assembly/compiler-override-scripts">
                <include name="**"/>
            </fileset>
        </copy>
        <chmod dir="${basedir}/bin" excludes="**/*.bat" perm="+x" />
        <mkdir dir="${basedir}/js/lib" />
        <echo>Copying Transpiler from ${ROYALE_COMPILER_REPO}</echo>
        <copy todir="${basedir}/js/lib">
            <fileset dir="${ROYALE_COMPILER_REPO}/compiler-jx/lib">
                <include name="**"/>
                <exclude name="junit*"/>
            </fileset>
        </copy>
        <!-- needed to make Flash Builder accept folder as a Flex SDK -->
        <copy file="${ROYALE_COMPILER_REPO}/compiler/lib/compiler-mxmlc.jar" tofile="${basedir}/lib/mxmlc.jar" />
        <copy file="${ROYALE_COMPILER_REPO}/compiler/lib/compiler-mxmlc.jar" tofile="${basedir}/lib/adt.jar" />
        <!-- compc used to come from flex-compiler-oem, hopefull this one is ok as well -->
        <copy file="${ROYALE_COMPILER_REPO}/compiler/lib/compiler-compc.jar" tofile="${basedir}/lib/compc.jar" />
    </target>
    
    <target name="check_jquery" >
        <condition property="jquery_exists">
            <available file="${basedir}/js/libs/jquery.swc" />
        </condition>
    </target>
    
    <target name="rename_jquery" depends="check_jquery" unless="jquery_exists" >
        <move file="${basedir}/js/libs/jquery-1.9.swc" tofile="${basedir}/js/libs/jquery.swc" />
    </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" />
        
        <property name="release.target" value="true" />
    </target>
    
    <!--
        Cleanup
    -->
    
    <target name="super-clean" depends="thirdparty-clean,clean" description="Cleans everything including thirdparty downloads.">
        <delete dir="${basedir}/mustella/tests/basicTests/bin"/>
        <delete dir="${basedir}/mustella/tests/mxtests/basicTests/bin"/>
        <delete dir="${basedir}/bin" failonerror="false">
            <include name="**"/>
            <exclude name=".gitignore"/>
        </delete>
        <delete dir="${basedir}/lib" failonerror="false" includeEmptyDirs="true"/>
        <delete dir="${basedir}/js/lib" failonerror="false" includeEmptyDirs="true"/>
        <delete dir="${ROYALE_HOME}/frameworks/libs/player" failonerror="false" includeEmptyDirs="true"/>
        <delete dir="${ROYALE_HOME}/frameworks/libs/air" failonerror="false" includeEmptyDirs="true"/>
        <delete dir="${ROYALE_HOME}/frameworks/locale" failonerror="false" includeEmptyDirs="true"/>
        <delete dir="${ROYALE_HOME}/frameworks/mx" failonerror="false" includeEmptyDirs="true"/>
        <delete dir="${ROYALE_HOME}/frameworks/rsls" failonerror="false" includeEmptyDirs="true"/>
        <delete dir="${ROYALE_HOME}/frameworks/themes/Halo" failonerror="false" includeEmptyDirs="true"/>
        <delete dir="${ROYALE_HOME}/frameworks/themes/Spark" failonerror="false" includeEmptyDirs="true"/>
        <delete file="${ROYALE_HOME}/frameworks/airmobile-config.xml" failonerror="false"/>
        <delete file="${ROYALE_HOME}/frameworks/macfonts.ser" failonerror="false"/>
        <delete file="${ROYALE_HOME}/frameworks/winfonts.ser" failonerror="false"/>
        <delete file="${ROYALE_HOME}/frameworks/localfonts.ser" failonerror="false"/>
        <delete file="${ROYALE_HOME}/frameworks/mxml-manifest.xml" failonerror="false"/>
        <delete file="${ROYALE_HOME}/frameworks/spark-manifest.xml" failonerror="false"/>
        <delete file="${ROYALE_HOME}/ide/flashbuilder/flashbuilder-config.xml" failonerror="false"/>
        <delete dir="${basedir}" failonerror="false">
            <include name="**/*.log"/>
            <include name="**/*.mdmp"/>
        </delete>
    </target>

    <target name="thirdparty-clean" description="Removes all thirdparty downloads.">
        <ant dir="${basedir}/frameworks" target="thirdparty-clean"/>
        <delete dir="${basedir}/in"/>
        <delete dir="${basedir}/lib"/>
        <delete dir="${basedir}/marmotinni/java/lib"/>
    </target>

    <target name="clean" depends="examples-clean,frameworks-clean,package-clean,checkintests-clean,mxtests-clean"
        description="Full clean excluding thirdparty downloads">
        
        <delete file="${basedir}/royale-sdk-description.xml" failonerror="false"/>
        <delete file="${basedir}/rat.report" failonerror="false"/>
        
        <delete dir="${basedir}/examples" failonerror="false">
            <include name="**/*.swc"/>
            <include name="**/*.swf"/>
        </delete>

        <delete dir="${basedir}/js/libs" failonerror="false" includeEmptyDirs="true"/>
        <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="examples-clean">
        <ant dir="${basedir}/examples" target="clean"/>
        <ant dir="${basedir}/manualtests" target="clean"/>
    </target>

    <target name="frameworks-clean">
        <ant dir="${basedir}/frameworks" target="clean"/>
        <ant dir="${basedir}/frameworks/js" target="clean"/>
    </target>

    <target name="package-clean">
        <delete dir="${basedir}/out" failonerror="false" includeEmptyDirs="true"/>
        <antcall target="clean-temp"/>
    </target>

    <target name="checkintests-clean">
        <delete file="${basedir}/mustella/tests/basicTests/BasicTestsApp.swf" failonerror="false"/>
        <delete dir="${basedir}/mustella/tests/basicTests/bin" failonerror="false" includeEmptyDirs="true"/>
    </target>

    <target name="player-clean">
        <delete dir="${basedir}/in/player" failonerror="false" includeEmptyDirs="true"/>
    </target>
    
    <!--
        Build Examples
    -->

    <target name="examples" description="Build the examples"
        depends="prebuild,check-goog-home">
        <ant dir="${basedir}/examples"/>
    </target>

    <!--
        Build framework SWCs
    -->

    <target name="frameworks" description="Full build of all Actionscript framework SWCs, including resource bundles and themes" unless="airsdk.found">
        <ant dir="${basedir}/frameworks">
            <property name="locale" value="${locale}"/>
        </ant>
        <antcall target="tweak-for-jsonly"/>
    </target>

    <target name="sample-themes" description="Build the sample themes">
        <!--<ant dir="${basedir}/samples/themes/zen" target="main" /> -->
    </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/royale2/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="${ROYALE_HOME}/javadoc"/>
        <delete dir="${basedir}/javadoc" failonerror="false" includeEmptyDirs="true"/>
    </target>

	<target name="ide" description="Build any ide specific files" unless="airsdk.found">
        <!--<ant dir="${basedir}/ide/flashbuilder" />-->
    </target>
    
    <target name="post-build" depends="ide" description="Handle post-build activities" unless="airsdk.found">
        <!-- fake a bunch of files to make the folder appear like a valid Flex SDK to Flash Builder -->
        <echo file="${ROYALE_HOME}/ide/flashbuilder/flashbuilder-config.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;flashbuilder-config&gt;
    &lt;express-install-swf&gt;expressInstall.swf&lt;/express-install-swf&gt;
    &lt;/flashbuilder-config&gt;
</echo>
        <echo file="${ROYALE_HOME}/frameworks/mxml-manifest.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;componentPackage&gt;
    &lt;/componentPackage&gt;
</echo>
        <echo file="${ROYALE_HOME}/frameworks/spark-manifest.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;componentPackage&gt;
    &lt;/componentPackage&gt;
</echo>
        <mkdir dir="${ROYALE_HOME}/frameworks/locale" />
        <mkdir dir="${ROYALE_HOME}/frameworks/mx" />
        <mkdir dir="${ROYALE_HOME}/frameworks/projects" />
        <mkdir dir="${ROYALE_HOME}/frameworks/rsls" />
        <mkdir dir="${ROYALE_HOME}/frameworks/themes/Halo" />
        <copy file="${ROYALE_HOME}/js/libs/js.swc"
        tofile="${ROYALE_HOME}/frameworks/themes/Halo/Halo.swc" />
        <copy file="${ROYALE_HOME}/frameworks/air-config.xml"
        tofile="${ROYALE_HOME}/frameworks/airmobile-config.xml" />
        <touch file="${ROYALE_HOME}/frameworks/macfonts.ser" />
        <touch file="${ROYALE_HOME}/frameworks/winfonts.ser" />
        <touch file="${ROYALE_HOME}/frameworks/localfonts.ser" />
    </target>

    <!--
        Build the ASDoc html pages.
    -->
    <target name="asdoc" description="asdoc">
        <ant dir="${basedir}/asdoc" />
    </target>

    <!--
        Package up the Apache Royale 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,stage-compiler,stage-typedefs,stage-top-level,source-package-zip,source-package-tgz"
        description="Package source files required to build in zip and tar-gzip file">
    </target>

    <target name="stage-compiler" >
        <echo file="${ROYALE_COMPILER_REPO}/env.properties">env.ASJS_HOME=${basedir}</echo>
        <!-- windows needs backslashes escaped -->
        <replaceregexp file="${ROYALE_COMPILER_REPO}/env.properties" match="\\" replace="\\\\\\\\" flags="g" />
        <ant dir="${ROYALE_COMPILER_REPO}" target="wipe-all" />
        <ant dir="${ROYALE_COMPILER_REPO}" target="stage-all" >
            <property name="staging-dir" value="${basedir}/temp/royale-compiler" />
        </ant>
    </target>
    
    <target name="stage-typedefs" >
        <ant dir="${ROYALE_TYPEDEFS_HOME}" target="wipe" />
        <mkdir dir="${staging-dir}/../royale-typedefs"/>
        <copy todir="${staging-dir}/../royale-typedefs" includeEmptyDirs="false" >
            <fileset dir="${ROYALE_TYPEDEFS_HOME}" includes="**" />
        </copy>
    </target>
    
    <target name="stage-top-level" >
        <copy file="${basedir}/npm/js-swf/package.json" todir="${basedir}/temp" />
        <copy todir="${basedir}/temp" includeEmptyDirs="false">
            <fileset dir="${basedir}/releasemgr" includes="**" />
        </copy>
        <!-- use royale-asjs LICENSE at top-level as well for now
             since it doesn't really need to be different -->
        <copy file="${basedir}/LICENSE" todir="${basedir}/temp" />
    </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"/>
        <sleep seconds="3" />
        <mkdir dir="${staging-dir}"/>
       
        <copy todir="${staging-dir}" includeEmptyDirs="true">
            <fileset dir="${basedir}">
                <include name="**"/>
                <exclude name="local.properties"/>
                <exclude name="nightly.properties"/>
                <exclude name="releasecandidate.xml"/>
                <exclude name="ApproveRoyale.xml"/>
                <exclude name=".DS_Store"/>
                <exclude name="**/.DS_Store"/>
                <exclude name=".git/**"/>
                <exclude name="in/**"/>
                <exclude name="out/**"/>
                <exclude name="**/out/**"/>
                <exclude name="**/target/**"/>
                <exclude name="manualtests/**"/>
                <exclude name="marmotinni/**"/>
                <exclude name="mustella/**"/>
                <exclude name="src/site/**"/>
                <exclude name="testsuite/**"/>
                <exclude name="fxg2svg/**"/>
                <exclude name="temp/**"/>
                <exclude name="vf2js/**"/>
                <exclude name="**/RoyaleTest_again/**" />
                <exclude name="**/VanillaSDK_POC/**" />
                <exclude name="**/.plxarc"/>
                <exclude name="**/.settings/**"/>
                <exclude name="frameworks/fb.properties"/>
                <exclude name="frameworks/fonts/**"/>
                <exclude name="frameworks/test*/**"/>
                <exclude name="frameworks/js/VanillaSDK/**"/>
                <exclude name="**/*.iml"/>
                <!-- the below is used in one case as a binary vector format for generating svg vector content -->
                <exclude name="**/*.afdesign"/>
            </fileset>
        </copy>
        
        <tstamp>
            <format property="build.number.date" pattern="yyyyMMdd" />
        </tstamp>
        <property name="build.version" value="${release.version}.${build.number.date}" />
        
        <!-- 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="${staging-dir}/frameworks/air-config-template.xml" version="${build.version}" />
        <echo message="Updating config file royale-config.xml with version ${build.version}"/>
        <fix-config-file file="${staging-dir}/frameworks/royale-config-template.xml" version="${build.version}" />
        <echo message="Updating config file js-config.xml with version ${build.version}"/>
        <fix-config-file file="${staging-dir}/frameworks/js-config-template.xml" version="${build.version}" />
        <echo message="Updating config file jquery-config.xml with version ${build.version}"/>
        <fix-config-file file="${staging-dir}/frameworks/jquery-config-template.xml" version="${build.version}" />
        <echo message="Updating config file ace-config.xml with version ${build.version}"/>
        <fix-config-file file="${staging-dir}/frameworks/ace-config-template.xml" version="${build.version}" />
        <echo message="Updating config file createjs-config.xml with version ${build.version}"/>
        <fix-config-file file="${staging-dir}/frameworks/createjs-config-template.xml" version="${build.version}" />
        <echo message="Updating config file node-config.xml with version ${build.version}"/>
        <fix-config-file file="${staging-dir}/frameworks/node-config-template.xml" version="${build.version}" />
        
        <fixcrlf srcdir="${staging-dir}/bin" eol="crlf" fixlast="false">
            <include name="**/*.bat"/>
        </fixcrlf>
        <fixcrlf srcdir="${staging-dir}/js/bin" eol="crlf" fixlast="false">
            <include name="**/*.bat"/>
        </fixcrlf>
        
        <!-- Unix shell scripts need the correct line endings. -->
        <fixcrlf srcdir="${staging-dir}/bin" eol="unix" fixlast="false">
            <exclude name="**/*.bat"/>
        </fixcrlf>
        <fixcrlf srcdir="${staging-dir}/js/bin" eol="unix" fixlast="false">
            <exclude name="**/*.bat"/>
        </fixcrlf>
        
        <chmod dir="${staging-dir}/js/bin" excludes="**/*.bat" perm="+x" />
        <chmod dir="${staging-dir}/bin" excludes="**/*.bat" perm="+x" />
        
        <!--
             Source files have Windows line endings.  Most UNIX editors can handle
             either type of line endings but the converse is often not true.             
        -->
        <fixcrlf srcdir="${staging-dir}/frameworks" 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"/>
            <exclude name="**/*.swc"/>
        </fixcrlf>
               
        <!-- 
            Unix shell scripts need the correct line endings. 
            The bin directory is handled in stage-bin.
        -->      
        <fixcrlf srcdir="${staging-dir}/" eol="unix" fixlast="false">
            <include name="**.sh"/>
            <exclude name="bin/**"/>
        </fixcrlf>
        
        <!-- delete any left-over empty directories -->
        <delete includeemptydirs="true">
            <fileset dir="${staging-dir}/frameworks/projects">
                <and>
                    <size value="0"/>
                    <type type="dir"/>
                </and>
            </fileset>
        </delete>
        <delete includeemptydirs="true">
            <fileset dir="${staging-dir}/frameworks/js/projects">
                <and>
                    <size value="0"/>
                    <type type="dir"/>
                </and>
            </fileset>
        </delete>
        <delete includeemptydirs="true">
            <fileset dir="${staging-dir}/examples">
                <and>
                    <size value="0"/>
                    <type type="dir"/>
                </and>
            </fileset>
        </delete>

    </target>

    <target name="jsonly-package" if="swf.distribution"
        description="subset binary package to be a js-only package if AIR_HOME is set and we built a SWF+JS package">
        <!-- assumes temp folder contains the binary package with SWF stuff in it -->
        <delete dir="${basedir}/temp/royale-asjs/frameworks/libs" failonerror="false" includeEmptyDirs="true" />
        <mkdir dir="${basedir}/temp/royale-asjs/frameworks/libs" />
        <copy file="${ROYALE_HOME}/js/libs/js.swc"
                tofile="${basedir}/temp/royale-asjs/frameworks/libs/KeepsFBFromHanging.swc" />
        <mkdir dir="${basedir}/temp/royale-asjs/frameworks/libs/player/${playerglobal.version}"/>
        <copy file="${ROYALE_HOME}/js/libs/js.swc" tofile="${basedir}/temp/royale-asjs/frameworks/libs/player/${playerglobal.version}/playerglobal.swc" />
        <mkdir dir="${basedir}/temp/royale-asjs/frameworks/libs/air"/>
        <copy file="${ROYALE_HOME}/js/libs/js.swc" tofile="${basedir}/temp/royale-asjs/frameworks/libs/air/airglobal.swc" />
        <replace token="{playerglobalHome}" value="libs/player" >
            <fileset dir="${staging-dir}/frameworks">
                <include name="air-config.xml"/>
                <include name="airmobile-config.xml"/>
                <include name="createjs-config.xml"/>
                <include name="flex-config.xml"/>
                <include name="jquery-config.xml"/>
                <include name="ace-config.xml"/>
                <include name="js-config.xml"/>
                <include name="node-config.xml"/>
                <include name="royale-config.xml"/>
            </fileset>
        </replace>
        <replace token="&lt;path-element&gt;libs&lt;/path-element&gt;"
                    value="&lt;path-element&gt;js/libs&lt;/path-element&gt;" >
            <fileset dir="${staging-dir}/frameworks">
                <include name="air-config.xml"/>
                <include name="airmobile-config.xml"/>
                <include name="createjs-config.xml"/>
                <include name="flex-config.xml"/>
                <include name="jquery-config.xml"/>
                <include name="ace-config.xml"/>
                <include name="js-config.xml"/>
                <include name="node-config.xml"/>
                <include name="royale-config.xml"/>
            </fileset>
        </replace>
        <replace token="&lt;target&gt;SWF&lt;/target&gt;" value="" >
            <fileset dir="${staging-dir}/frameworks">
                <include name="air-config.xml"/>
                <include name="airmobile-config.xml"/>
                <include name="createjs-config.xml"/>
                <include name="flex-config.xml"/>
                <include name="jquery-config.xml"/>
                <include name="ace-config.xml"/>
                <include name="js-config.xml"/>
                <include name="node-config.xml"/>
                <include name="royale-config.xml"/>
            </fileset>
        </replace>
        <replaceregexp file="${staging-dir}/frameworks/royale-config.xml" match="(\s+?)&lt;path-element&gt;libs\/[^\.]+\.swc&lt;\/path-element&gt;(\s+?)" replace="" flags ="g"/>
        <replace file="${staging-dir}/frameworks/royale-config.xml" token="&lt;path-element&gt;libs/player/{targetPlayerMajorVersion}.{targetPlayerMinorVersion}&lt;/path-element&gt;" value="&lt;path-element&gt;libs/KeepsFBFromHanging.swc&lt;/path-element&gt;"/>
        <!-- replace npm descriptor with js-only descriptor -->
        <antcall target="create-jsonly-description" />
        <copy file="${basedir}/npm/js-only/package.json" todir="${basedir}/temp" overwrite="true"/>
        <zip destfile="${basedir}/out/${binary-js.kit}.zip" basedir="${basedir}/temp"/>
        <tar-gzip name="${binary-js.kit}" />
    </target>
    
    <target name="binary-package"
        description="Package binary files in zip and tar-gzip file.">

        <antcall target="stage-source"/>
                
        <!-- concat the license file with the binary license file for the 3rd party deps -->
        <concat destfile="${basedir}/temp/LICENSE">
            <filelist dir="${basedir}" files="LICENSE,LICENSE.bin"/>
        </concat>
        
    	<antcall target="copy-gcl-from-goog-home"/>
    	<antcall target="copy-gcl-from-downloaded"/>
        
        <antcall target="inject-asf-header" />
        <antcall target="binary-package-zip"/>
        <antcall target="binary-package-tgz"/>
        <!--<copy todir="${basedir}/out" file="${basedir}/apache-royale-installer-config.xml" />-->
    </target>

	<target name="copy-gcl-from-goog-home" if="GOOG_HOME">
		<echo message="Copying GCL from ${GOOG_HOME}"></echo>
		<copy todir="${staging-dir}/js/lib/google/closure-library">
			<fileset dir="${GOOG_HOME}" >
                <include name="**"/>
                <exclude name="closure/goog/crypt/**" />
            </fileset>
		</copy>
	</target>
	
	<target name="copy-gcl-from-downloaded" unless="GOOG_HOME">
		<echo message="Copying GCL from ${staging-dir}/js/lib/google/closure-library"></echo>
		<copy todir="${staging-dir}/js/lib/google/closure-library">
			<fileset dir="${basedir}/js/lib/google/closure-library" >
                <include name="**"/>
                <exclude name="closure/goog/crypt/**" />
            </fileset>
		</copy>
        <property name="GOOG_HOME" value="${staging-dir}/js/lib/google/closure-library" />
        <property name="env.GOOG_HOME" value="${staging-dir}/js/lib/google/closure-library" />
	</target>
	
    <target name="tweak-for-jsonly" unless="swf.distribution" description="do a few more things so the JSOnly package works">
        <copy file="${ROYALE_HOME}/js/libs/js.swc"
        tofile="${ROYALE_HOME}/frameworks/libs/KeepsFBFromHanging.swc" failonerror="false"/>
        <copy file="${basedir}/npm/js-only/package.json" todir="${basedir}/temp" overwrite="true"/>
        <antcall target="fixup-royale-config" />
    </target>
    
    <target name="check-royale-config">
        <condition property="royale-config-fixed">
                <resourcecontains resource="${ROYALE_HOME}/frameworks/royale-config.xml" substring="KeepsFBFromHanging.swc" />
        </condition>
    </target>
    
    <target name="fixup-royale-config" depends="check-royale-config" unless="royale-config-fixed">
        <replaceregexp file="${ROYALE_HOME}/frameworks/royale-config.xml" match="(\s+?)&lt;path-element&gt;libs\/[^\.]+\.swc&lt;\/path-element&gt;(\s+?)" replace="" flags ="g"/>
        <replace file="${ROYALE_HOME}/frameworks/royale-config.xml" token="&lt;path-element&gt;libs/player/{targetPlayerMajorVersion}.{targetPlayerMinorVersion}&lt;/path-element&gt;" value="&lt;path-element&gt;libs/KeepsFBFromHanging.swc&lt;/path-element&gt;"/>
    </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="royale-asjs/bin/**" />
                        <exclude name="royale-asjs/js/bin/**" />
                        <exclude name="**/*.sh" />
                    </tarfileset>
                    <tarfileset dir="${basedir}/temp" prefix="@{name}">
                        <include name="royale-asjs/bin/*.bat" />
                        <include name="royale-asjs/js/bin/*.bat" />
                    </tarfileset>
                    <tarfileset dir="${basedir}/temp" prefix="@{name}" filemode="755">
                        <include name="royale-asjs/bin/*" />
                        <include name="royale-asjs/js/bin/*" />
                        <include name="**/*.sh" />
                        <exclude name="royale-asjs/bin/*.bat" />
                        <exclude name="royale-asjs/js/bin/*.bat" />
                    </tarfileset>
                </tar>
        </sequential>
    </macrodef>	
    
    <!--
	    Update various files for a new release version.
     -->
    <target name="update-version">
        <fail message="old-version and new-version must be set in the form major.minor.hotfix i.e. 0.7.0">
            <condition>
                <or>
                    <not>
                        <isset property="old-version"/>
                    </not>
                    <not>
                        <isset property="new-version"/>
                    </not>
                </or>
            </condition>
        </fail>
        <replace file="${ROYALE_HOME}/build.properties"
            token="${old-version}"
            value="${new-version}" />
        <replace file="${ROYALE_HOME}/nightly.properties"
            token="${old-version}"
            value="${new-version}" />
        <replace file="${ROYALE_HOME}/installer.xml"
            token="${old-version}"
            value="${new-version}" />
        <replace dir="${ROYALE_HOME}/examples"
            token="&lt;versionNumber&gt;${old-version}&lt;/versionNumber&gt;"
            value="&lt;versionNumber&gt;${new-version}&lt;/versionNumber&gt;" >
            <include name="**/*-app.xml"/>
        </replace>
        <echo>Don't forget to update JIRA to indicate current version is released and add new version</echo>
    </target>
    
	<!--
	    Update all frameworks Version.as files in the kit stagging area with the 
	    latest version build number info.
	    
	    You need to place the AntelopeTasks_*.jar jar file in the anttask.classpath
	    in order to do this.  If the jar isn't found, the update is skipped.
	-->
	<target name="version-update"
	    description="Update all frameworks/Version.as files">

        <available property="have.greptask"
            classname="ise.antelope.tasks.Find" 
            classpathref="anttask.classpath"/>
        
        <antcall target="have-greptask"/>
        <antcall target="no-greptask"/>
    </target>

    <target name="have-greptask" if="have.greptask">
		<taskdef name="grep" classname="ise.antelope.tasks.Find"
                 classpathref="anttask.classpath"/>                 

        <echo message="Updating all frameworks/projects/**/Version.as files with version ${release.version}.${build.number.date}"/>
		
        <!-- Update all Version.as files in the kit frameworks directory-->
        <replaceregexp>
            <regexp pattern='"[0-9].[0-9].[0-9].[0-9]";'/>
            <substitution expression='"${release.version}.${build.number.date}";'/>
            <fileset dir="${ROYALE_HOME}/temp/frameworks/projects">
                <include name="**/Version.as"/>
            </fileset>
        </replaceregexp>		
    </target>

    <target name="no-greptask" unless="have.greptask">
        <echo message="Version files not updated."/>
        <echo message="AntelopeTasks_*.jar not found in anttask.classpath"/>
    </target>   
    
    <target name="asdoc-package" description="Package the asdocs">      
        <antcall target="clean-temp"/>
        <antcall target="asdoc"/>
        <property name="doc_output" value="${basedir}/asdoc-output" />
        <copy todir="${staging-dir}/asdoc">
            <fileset dir="${doc_output}"/>
        </copy>
        <copy todir="${staging-dir}/asdoc" file="${basedir}/NOTICE" />
        <copy tofile="${staging-dir}/asdoc/LICENSE" file="${basedir}/LICENSE.base" />
        <zip file="${basedir}/out/${kit.prefix}-asdocs.zip" basedir="${staging-dir}"/>
        <antcall target="clean-temp"/>
    </target>

    <target name="clean-temp" unless="noclean.temp">
        <delete dir="${staging-dir}" failonerror="false" includeEmptyDirs="true"/>
    </target>

    <!--
        Tests: The current checkintests that must be run before every checkin
    -->

    <target name="checkintests" depends="checkintests-clean,basictests-mustella,basictests-marmotinni" description="Run these tests before every checkin" unless="skipTests" />
    
    <!--
     Tests: Marmotinni checkintests
     -->
    
    <target name="basictests-marmotinni" depends="marmotinni-setup,basictests-js" unless="skipTests"/>

    <target name="marmotinni-setup"  description="download and set up marmotinni" unless="skipTests">
        <subant target="main" >
            <fileset dir="${basedir}/marmotinni/java" includes="downloads.xml"/>
        </subant>
        <ant dir="${basedir}/mustella"/>
    </target>
    
    <target name="basictests-js" depends="basictests-compile-js,basictests-compile-java,basictests-run-js" unless="skipTests"/>
    
    <target name="basictests-run-js" unless="skipTests" >
        <property name="profile_arg" value="dummy=false" />
        <echo>GECKODRIVER_HOME=${env.GECKODRIVER_HOME}</echo>
        <echo>url=file://${basedir}/mustella/tests/basicTests/bin/js-debug/index.html</echo>
        <echo>script=${basedir}/mustella/tests/basicTests/halo/scripts/ButtonTestScript.mxml</echo>
        <echo>script=${basedir}/mustella/tests/basicTests/halo/scripts/CheckBoxTestScript.mxml</echo>
		<java classname="marmotinni.MarmotinniRunner" classpath="${basedir}/mustella/target/classes" fork="true" failonerror="yes">
            <sysproperty key="webdriver.gecko.driver" value="${env.GECKODRIVER_HOME}" />
		    <!--<arg value="browser=chrome" />-->
		    <arg value="url=file://${basedir}/mustella/tests/basicTests/bin/js-debug/index.html" />
		    <arg value="script=${basedir}/mustella/tests/basicTests/halo/scripts/ButtonTestScript.mxml" />
		    <arg value="script=${basedir}/mustella/tests/basicTests/halo/scripts/CheckBoxTestScript.mxml" />
		    <!--<arg value="showSteps=true" />-->
		    <arg value="${profile_arg}" />
            <classpath>
                <pathelement location="${basedir}/marmotinni/java/lib/selenium/client-combined-3.141.59.jar"/>
                <pathelement location="${basedir}/marmotinni/java/lib/selenium/libs/byte-buddy-1.8.15.jar"/>
                <pathelement location="${basedir}/marmotinni/java/lib/selenium/libs/commons-exec-1.3.jar"/>
                <pathelement location="${basedir}/marmotinni/java/lib/selenium/libs/guava-25.0-jre.jar"/>
                <pathelement location="${basedir}/marmotinni/java/lib/selenium/libs/okhttp-3.11.0.jar"/>
                <pathelement location="${basedir}/marmotinni/java/lib/selenium/libs/okio-1.14.0.jar"/>
            </classpath>
		</java>

    </target>
    
    <target name="basictests-compile-js" depends="load-task" unless="swf.distribution">
        <property name="ROYALE_HOME" value="${ROYALE_HOME}"/>
        <property name="ROYALE_COMPILER_HOME" value="${ROYALE_HOME}/js"/>
        <property name="GOOG_HOME" value="${env.GOOG_HOME}"/>
        <echo message="ROYALE_HOME: ${ROYALE_HOME}"/>
        <echo message="ROYALE_COMPILER_HOME: ${ROYALE_COMPILER_HOME}"/>
        <echo message="GOOG_HOME: ${GOOG_HOME}"/>
        <delete dir="${basedir}/mustella/tests/basicTests/bin" failonerror="false" />
        <mxmlc fork="true" debug="true"
            closure-lib="${env.GOOG_HOME}"
            file="${basedir}/mustella/tests/basicTests/BasicTestsApp.mxml">
            <jvmarg line="${mxmlc.jvm.args}"/>
            <targets>JSRoyale</targets>
            <library-path dir="${ROYALE_HOME}">
                <include name="mustella/mustella.swc"/>
            </library-path>
            <js-external-library-path dir="${basedir}">
                <include name="js/libs/js.swc"/>
            </js-external-library-path>
            <js-library-path dir="${basedir}" >
                <include name="frameworks/js/libs"/>
            </js-library-path>
            <js-library-path dir="${ROYALE_HOME}" append="true">
                <include name="mustella/mustella.swc"/>
            </js-library-path>
            <arg value="-sdk-js-lib=${ROYALE_HOME}/mustella/js" />
        </mxmlc>
    </target>
    
    <target name="basictests-compile-java" depends="marmotinni-setup" unless="skipTests">
        <delete dir="${basedir}/mustella/java/bin"/><!-- the old folder-->
        <delete dir="${basedir}/mustella/target/classes"/>
        <mkdir dir="${basedir}/mustella/target/classes"/>
        <javac srcdir="${basedir}/mustella/src/main/java" destdir="${basedir}/mustella/target/classes" debug="off" optimize="on">
            <classpath>
                <pathelement location="${basedir}/marmotinni/java/lib/selenium/client-combined-3.141.59.jar"/>
                <pathelement location="${basedir}/marmotinni/java/lib/selenium/libs/byte-buddy-1.8.15.jar"/>
                <pathelement location="${basedir}/marmotinni/java/lib/selenium/libs/commons-exec-1.3.jar"/>
                <pathelement location="${basedir}/marmotinni/java/lib/selenium/libs/guava-25.0-jre.jar"/>
                <pathelement location="${basedir}/marmotinni/java/lib/selenium/libs/okhttp-3.11.0.jar"/>
                <pathelement location="${basedir}/marmotinni/java/lib/selenium/libs/okio-1.14.0.jar"/>
            </classpath>
        </javac>
    </target>
    
    <!--
        Tests: Mustella checkintests
    -->

    <target name="basictests-mustella" depends="mustella-setup,basictests" if="swf.distribution" unless="skipTests"/>

    <target name="mustella-setup" depends="prebuild,runtime-setup" description="compile mustella java file"  if="swf.distribution" unless="skipTests">
        <ant dir="${basedir}/mustella" />
    <!--
        <ant dir="${basedir}/mustella" target="makemustellaswc">
            <property name="use_mustella_framework_dir" value="false"/>
        </ant>
        <property name="moreCompilerArgs" value=""/> -->
        <!-- compile the results parser -->
    <!--<javac srcdir="mustella" includes="MustellaResultsParser.java"/>-->
    </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" if="swf.distribution"
        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}/js/lib/compiler-royaleTasks.jar"/>
    </target>

    <target name="basictests" depends="load-task,basictests-compile-java" description="run basic tests using mustella"  if="swf.distribution" unless="skipTests">
        <property name="ROYALE_COMPILER_HOME" value="${basedir}/js" />
        <property name="ROYALE_HOME" value="${basedir}" />
        <mxmlc fork="true" debug="true"
               closure-lib="${env.GOOG_HOME}"
               file="${basedir}/mustella/tests/basicTests/BasicTestsApp.mxml">
            <jvmarg line="${mxmlc.jvm.args}"/>
            <library-path dir="${ROYALE_HOME}" append="true">
                <include name="mustella/mustella.swc"/>
            </library-path>
            <js-external-library-path dir="${basedir}">
                <include name="js/libs/js.swc"/>
            </js-external-library-path>
            <js-library-path dir="${basedir}" >
                <include name="frameworks/js/libs"/>
            </js-library-path>
            <js-library-path dir="${ROYALE_HOME}" append="true">
                <include name="mustella/mustella.swc"/>
            </js-library-path>
            <arg value="-sdk-js-lib=${ROYALE_HOME}/mustella/js" />
            <arg value="+env.PLAYERGLOBAL_HOME=${env.PLAYERGLOBAL_HOME}" />
        </mxmlc>
        <mkdir dir="${basedir}/mustella/tests/basicTests/fonts" />
        <copy todir="${basedir}/mustella/tests/basicTests/fonts" failonerror="false">
            <fileset dir="${ROYALE_HOME}/frameworks/fonts">
                <include name="**/*.swf" />
            </fileset>
        </copy>
        <!-- compile supporting swfs for basic tests
        <mxmlc fork="true"
               file="${basedir}/frameworks/tests/basicTests/basicLoader.as">
            <jvmarg line="${mxmlc.jvm.args}"/>
        </mxmlc>
        <mxmlc fork="true"
               file="${basedir}/frameworks/tests/basicTests/spark/views/StyleManagerModuleTest.mxml">
            <jvmarg line="${mxmlc.jvm.args}"/>
        </mxmlc>
        <mxmlc fork="true"
               file="${basedir}/frameworks/tests/basicTests/spark/views/HelloWorld.mxml"
                     static-rsls="false"
                     remove-unused-rsls="true" >
            <jvmarg line="${mxmlc.jvm.args}"/>
        </mxmlc>
         -->
        <!-- run the component smoke -->
        <echo message="launching player and swf ${flash.player} ${basedir}/mustella/tests/basicTests/BasicTestsApp.swf"/>
        <exec executable="${flash.player}" dir="${basedir}/mustella/tests/basicTests" failonerror="true">
            <arg value="${basedir}/mustella/tests/basicTests/BasicTestsApp.swf"/>
        </exec>
        <!-- halt if there was an error -->
        <antcall target="mustellaresultsparser"/>
    </target>

    <target name="mustellaresultsparser" unless="skipTests">
        <java classname="mustella.MustellaResultsParser" failonerror="true">
            <sysproperty key="APPDATA" value="${env.APPDATA}"/>
            <classpath>
                <pathelement location="${ROYALE_HOME}/mustella/target/classes"/>
            </classpath>
        </java>
    </target>
    
    <!--
    	MX and Spark emulation tests
    -->
    
    <target name="runmxtests" depends="mxtests-clean,mxtests-mustella" description="Tests MX and Spark emulation code" />
    
    <target name="mxtests-clean">
        <delete file="${basedir}/mustella/tests/mxtests/BasicTests.swf" failonerror="false"/>
        <delete dir="${basedir}/mustella/tests/mxtests/basicTests/bin" failonerror="false" includeEmptyDirs="true"/>
    </target>
    
    <target name="mxtests-mustella" depends="mustella-setup,mxtests" if="swf.distribution" />
    
    <target name="mxtests-compile-java" depends="basictests-compile-java" />
    
    <target name="mxtests" depends="load-task,mxtests-compile-java" description="run MX tests using mustella"  if="swf.distribution">
        <property name="ROYALE_COMPILER_HOME" value="${basedir}/js" />
        <property name="ROYALE_HOME" value="${basedir}" />
        <mxmlc fork="true" debug="true" configname="flex"
               closure-lib="${env.GOOG_HOME}"
               file="${basedir}/mustella/tests/mxtests/basicTests/BasicTests.mxml">
            <jvmarg line="${mxmlc.jvm.args}"/>
            <library-path dir="${ROYALE_HOME}" append="true">
                <include name="mustella/mustella.swc"/>
            </library-path>
            <js-external-library-path dir="${basedir}">
                <include name="js/libs/js.swc"/>
            </js-external-library-path>
            <js-library-path dir="${basedir}" >
                <include name="frameworks/js/libs"/>
            </js-library-path>
            <js-library-path dir="${basedir}" >
                <include name="js/libs/GCL.swc"/>
            </js-library-path>
            <js-library-path dir="${ROYALE_HOME}" append="true">
                <include name="mustella/mustella.swc"/>
            </js-library-path>
            <arg value="-sdk-js-lib=${ROYALE_HOME}/mustella/js" />
            <arg value="+env.PLAYERGLOBAL_HOME=${env.PLAYERGLOBAL_HOME}" />
        </mxmlc>
        <!-- compile supporting swfs for basic tests
        <mkdir dir="${basedir}/mustella/tests/mxtests/basicTests/fonts" />
        <copy todir="${basedir}/mustella/tests/mxtests/basicTests/fonts" failonerror="false">
            <fileset dir="${ROYALE_HOME}/frameworks/fonts">
                <include name="**/*.swf" />
            </fileset>
        </copy>
        <mxmlc fork="true"
               file="${basedir}/frameworks/tests/basicTests/basicLoader.as">
            <jvmarg line="${mxmlc.jvm.args}"/>
        </mxmlc>
        <mxmlc fork="true"
               file="${basedir}/frameworks/tests/basicTests/spark/views/StyleManagerModuleTest.mxml">
            <jvmarg line="${mxmlc.jvm.args}"/>
        </mxmlc>
        <mxmlc fork="true"
               file="${basedir}/frameworks/tests/basicTests/spark/views/HelloWorld.mxml"
                     static-rsls="false"
                     remove-unused-rsls="true" >
            <jvmarg line="${mxmlc.jvm.args}"/>
        </mxmlc>
         -->
        <!-- run the component smoke -->
        <echo message="launching player and swf ${flash.player} ${basedir}/mustella/tests/mxtests/basicTests/BasicTests.swf"/>
        <exec executable="${flash.player}" dir="${basedir}/mustella/tests/mxtests/basicTests" failonerror="true">
            <arg value="${basedir}/mustella/tests/mxtests/basicTests/BasicTests.swf"/>
        </exec>
        <!-- halt if there was an error -->
        <antcall target="mustellaresultsparser"/>
    </target>

    <target name="mxtests-marmotinni" depends="marmotinni-setup,mxtests-js"/>

    <target name="mxtests-js" depends="mxtests-compile-js,mxtests-compile-java,mxtests-run-js" />

    <target name="mxtests-run-js" >
        <property name="profile_arg" value="dummy=false" />
        <echo>url=file://${basedir}/mustella/tests/mxtests/bin/js-debug/index.html</echo>
        <echo>GECKODRIVER_HOME=${env.GECKODRIVER_HOME}</echo>
        <java classname="marmotinni.MarmotinniRunner" classpath="${basedir}/mustella/target/classes" fork="true" failonerror="yes">
            <sysproperty key="webdriver.gecko.driver" value="${env.GECKODRIVER_HOME}" />
            <!--<arg value="browser=chrome" />-->
            <arg value="url=file://${basedir}/mustella/tests/mxtests/basicTests/bin/js-debug/index.html" />
            <arg value="script=${basedir}/mustella/tests/mxtests/basicTests/halo/scripts/ButtonTestScript.mxml" />
            <arg value="script=${basedir}/mustella/tests/mxtests/basicTests/halo/scripts/CheckBoxTestScript.mxml" />
            <arg value="script=${basedir}/mustella/tests/mxtests/basicTests/halo/scripts/RadioButtonTestScript.mxml" />
            <arg value="script=${basedir}/mustella/tests/mxtests/basicTests/halo/scripts/TextInputTestScript.mxml" />
            <arg value="script=${basedir}/mustella/tests/mxtests/basicTests/halo/scripts/TextAreaTestScript.mxml" />
            <arg value="script=${basedir}/mustella/tests/mxtests/basicTests/halo/scripts/ComboBoxTestScript.mxml" />
            <arg value="script=${basedir}/mustella/tests/mxtests/basicTests/halo/scripts/ListAndDataGridTestScript.mxml" />
            <arg value="script=${basedir}/mustella/tests/mxtests/basicTests/halo/scripts/NumericStepperTestScript.mxml" />
            <arg value="script=${basedir}/mustella/tests/mxtests/basicTests/halo/scripts/DateFieldTestScript.mxml" />
            <arg value="script=${basedir}/mustella/tests/mxtests/basicTests/halo/scripts/MenuBarTestScript.mxml" />
            <arg value="script=${basedir}/mustella/tests/mxtests/basicTests/spark/scripts/ButtonTestScript.mxml" />
            <arg value="showSteps=true" />
            <arg value="showScripts=true" />
            <arg value="${profile_arg}" />
            <classpath>
                <pathelement location="${basedir}/marmotinni/java/lib/selenium/client-combined-3.141.59.jar"/>
                <pathelement location="${basedir}/marmotinni/java/lib/selenium/libs/byte-buddy-1.8.15.jar"/>
                <pathelement location="${basedir}/marmotinni/java/lib/selenium/libs/commons-exec-1.3.jar"/>
                <pathelement location="${basedir}/marmotinni/java/lib/selenium/libs/guava-25.0-jre.jar"/>
                <pathelement location="${basedir}/marmotinni/java/lib/selenium/libs/okhttp-3.11.0.jar"/>
                <pathelement location="${basedir}/marmotinni/java/lib/selenium/libs/okio-1.14.0.jar"/>
            </classpath>
        </java>
        
    </target>

    <target name="mxtests-compile-js" depends="load-task" unless="swf.distribution">
        <property name="ROYALE_HOME" value="${ROYALE_HOME}"/>
        <property name="ROYALE_COMPILER_HOME" value="${ROYALE_HOME}/js"/>
        <property name="GOOG_HOME" value="${env.GOOG_HOME}"/>
        <echo message="ROYALE_HOME: ${ROYALE_HOME}"/>
        <echo message="ROYALE_COMPILER_HOME: ${ROYALE_COMPILER_HOME}"/>
        <echo message="GOOG_HOME: ${GOOG_HOME}"/>
        <delete dir="${basedir}/mustella/tests/mxtests/basicTests/bin" failonerror="false" />
        <mxmlc fork="true" debug="true" configname="flex"
            closure-lib="${env.GOOG_HOME}"
            file="${basedir}/mustella/tests/mxtests/BasicTestsApp.mxml">
            <jvmarg line="${mxmlc.jvm.args}"/>
            <targets>JSRoyale</targets>
            <library-path dir="${ROYALE_HOME}" append="true">
                <include name="mustella/mustella.swc"/>
            </library-path>
            <js-external-library-path dir="${basedir}">
                <include name="js/libs/js.swc"/>
            </js-external-library-path>
            <js-library-path dir="${basedir}" >
                <include name="frameworks/js/libs"/>
            </js-library-path>
            <js-library-path dir="${ROYALE_HOME}" append="true">
                <include name="mustella/mustella.swc"/>
            </js-library-path>
            <arg value="-sdk-js-lib=${ROYALE_HOME}/mustella/js" />
        </mxmlc>
    </target>

	<!--
	    Run the Apache Rat audit tool against the source in the source kit.
	    The report is written to rat.report.
	    
	    To check a subset of files run with -Drat.dir=<dir>.
	    
	    You need to place apache-rat-tasks-0.8.jar and apache-rat-0.8.jar in the
	    anttask.classpath in order to do this.  If the jar isn't found, the report
	    will not be generated.
	--> 
    <target name="rat-check" depends="rat-taskdef" if="have.rattasks"
        description="Report on licenses in source kit.">
    
        <property name="rat.dir" value="${basedir}/temp"/>
        <antcall target="rat-unzip" />
        
        <property name="rat.report" value="${basedir}/rat.report"/>
        <echo message="Checking files at ${rat.dir}, report is ${rat.report}"/>
             
        <rat:report xmlns:rat="antlib:org.apache.rat.anttasks" reportFile="${rat.report}">
            <fileset dir="${rat.dir}">
                <exclude name="README.md"/>
                <exclude name="**/README.md"/>
                <exclude name="RELEASE_NOTES.md"/>
                <exclude name="LICENSE.bin"/>
                <exclude name="LICENSE.base"/>
                <exclude name="royale-asjs/DEPENDENCIES"/>
                <exclude name="royale-asjs/README.md"/>
                <exclude name="royale-asjs/LICENSE.bin"/>
                <exclude name="royale-asjs/LICENSE.base"/>
                <!--          Start of binary files           -->
                <!-- exclude media (png, gif, jpg, mp3, flv) -->
                <exclude name="**/*.png"/>
                <exclude name="**/*.gif"/>
                <exclude name="**/*.jpg"/>
                <exclude name="**/*.mp3"/>
                <exclude name="**/*.flv"/>
                <!--          End of binary files           -->
                <!--          JSON doesn't really have a comment format     -->
                <exclude name="**/*.json"/>
                <!--          JSHint properties file           -->
                <exclude name="frameworks/js/jshint.properties"/>
                <exclude name="frameworks/js/.jshintrc"/>
                <exclude name="**/META-INF/DEPENDENCIES" />
                <!--          ide files     -->
                <exclude name="**/.vscode/**"/>
                <!--          royale-compiler -->
                <exclude name="**/org.apache.royale.tools.RoyaleToolGroup"/>
                <exclude name="**/debugger/META-INF/MANIFEST.MF"/>
                <exclude name="**/*.patch"/>
                <exclude name="royale-typedefs/DEPENDENCIES"/>
                <exclude name="royale-compiler/LICENSE.bin"/>
                <exclude name="royale-compiler/README_MAVEN.txt"/>
                <exclude name="royale-compiler/NOTICE.base"/>
                <exclude name="royale-compiler/NOTICE.fdb"/>
                <exclude name="royale-compiler/NOTICE.oem"/>
            </fileset>
        </rat:report>
    </target>

    <target name="rat-unzip" unless="no.zip">
        <antcall target="clean-temp" />
        <unzip src="${basedir}/out/${source.kit}.zip" dest="${rat.dir}"/>
    </target>
    
    <target name="rat-taskdef" description="Rat taskdef"> 
        <available property="have.rattasks" 
            resource="org/apache/rat/anttasks/antlib.xml" 
            classpathref="anttask.classpath"/>

        <antcall target="have-rattasks"/>
        <antcall target="no-rattasks"/>
    </target>

    <target name="have-rattasks" if="have.rattasks">
        <typedef resource="org/apache/rat/anttasks/antlib.xml"
                 uri="antlib:org.apache.rat.anttasks"
                 classpathref="anttask.classpath"/>                 
    </target>
    
    <target name="no-rattasks" unless="have.rattasks">
        <echo message="Rat report not generated."/>
        <echo message="rat jars (apache-rat-*.jar, apache-rat-tasks-*.jar)"/>
        <echo message="not found in anttask.classpath"/>
    </target>
    
    <target name="rat-check-mustella" depends="rat-taskdef" if="have.rattasks"
        description="Report on licenses in mustella directory.">
    
        <ant dir="${basedir}/mustella" target="clean"/>
        
        <property name="rat.mustella.dir" value="${basedir}/mustella"/>
        <property name="rat.mustella.report" value="rat.mustella.report"/>
                
        <echo message="Checking files at ${rat.mustella.dir}, report is ${basedir}/${rat.mustella.report}"/>
             
        <rat:report xmlns:rat="antlib:org.apache.rat.anttasks" 
            reportFile="${basedir}/${rat.mustella.report}">
            <fileset dir="${rat.mustella.dir}">
                <!--          Start of binary files           -->
                <!-- exclude media (png, gif, jpg, mp3, flv) -->
                <exclude name="assets/**"/>
                <exclude name="tests/**/*.png"/>
                <exclude name="tests/**/*.gif"/>
                <exclude name="tests/**/*.jpg"/>
                <exclude name="tests/**/*.mp3"/>
                <exclude name="tests/**/*.flv"/>
                <!--          End of binary files           -->
                <exclude name="tests/**/*.compile"/>
            </fileset>
        </rat:report>
    </target>
	
	<target name="create-SHA-512" >
		<echo message="Generating SHA-512 hashes for release artifacts"/>
		<checksum algorithm="SHA-512" file="${basedir}/out/${binary.kit}.tar.gz" forceOverwrite="yes" fileext=".sha512"/>
		<checksum algorithm="SHA-512" file="${basedir}/out/${binary.kit}.zip" forceOverwrite="yes" fileext=".sha512"/>
		<checksum algorithm="SHA-512" file="${basedir}/out/${source.kit}.tar.gz" forceOverwrite="yes" fileext=".sha512"/>
		<checksum algorithm="SHA-512" file="${basedir}/out/${source.kit}.zip" forceOverwrite="yes" fileext=".sha512"/>
	</target>

    <target name="create-SHA-512-jsonly" if="swf.distribution" >
        <echo message="Generating SHA-512 hashes for release artifacts"/>
        <checksum algorithm="SHA-512" file="${basedir}/out/${binary-js.kit}.tar.gz" forceOverwrite="yes" fileext=".sha512"/>
        <checksum algorithm="SHA-512" file="${basedir}/out/${binary-js.kit}.zip" forceOverwrite="yes" fileext=".sha512"/>
    </target>

    <target name="sign-jsonly" if="swf.distribution" >
        <exec executable="gpg">
            <arg value="--armor" />
            <arg value="--output" />
            <arg value="${basedir}/out/${binary-js.kit}.zip.asc" />
            <arg value="--detach-sig" />
            <arg value="${basedir}/out/${binary-js.kit}.zip" />
        </exec>
        
        <exec executable="gpg">
            <arg value="--armor" />
            <arg value="--output" />
            <arg value="${basedir}/out/${binary-js.kit}.tar.gz.asc" />
            <arg value="--detach-sig" />
            <arg value="${basedir}/out/${binary-js.kit}.tar.gz" />
        </exec>
    </target>

    <target name="sign" >
        <exec executable="gpg">
            <arg value="--armor" />
            <arg value="--output" />
            <arg value="${basedir}/out/${source.kit}.zip.asc" />
            <arg value="--detach-sig" />
            <arg value="${basedir}/out/${source.kit}.zip" />
        </exec>
        
        <exec executable="gpg">
            <arg value="--armor" />
            <arg value="--output" />
            <arg value="${basedir}/out/${source.kit}.tar.gz.asc" />
            <arg value="--detach-sig" />
            <arg value="${basedir}/out/${source.kit}.tar.gz" />
        </exec>
        
        <exec executable="gpg">
            <arg value="--armor" />
            <arg value="--output" />
            <arg value="${basedir}/out/${binary.kit}.zip.asc" />
            <arg value="--detach-sig" />
            <arg value="${basedir}/out/${binary.kit}.zip" />
        </exec>
        
        <exec executable="gpg">
            <arg value="--armor" />
            <arg value="--output" />
            <arg value="${basedir}/out/${binary.kit}.tar.gz.asc" />
            <arg value="--detach-sig" />
            <arg value="${basedir}/out/${binary.kit}.tar.gz" />
        </exec>
    </target>
        
	<target name="doc-create-SHA-512" >
		<echo message="Generating SHA-512 hashes for doc artifacts"/>
		<checksum algorithm="SHA-512" file="${basedir}/out/${kit.prefix}-asdocs.zip" forceOverwrite="yes" fileext=".sha512"/>
	</target>
	
    <target name="doc-sign" >
        <exec executable="gpg">
            <arg value="--armor" />
            <arg value="--output" />
            <arg value="${basedir}/out/${kit.prefix}-asdocs.zip.asc" />
            <arg value="--detach-sig" />
            <arg value="${basedir}/out/${kit.prefix}-asdocs.zip" />
        </exec>
	</target>
	
    <target name="check-if-ide" depends="check-for-airsdk, ask-about-downloading-repos, block-main" />
    <target name="check-for-airsdk" >
        <available file="${basedir}/airsdk.xml"
        type="file"
        property="airsdk.found"/>
    </target>
    <target name="block-main" description="set flags so main targets don't do anything" if="airsdk.found">
        <!-- these keep the main target from doing other checks -->
        <property name="mxmlc.jar.exists" value="set" />
        <property name="ROYALE_COMPILER_REPO" value="set" />
    </target>
    
    <target name="ask-about-downloading-repos" depends="ask-or-fail, download-all" if="airsdk.found" />
    <target name="ask-or-fail" if="airsdk.found" >
        <echo>This folder appears to be an IDE-compatible Royale SDK.</echo>
        <input
        message="Do you want to download and setup the build environment?"
        validargs="y,n"
        defaultvalue="n"
        addproperty="input.all.download"/>
        <condition property="do.all.download">
            <equals arg1="y" arg2="${input.all.download}"/>
        </condition>
        <fail message="Cancelling build.  Builds are not supported in ide-compatible configurations."
        unless="do.all.download"/>
    </target>
    
    <target name="check-git">
        <echo>Checking for Git...</echo>
        <exec executable="git" failonerror="true" >
            <arg value="version" />
        </exec>
    </target>
    
    <target name="get-download-folder" depends="check-git" if="airsdk.found">
        <condition property="defaultPath" value="${env.HOME}/git/apache.royale">
            <os family="mac" />
        </condition>
        <property name="defaultPath" value="c:\git\apache.royale" />
        <input
        message="Enter absolute path to a folder.  The folder will be created if it doesn't exist."
        defaultvalue="${defaultPath}"
        addproperty="base.folder.name"/>
    </target>
    
    <target name="download-all" depends="get-download-folder" if="base.folder.name" >
        <echo>Using folder ${base.folder.name}</echo>
        <mkdir dir="${base.folder.name}" />
        <antcall target="warn-before-clone" />
        <antcall target="clone-royale-asjs" />
        <antcall target="clone-royale-compiler" />
        <antcall target="clone-royale-typedefs" />
        <antcall target="build-all" />
    </target>

    <target name="warn-before-clone" depends="check-royale-asjs" unless="royale-asjs-exists">
        <input
        message="This script will clone 2 repos.  This will take several minutes.  Then it will ask you a few questions then take several more minutes to download more files and compile them.  Press the enter key to continue."
        />
    </target>
    
    <target name="check-royale-asjs">
        <available file="${base.folder.name}/royale-asjs"
        type="dir"
        property="royale-asjs-exists"/>
    </target>
    
    <target name="clone-royale-asjs" depends="check-royale-asjs" unless="royale-asjs-exists">
        <echo>cloning royale-asjs repo into ${base.folder.name}/royale-asjs</echo>
        <exec executable="git" failonerror="true" dir="${base.folder.name}">
            <arg value="clone" />
            <arg value="https://github.com/apache/royale-asjs.git" />
            <arg value="royale-asjs" />
        </exec>
        <exec executable="git" failonerror="true" dir="${base.folder.name}/royale-asjs">
            <arg value="checkout" />
            <arg value="develop" />
        </exec>
        <echo>change directory to ${base.folder.name}/royale-asjs and run ant for future builds.</echo>
    </target>

    <target name="check-royale-compiler">
        <available file="${ROYALE_COMPILER_REPO}"
        type="dir"
        property="royale-compiler-exists"/>
        <available file="${base.folder.name}/royale-compiler"
        type="dir"
        property="royale-compiler-exists"/>
        <available file="${base.folder.name}/royale-compiler"
        type="dir"
        property="ROYALE_COMPILER_REPO"
        value="${base.folder.name}/royale-compiler"/>
    </target>

    <target name="clone-royale-compiler" depends="check-royale-compiler" unless="royale-compiler-exists">
        <echo>cloning royale-compiler repo into ${base.folder.name}/royale-compiler</echo>
        <exec executable="git" failonerror="true" dir="${base.folder.name}">
            <arg value="clone" />
            <arg value="https://github.com/apache/royale-compiler.git" />
            <arg value="royale-compiler" />
        </exec>
        <property name="ROYALE_COMPILER_REPO" value="${base.folder.name}/royale-compiler" />
        <exec executable="git" failonerror="true" dir="${base.folder.name}/royale-compiler">
            <arg value="checkout" />
            <arg value="develop" />
        </exec>
    </target>

    <target name="check-royale-typedefs">
        <available file="${ROYALE_TYPEDEFS_HOME}"
        type="dir"
        property="royale-typedefs-exists"/>
        <available file="${base.folder.name}/royale-typedefs"
        type="dir"
        property="royale-typedefs-exists"/>
        <available file="${base.folder.name}/royale-typedefs"
        type="dir"
        property="ROYALE_TYPEDEFS_HOME"
        value="${base.folder.name}/royale-typedefs"/>
    </target>

    <target name="clone-royale-typedefs" depends="check-royale-typedefs" unless="royale-typedefs-exists">
        <echo>cloning royale-typedefs repo into ${base.folder.name}/royale-typedefs</echo>
        <exec executable="git" failonerror="true" dir="${base.folder.name}">
            <arg value="clone" />
            <arg value="https://github.com/apache/royale-typedefs.git" />
            <arg value="royale-typedefs" />
        </exec>
        <property name="ROYALE_TYPEDEFS_HOME" value="${base.folder.name}/royale-typedefs" />
        <exec executable="git" failonerror="true" dir="${base.folder.name}/royale-typedefs">
            <arg value="checkout" />
            <arg value="develop" />
        </exec>
    </target>

    <target name="build-all" depends="check-playerglobal-home,check-air-home,check-royale-compiler,check-royale-typedefs">
        <property name="font.donot.ask" value="set" />
        <antcall target="ask-before-build-all" />
        <property name="javadoc.zip.uptodate" value="set" /> <!-- javadoc fails on windows? -->
        <ant dir="${ROYALE_COMPILER_REPO}" />
        <ant dir="${ROYALE_TYPEDEFS_HOME}" />
    </target>
    <target name="ask-before-build-all" unless="release.target">
        <input
        message="This script will now download and compile lots of files.  This can take several minutes.   No interaction should be required.  Press the enter key to continue."
        />
    </target>
    
    <target name="all" depends="set.base.folder, download-all, main" />
    <target name="set.base.folder" >
        <property name="base.folder.name" value="${basedir}/.." />
    </target>
    
    <!-- may not work on windows -->
    <target name="inject-asf-header" >
        <replaceregexp match="${generated.by.match}"
            replace="${asfheader}${generated.by.comment}"
            byline="false"
            flags="s">
            <fileset dir="${staging-dir}">
                <include name="**/*.js" />
            </fileset>
        </replaceregexp>
    </target>
    
    <target name="last-message-if-airsdk" if="airsdk.found" >
        <echo>Please change directory to ${base.folder.name}/royale-asjs and run ant to complete build</echo>
    </target>

    <target name="compile" depends="check-compiler-home,check-goog-home,load-task" description="compile for SWF">
        
        <property name="ROYALE_HOME" value="${basedir}" />
        <mxmlc fork="true" debug="true"
            file="${file}">
            <jvmarg line="${mxmlc.jvm.args}"/>
            <arg value="-closure-lib=${GOOG_HOME}" />
            <arg value="-define=COMPILE::SWF,true" />
            <arg value="-define=COMPILE::JS,false" />
        </mxmlc>
    </target>
    
    <target name="compile-release" depends="check-compiler-home,check-goog-home,load-task" description="compile for SWF">
        
        <property name="ROYALE_HOME" value="${basedir}" />
        <mxmlc fork="true" debug="false"
            file="${file}">
            <jvmarg line="${mxmlc.jvm.args}"/>
            <arg value="-closure-lib=${GOOG_HOME}" />
        </mxmlc>
    </target>
    
    <target name="compile-js" depends="check-compiler-home,check-goog-home" description="compile for JS">
        <property name="ROYALE_HOME" value="${basedir}" />
        <java jar="${basedir}/js/lib/mxmlc.jar"
            fork="true">
            <jvmarg line="${mxmlc.jvm.args}"/>
            <jvmarg line="-Droyalelib=${ROYALE_HOME}/frameworks}"/>
            <arg value="+royalelib=${ROYALE_HOME}/frameworks" />
            <arg value="-debug" />
            <arg value="+playerglobal.version=${playerglobal.version}" />
            <arg value="+env.PLAYERGLOBAL_HOME=${env.PLAYERGLOBAL_HOME}" />
            <arg value="-external-library-path=${ROYALE_HOME}/js/libs/js.swc" />
            <arg value="-js-output-type=ROYALE" />
            <arg value="-closure-lib=${GOOG_HOME}" />
            <arg value="-remove-circulars" />
            <arg value="-define=COMPILE::SWF,false" />
            <arg value="-define=COMPILE::JS,true" />
            <arg value="${file}" />
        </java>
    </target>
    
    <target name="compile-js-release" depends="check-compiler-home,check-goog-home" description="compile for JS">
        <property name="ROYALE_HOME" value="${basedir}" />
        <java jar="${basedir}/js/lib/mxmlc.jar"
            fork="true">
            <jvmarg line="${mxmlc.jvm.args}"/>
            <jvmarg line="-Droyalelib=${ROYALE_HOME}/frameworks}"/>
            <arg value="+royalelib=${ROYALE_HOME}/frameworks" />
            <arg value="+playerglobal.version=${playerglobal.version}" />
            <arg value="+env.PLAYERGLOBAL_HOME=${env.PLAYERGLOBAL_HOME}" />
            <arg value="-external-library-path=${ROYALE_HOME}/js/libs/js.swc" />
            <arg value="-js-output-type=ROYALE" />
            <arg value="-closure-lib=${GOOG_HOME}" />
            <arg value="-remove-circulars" />
            <arg value="-define=COMPILE::SWF,false" />
            <arg value="-define=COMPILE::JS,true" />
            <arg value="${file}" />
        </java>
    </target>
    
    <target name="print.geckodriver.version" >
        <exec executable="${webdriver.gecko.driver}" failonerror="true">
            <arg value="--version"/>
        </exec>
    </target>
</project>
