<!--
Copyright (c) 2007 FlexLib Contributors. See:
http://code.google.com/p/flexlib/wiki/ProjectContributors
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
of the Software, and to permit persons to whom the Software is furnished to do
so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
-->
<project name="flexlib" default="lib">
<!-- Define variables/paths used in this build script -->
<!-- Depending on the host os, fetch relevant prop file -->
<condition property="platformSpecificPropertyFile" value="build.mac.properties">
<os family="mac" />
</condition>
<condition property="platformSpecificPropertyFile" value="build.win.properties">
<os family="windows" />
</condition>
<condition property="platformSpecificPropertyFile" value="build.unix.properties">
<os family="unix" />
</condition>
<property file="./setup/config/${platformSpecificPropertyFile}" />
<property file="./build.properties" />
<!--
Have you edit the properties file to make sure the paths are right on your system?
-->
<target name="properties">
<fail unless="asdoc.exe">The "asdoc.exe" property must be set in ${build.dir}/build.properties.</fail>
<fail unless="compc.exe">The "compc.exe" property must be set in ${build.dir}/build.properties.</fail>
<fail unless="mxmlc.exe">The "mxmlc.exe" property must be set in ${build.dir}/build.properties.</fail>
</target>
<!-- Extension for ANT to allow for tasks like "for" and "propertyregex" -->
<taskdef resource="net/sf/antcontrib/antlib.xml">
<classpath>
<pathelement location="${setup.lib}/ant-contrib-1.0b3.jar" />
</classpath>
</taskdef>
<!-- Cleans project -->
<target name="clean">
<delete dir="${build}" />
<delete dir="${dist}" />
</target>
<!-- creates buid/dist folders -->
<target name="init">
<mkdir dir="${build}" />
<mkdir dir="${build.config}" />
<mkdir dir="${dist}" />
<mkdir dir="${dist.examples}" />
<mkdir dir="${dist.docs}" />
</target>
<!-- Compile the unit tests for the library, placing the test runner .swf file
in the bin directory. -->
<target name="compileTests" depends="init">
<copy tofile="${build.config}/tests-config.xml"
file="${setup.config}/tests-config.template.xml"
overwrite="true" />
<replace file="${build.config}/tests-config.xml">
<replacefilter token="@FLEX_LIBS_HOME@" value="${flexsdk.lib}" />
<replacefilter token="@FLEX_BUILD_VERSION@" value="${flex.version}" />
</replace>
<exec executable="${mxmlc.exe}" dir="${basedir}">
<arg line="'${tests.dir}/${testRunner.dir}/${testRunner.name}.mxml'" />
<arg line="-o ${dist}/${testRunner.name}.swf" />
<arg line="-load-config '${flexsdk.dir}/frameworks/flex-config.xml'" />
<arg line="-load-config ${build.config}/tests-config.xml" />
</exec>
</target>
<!--
Runs the unit tests for the library in the stand-alone Flash Player
-->
<target name="test" depends="compileTests">
<!--
If/When we add support for determining the status of unit tests
as part of the ANT build process, we need to change the spawn to
"no" so that ANT waits until the test runner closes before
proceeding.
-->
<exec executable="${flashDebugPlayer.exe}" spawn="yes">
<arg line="${dist}/${testRunner.name}.swf" />
</exec>
</target>
<!--
Compile all of the classes under the "src" tree into a .swc file
-->
<target name="lib" depends="init">
<copy tofile="${build.config}/flexlib-config.xml"
file="${setup.config}/flexlib-config.template.xml"
overwrite="true" />
<replace file="${build.config}/flexlib-config.xml">
<replacefilter token="@FLEX_SDK@" value="${flexsdk.dir}" />
<replacefilter token="@FLEX_VERSION_3@" value="${flex.version3}" />
<replacefilter token="@FLEX_VERSION_4@" value="${flex.version4}" />
</replace>
<exec executable="${compc.exe}" dir="${basedir}">
<arg line="-o ${dist}/${library.name}.swc" />
<arg line="-load-config '${flexsdk.dir}/frameworks/flex-config.xml'" />
<arg line="-load-config ${build.config}/flexlib-config.xml" />
</exec>
</target>
<target name="release-lib" depends="clean">
<antcall target="lib" />
</target>
<!--
Generate the example applications using the library
-->
<target name="examples_modified">
<condition property="examplesFolder"
value="flex3"
else="flex4">
<equals arg1="${flex.version3}" arg2="true" />
</condition>
<echo>Building ${examplesFolder} modified examples</echo>
<copy tofile="${build.config}/examples-config.xml"
file="${setup.config}/examples-config.template.xml"
overwrite="true" />
<replace file="${build.config}/examples-config.xml">
<replacefilter token="@FLEX_LIBS_HOME@" value="${flexsdk.lib}" />
<replacefilter token="@FLEX_BUILD_VERSION@" value="${flex.version}" />
</replace>
<!--
Loop over all of the Sample applications in the examples directory,
compile them, and place the resulting .swf next to the application
.mxml file.
-->
<for param="file">
<!-- Find the sample applications -->
<fileset dir="${basedir}/examples">
<!--
The modified selector will only select files that have been
modified since the examples target was last run. This means we
can update a single example, then run the examples target and
only the updated example will get recompiled.
-->
<modified />
<include name="**/*_Sample.mxml" />
<!--
For only building specific examples, comment out
the line above, and uncomment the line below and modify
as appropriate.
-->
<!-- include name="**/*_Sample.mxml" / -->
</fileset>
<sequential>
<!-- Pull out the example name and folder -->
<propertyregex property="exampleApplicationName"
override="yes"
input="@{file}"
regexp=".*${file.separator}(.*)_Sample.mxml"
replace="\1" />
<propertyregex property="exampleFolderName"
override="yes"
input="@{file}"
regexp="(.*)${file.separator}(.*)_Sample.mxml"
replace="\1" />
<exec executable="${mxmlc.exe}" dir="${basedir}">
<arg line="'@{file}'" />
<arg line="-o ${dist}/examples/${exampleApplicationName}_Sample.swf" />
<arg line="-load-config '${flexsdk.dir}/frameworks/flex-config.xml'" />
<arg line="-load-config ${build.config}/examples-config.xml" />
</exec>
</sequential>
</for>
</target>
<!--
Exactly the same as examples_modified, except we regenerate all example files,
regardless of whether they've been modified since last run. This is almost line-for-line
the same as the examples_modified target, so all comments have been removed for brevity.
-->
<target name="examples_all">
<condition property="examplesFolder"
value="flex3"
else="flex4">
<equals arg1="${flex.version3}" arg2="true" />
</condition>
<echo>Building all ${examplesFolder} examples</echo>
<copy tofile="${build.config}/examples-config.xml"
file="${setup.config}/examples-config.template.xml"
overwrite="true" />
<replace file="${build.config}/examples-config.xml">
<replacefilter token="@FLEX_LIBS_HOME@" value="${flexsdk.lib}" />
<replacefilter token="@FLEX_BUILD_VERSION@" value="${flex.version}" />
</replace>
<for param="file">
<fileset dir="${basedir}/examples">
<include name="**/${examplesFolder}/**/*_Sample.mxml" />
</fileset>
<sequential>
<propertyregex property="exampleApplicationName"
override="yes"
input="@{file}"
regexp=".*${file.separator}(.*)_Sample.mxml"
replace="\1" />
<propertyregex property="exampleFolderName"
override="yes"
input="@{file}"
regexp="(.*)${file.separator}(.*)_Sample.mxml"
replace="\1" />
<exec executable="${mxmlc.exe}" dir="${basedir}">
<arg line="'@{file}'" />
<arg line="-o ${dist}/examples/${exampleApplicationName}_Sample.swf" />
<arg line="-load-config '${flexsdk.dir}/frameworks/flex-config.xml'" />
<arg line="-load-config ${build.config}/examples-config.xml" />
</exec>
</sequential>
</for>
</target>
<!--
Generate ASDoc output for the library
-->
<target name="docs" depends="init">
<!-- Clean out the contents of the doc directory, without deleting "docs" -->
<delete includeemptydirs="true">
<fileset dir="${dist.docs}" includes="**/*" />
</delete>
<exec executable="${asdoc.exe}" spawn="no">
<arg line="-define+=FLEX_TARGET_VERSION::flex4,${flex.version4} -define+=FLEX_TARGET_VERSION::flex3,${flex.version3}" />
<!-- Place the documentation in the "docs" directory -->
<arg line="-o '${dist.docs}'" />
<!-- Specify the main source path as "src" -->
<arg line="-sp '${src.dir}'" />
<!-- Document all of the classes in the "src" tree -->
<arg line="-ds '${src.dir}' " />
<!-- Include the library name in the window title -->
<arg line="-window-title '${library.name}' " />
<arg line="-templates-path '${flexsdk.templates.dir}' " />
</exec>
</target>
<!--
When the ASDoc files are generated and imported into the SVN
repository, the files need to have mime types set correctly so that
you can open a web browser to the docs in the repository and
have the HTML render correctly. Failure to set the mime types will
result in the doc source being displayed, rather than the docs being
rendered.
This target requires the ANT contrib library in order to run.
-->
<target name="fixDocMimeTypes">
<!-- Loop over the files in the doc directory -->
<for param="file">
<!-- Include the following file types in the target directory as part of the loop -->
<fileset dir="docs">
<include name="**/*.html" />
<include name="**/*.png" />
<include name="**/*.jpg" />
<include name="**/*.css" />
<include name="**/*.js" />
<include name="**/*.gif" />
</fileset>
<sequential>
<!---
Determine the mime-type from the file extension.
-->
<property name="mime.type.html" value="text/html" />
<property name="mime.type.png" value="image/png" />
<property name="mime.type.jpg" value="image/jpeg" />
<property name="mime.type.css" value="text/css" />
<property name="mime.type.js" value="text/plain" />
<property name="mime.type.gif" value="image/gif" />
<!-- Extract the extension from the file name -->
<propertyregex property="fileExtension"
override="yes"
input="@{file}"
regexp=".*${file.separator}([^\\]+)\.([a-zA-Z0-9]+)"
replace="\2" />
<!-- Set the mime.type property based on the extension -->
<propertycopy name="mime.type"
from="mime.type.${fileExtension}"
override="yes" />
<!-- Sanity check...
<echo>@{file} is ${fileExtension} with mime type ${mime.type}</echo>
-->
<!-- Configure the mime type for the file -->
<exec executable="${svn.exe}" spawn="no">
<arg line="propset svn:mime-type '${mime.type}' '@{file}'" />
</exec>
</sequential>
</for>
</target>
<!--
Generate a distribution based on the current source code. Includes
the source code, the documentation, the examples, and the binary .swc file.
-->
<target name="release" depends="clean, init, lib, examples_all, docs">
<!-- Creates the .zip file in the bin directory -->
<zip destfile="${dist}/${library.name}.zip">
<fileset dir="${basedir}">
<include name="bin/${library.name}.swc" />
<include name="src/**" />
<include name="docs/**" />
<include name="examples/**" />
<exclude name="**/*_Sample.swf" />
</fileset>
</zip>
</target>
</project>