Build Automation via Ant – Facebook Photo Gallery

Using ant macros for extracting swf libary files from the swc runtime shared libraries, compiling the external swf modules, generating the html wrappers. Flex Ant tasks have priority over corresponding exec or java commands. This is the case for compc and mxmlc compilers. For extracting swf libraries from rsls or for generating custom html wrappers, exec commands are used because there are no corresponding flex ant tasks.

There are three related build files: build.properties, asabau_cg3_fb_config.xml, build.xml.

build.properties
Defines build properties used by build.xml including paths for flex sdk, flex compilers, external modules and libraries. FLEX_HOME stands out from the low-case naming convention and is required by all flex ant tasks:

flex.sdk = C:/flex_sdks/3.4.1
FLEX_HOME = ${flex.sdk}
flex.framework = ${flex.sdk}/frameworks/libs

flex.mxmlc = ${flex.sdk}/bin/mxmlc.exe
flex.compc = ${flex.sdk}/bin/compc.exe
flex.asdoc = ${flex.sdk}/bin/asdoc.exe
flex.optimizer = ${flex.sdk}/bin/optimizer.exe
flex.digest = ${flex.sdk}/bin/digest.exe

project.dir = ${basedir}/..
...

asabau_cg3_fb_config.xml
Contains additional compiler options when using mxmlc or compc flex ant tasks. Used for specifying metadata tags required by the Parsley framework that if not listed here won’t make it into the compiled swf/swc file. Extract from this file:

<keep-as3-metadata>
	...
	<name>Metadata</name>
	<name>AsyncInit</name>
	<name>ManagedEvents</name>
	<name>Command</name>
	<name>CommandResult</name>
	<name>CommandError</name>
	<name>CommandStatus</name>
	...
</keep-as3-metadata>

build.xml
Main build file. Contains tasks for compiling each external module and library, as well as a compile_main_launcher task putting it all together:

<target
  name="compile_main_launcher"
  depends="init, compile_api, copyRSLs"
  >
  <compile_module
    input.file="${asabau_cg3_fb_authentication.src.dir}/
    AuthenticationModule.mxml"
    output.file="${release.dir}/AuthenticationModule.swf"
    />
  <compile_module
    input.file="${asabau_cg3_fb_album.src.dir}/AlbumModule.mxml"
    output.file="${release.dir}/AlbumModule.swf"
    />
  <compile_module
    input.file="${asabau_cg3_fb_shell.src.dir}/MainLauncher.mxml"
    output.file="${release.dir}/MainLauncher.swf"
    />

  <custom_html_wrapper
    template.dir="${asabau_cg3_fb_shell.src.dir}/../html-template"
    input.file="index.template.html" output.file="MainLauncher.html"
    application="main"
    title="Facebook Photo Gallery Using Parsley Application Framework"
    swf="MainLauncher" width="1000" height="700" bgcolor="#FFFFFF"
    />
</target>

Before starting to compile the main launcher, some preparation tasks are performed via depends property:

  • init – deletes and recreates the app release directory
  • compile_api – compiles asabau_cg3_fb_api into an external swc file
  • copyRSLs – generates and copies all required rsls to the project release directory

A .swf runtime shared library (rsl) is generated from a swc file by the create-rsl ant macro. A swc file is just an archive containing among other things a library.swf file. This library.swf file represents the runtime-shared-library. One needs to extract library.swf, optimize it to minimize size, update its flex digest signature to prevent runtime conflicts between libraries.

<macrodef name="create-rsl">
  <attribute name="rsl-dir"/>
  <attribute name="swc-dir"/>
  <attribute name="swc-name"/>

  <sequential>
    <unzip src="@{swc-dir}/@{swc-name}.swc" dest="@{rsl-dir}" >
      <patternset>
        <include name="library.swf" />
      </patternset>
    </unzip>

    <exec executable="${flex.optimizer}" failonerror="true">
      <arg line="-input @{rsl-dir}/library.swf
      -output @{rsl-dir}/@{swc-name}.swf"/>
      <arg line="-load-config ${basedir}/asabau_cg3_fb_config.xml"/>
    </exec>

    <delete file="@{rsl-dir}/library.swf"/>

    <exec executable="${flex.digest}" failonerror="true">
      <arg line="-digest.rsl-file  @{rsl-dir}/@{swc-name}.swf"/>
      <arg line="-digest.swc-path  @{swc-dir}/@{swc-name}.swc"/>
    </exec>
    </sequential>

</macrodef>

External modules are compiled using an ant macro like the one below. This makes sense because all external modules need to be compiled against the same external libraries, using the same method.

<compile_module
    input.file="${asabau_cg3_fb_authentication.src.dir}/
    AuthenticationModule.mxml"
    output.file="${release.dir}/AuthenticationModule.swf"
/>

A custom html wrapper macro – custom_html_wrapper – is being used because Flex 3 html-wrapper task doesn’t support generation of custom html code. In this case, swfobject and facebook html/javascript code is required in the main html launcher. This macro just parses an html file replacing all html occurrences of several key elements like ${swf}, ${title} with the input parameters. These elements are found in the exact same form in standard flex html-template/index.template.html files.

<custom_html_wrapper
    template.dir="${asabau_cg3_fb_shell.src.dir}/../html-template"
    input.file="index.template.html"
    output.file="MainLauncher.html"
    application="main"
    title="Facebook Photo Gallery Using Parsley Application Framework"
    swf="MainLauncher" width="1000" height="700" bgcolor="#FFFFFF"
/>

This post is part of Facebook Photo Gallery.

Leave a Reply

Your email address will not be published. Required fields are marked *