views:

1099

answers:

4

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?

+8  A: 

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.

Gregor Kiddie
Gregor, that's _fantastic_. Thank you!
Chris R
Checkout Rick's answer which uses the include-sources element. Seems to be a more elegant solution.
paul_sns
A: 

Hi there, Does this ant script includes images and all assets in the library too? If not, do you know a way to do it?

Thanks, Victor

Victor
A: 

You can use Maven. It's a configuration management tool rather than just a build tool. It does rely on your project having a manifest file.

Andrew Aylett
Can you provide a concrete example? Ideally one that integrates with FB4 for development.
Chris R
+1  A: 

Lucky for you I JUST solved this problem and was looking for the answer to another problem!

    <compc output="${basedir}/mySwc.swc" locale="en_US">
        <source-path path-element="${basedir}/src/main/flex"/>
        <include-sources dir="${basedir}/src/main/flex" includes="*" />
        <load-config filename="${basedir}/fb3config.xml" />
    </compc>

The source-path is necessary to tell it what to look at when trying to resolve various references. The include-sources tells it which sources to include (obviously in this case all of them). The load-config is just the -dump-config output from Flex Builder.

Hope this helps!!

Rick Herrick
Will this include assets such as images and CSS files?
Chris R