Building SWCs with Flex Ant Tasks

2007:10:03

NOTE – This article is no longer relevant. The latest flex ant tasks support including recursive source directories. See comments posted by readers.

Using Flex Ant Tasks with the Flex SDK is a great way to do automated builds for your Flex Projects. Flex Tasks provide Ant task interfaces for compiling both applications (*.swf) and libraries (*.swc).

<compc> Requires Manually Specified Class Names!

The compc task comes up a little short in that you have to specify ALL of your classes you want in your component library like this

<compc

output=“MySWC.swc”

include-classes=“my.package.MyClass1 my.package.MyClass2″>

<source-path path-element=“${basedir}”/>

</compc>

 

Most of the time, I find myself wanting *all* of my actionscript classes in the component library SWC file. More importantly, I do not want to have to update an Ant target if I add classes to the library.

You might ask ‘well why not generate a fileset and pass it to the include-source attribute?’ Great idea except the compc task doesn’t support include-source. Boo!

*Sigh* – it would be nice if I could just have my classes auto-generated for this compilation task!

Use Ant to Auto-generate Class Names

After some googling, I found that there really isn’t a built-in mechanism for doing this. Below you’ll find a sample target I put together that auto-generates the class names to pass to compc based on the actionscript filenames it compiles.

<target name=“swc”>

<fileset id=“sources” dir=“com”>

<include name=“**/*.as”/>

</fileset>

<pathconvert property=“classes” pathsep=” “ refid=“sources”>

<chainedmapper>

<globmapper from=“${basedir}/*” to=“*”/>

<mapper type=“package” from=“*.as” to=“*”/>

</chainedmapper>

</pathconvert>

<echo message=“classes is set to = ${classes}”/>

<compc output=“MySWC.swc” include-classes=“${classes}”>

<source-path path-element=“${basedir}”/>

</compc>

</target>

 

 

 

The target uses the fileset, pathconvert and mapper tasks available in Ant.

  1. It finds all of the actionscript source files with a fileset.
  2. It converts the list of files to a single line with each file separated by a space
  3. Using mappers, it then converts the filename to a package/class name notation

Note that your project should define the ‘basedir’ property in the initial ‘project’ tag.

By using Ant to autogenerate classnames from actionscript filenames, my library build files are alot easier to maintain. Hopefully it’ll do the same for you!


Command-line History Autocomplete in OS-X

2007:10:03

A really nice command-line trick is to enable history autocomplete via up and down arrows. For example, if I am looking for an old ‘grep’ command, I could cycle through all greps in my history simply by typing ‘grep’ UP-ARROW.

All you need to do is add the following lines to the ‘.profile’ file in your home directory.

# make bash autocomplete with up arrow/down arrow
bind '"\e[A":history-search-backward'
bind '"\e[B":history-search-forward'

Note – You’ll need to start a new terminal session for this to take effect.