How to automate the building of a Flex component library

adobeantapache-flexflex3flexbuilder

I would like to build a flex library project automatically instead of the current process, which involves one of our developers compiling it on his machine and then us checking in the resulting .swc file. It's gross.

I am coming at this from the perspective of a java developer, so I'm having a hard time getting the hang of the compilation tools provided in the Flex Builder 3 application, but here's what I already have:

  1. I have created an ant file that loads the ant task library correctly, and can therefore execute <mxmlc/> and <compc/> tasks.
  2. I have located the source code that I need to build, and know what sort of .swc I want to end up with.

What I want is an ant script that will do the equivalent of these steps:

  1. We build all sources (actionscript and MXML) and assets in the project into an swc file.
  2. The library.swf file is extracted and optimized

So far I have this:

<target name="compile-component" depends="init">
  <compc output="${DEPLOY_DIR}/${SWC_NAME}.swc">
    <source-path path-element="${FLEX_HOME}/frameworks"/>
    <source-path path-element="${SRC_DIR}"/>
  </compc>
</target>

However, it's not including any content:

[compc] Loading configuration file /Applications/Adobe Flex Builder 3/sdks/3.2.0/frameworks/flex-config.xml
[compc] Adobe Compc (Flex Component Compiler)
[compc] Version 3.2.0 build 3958
[compc] Copyright (c) 2004-2007 Adobe Systems, Inc. All rights reserved.
[compc] 
[compc] Error: nothing was specified to be included in the library
[compc] 
[compc] Use 'compc -help' for information about using the command line.

It looks like I need to enumerate every class that I want to include in the library, which is… ludicrous. There must be a better way. How do I do this?

Best Answer

You can do the following... it takes all the files from the source path and converts it to a format that the compc task can then use.

<fileset id="project.test.dir.fileset" dir="${project.test.dir}">
    <include name="**/*.as" />
    <include name="**/*.mxml" />
</fileset>
<property name="project.test.dir.fileset" refid="project.test.dir.fileset" />

<!-- Convert the test files into a compiler friendly format. -->
<pathconvert property="project.test.dir.path" pathsep=" " refid="project.test.dir.fileset">
    <compositemapper>
        <chainedmapper>
            <globmapper from="${project.test.dir}/*" to="*" handledirsep="true" />
            <mapper type="package" from="*.as" to="*" />
        </chainedmapper>
        <chainedmapper>
            <globmapper from="${project.test.dir}/*" to="*" handledirsep="true" />
            <mapper type="package" from="*.mxml" to="*" />
        </chainedmapper>
    </compositemapper>
</pathconvert>

<compc headless-server="true" default-frame-rate="${flex.default-frame-rate}" debug="${flex.compiler.debug.mode}" output="${build.swc.dir}/${test.component.name}.swc" include-classes="${project.test.dir.path}" directory="false">
    <source-path path-element="${project.test.dir}" />
    &dependencies;
</compc>

We use it to produce swcs for testing purposes.