Stop Coding!

The Unofficial Flex Compiler Blog

Ant Tasks for HFCD Now Available

with 6 comments

Hello, a couple of months ago, I was asked by some developers about adding support for Apache Ant. They wanted to have ant support because they either wanted to use HFCD in their build processes or they used Flex IDEs (IntelliJ IDEA, FDT, etc) other than Flex Builder. I thought that sounded right plus, I planned on doing that anyway. So, I went ahead and implemented it. It’s now available in the latest HFCD build (just updated yesterday).

My last post showed an example of build.xml using the ant tasks for HFCD. I’ll make the user’s guide available this weekend. But I’m going to briefly explain the basic syntax here.

<hfcd>

First of all, you need to define the ant task in your build.xml. For HFCD, this means you need the following <taskdef> in your build.xml:

    <taskdef name="hfcd" classname="hellfire.tools.ant.HFCD"/>

Whenever you use <taskdef>, you need to tell ant where the class is. In this case, I specify the location of the class like this:

    > ant -lib /Applications/HFCD/3.3.0/client/lib/hfcd-ant-tasks.jar -file build.xml

In your target definition, you use the <hfcd> task to communicate with the HFCD server:

    <target name="main">
        <hfcd>
            ...
        </hfcd>
    </target>

The supported tag attributes are:

  • hostname – the HFCD server hostname or IP address. default is 127.0.0.1
  • compilerPort – the compiler port number. default is 50207
  • adminPort – the admin port number. default is 50208.
  • clean – ask hfcd to clean the builds. default is false.
  • close – ask hfcd to save build data and clean the builds. default is false.
  • gc – ask hfcd to run garbage collection. default is false.
  • license – license file location. default is $HOME/.hfcd/license.dat.

Usually you don’t use the ‘clean’, ‘close’ and ‘gc’ attributes in your main ant target. Instead, you use them in two separate ant targets:

    <target name="clean">
        <hfcd clean="true"/>
    </target>

    <target name="close">
        <hfcd close="true" gc="true"/>
    </target>

There are three supported nested elements for <hfcd>:

  • <watcher> – upload files and directories to HFCD
  • <application> – build Flex applications
  • <library> – build Flex libraries

There should be exactly one <watcher> element and one or more <application> or <library> in the main ant target.

<watcher>

The <watcher> element uploads files and directories to HFCD. It supports two nested elements:

  • <fileset>
  • <dirset>

If you’ve used ant before, my guess is that you are already very familiar with these two tasks. You must have at least one or more <fileset> or <dirset> within <watcher>.

<application>

Each <application> element defines one Flex application/module for HFCD to build. The following is a list of supported tag attributes:

  • id – an unique identifier string for this <application> element
  • output – target SWF destination. It must be an absolute path.
  • depends – a comma-separated list of identifier strings. This defines which <application>(s) or <library>(s) should be built before this <application>.
  • description – a string that describes what this <application> does.

The <application> element supports two nested elements:

  • <fileset>
  • <configuration> – mxmlc/compc command-line compiler options.

<library>

Each <library> element defines one Flex library for HFCD to build. The following is a list of supported tag attributes:

  • id – an unique identifier string for this <library> element
  • output – target SWF destination. It must be an absolute path.
  • depends – a comma-separated list of identifier strings. This defines which <library>(s) should be built before this <library>.
  • description – a string that describes what this <library> does.

The <library> element supports two nested elements:

  • <components> – a list of space-separated source file names, class names or namespaces
  • <resourceBundles> – a list of space-separated resource bundle names
  • <archiveFile> – defines a file (e.g. an image) that needs to be included in the target SWC
  • <styleSheet> – defines a stylesheet (e.g. a CSS file) that needs to be included in the target SWC.
  • <configuration> – mxmlc/compc command-line compiler options.

<components>

You use the <components> element to group source files, class names or namespaces. How? For a group of source files, you use nested <fileset> elements.

    <components>
        <fileset dir="..." includes="**/*.as"/>
    </components>

For a group of class names, you simply specify a list of class name in a CDATA section.

    <components>
        org.stopcoding.MyButton
        org.stopcoding.MyTextField
        org.stopcoding.MyComboBox
    </components>

For a group of namespaces, you use nested <uri> elements.

    <components>
        <uri>http://www.adobe.com/2006/mxml</uri>
        <uri>http://stopcoding.org/2010/MyLib</uri>
    </components>

<resourceBundles>

You use the <resourceBundles> element to specify resource bundles in a CDATA section.

    <resourceBundles>
        core
        controls
        managers
    </resourceBundles>

<archiveFile> and <styleSheet>

Each <archiveFile> and <styleSheet> element defines one entry in the target SWC file. They both support the same two tag attributes.

  • name – name of the file entry in the target SWC file
  • file – a file path of an image, SWF and CSS stylesheet. The path must be an absolute path.
    <archiveFile name="Assets.swf" file="absolute path to Assets.swf"/>
    <styleSheet name="defaults.css" file="absolute path to defaults.css"/>

<configuration>

You use the <configuration> element to specify compiler options in a CDATA section.

    <configuration>
        --locale=
        --strict=true
        --library-path ...
    </configuration>

You must use double-quotes to quote paths that have spaces in them.

Generate build.xml Automatically!

If you feel somewhat overwhelmed by the above syntax description, don’t worry. You can always learn by examples. One of the features I added in the latest update is the ability for HFCD to automatically generate build.xml for you. You may notice that in the ‘HFCD View’ pull-down menu, there is now a new pull-down menu item “Generate Apache Ant build.xml“.

Once HFCD successfully builds your applications and libraries in the Flex Builder workspace, you may use this new feature to generate a build.xml file.

A number of things you should pay attention to about the generated build.xml:

  • The generated build.xml should ‘just work’. But you should always examine it for correctness.
  • You may need to change the HFCD server IP address at the top of build.xml.
  • You should check the <watcher> task to see if it’s setup to upload too many necessary files to HFCD.
  • HFCD must be running before you run ant.
  • HFCD currently only accepts one network connection at a time (but this may change). If FB is already connected to HFCD, your build.xml will fail to connect to the same HFCD server.

You can download HFCD here:

HFCD 3: http://stopcoding.org/hfcd/3/download

HFCD 4: http://stopcoding.org/hfcd/4/download

That’s it for now. Happy coding!

Advertisements

Written by Clement Wong

January 15, 2010 at 7:18 pm

6 Responses

Subscribe to comments with RSS.

  1. Hi, I am very interested in your Hell Fire Compiler project and would like to test it with FDT as I very rarely (read: never) use Flex Builder.

    However, I notice that the downloads are mainly for Flex Builder 3 and Flash Builder 4.

    Would you mind explaining which installer we need to download and how to set up build environment for use with ANT in an alternative Flash IDE?

    Thanks in advance

    George

    George

    January 19, 2010 at 7:52 am

  2. […] in the “main” target. For more information on the ant task syntax, please check out my previous post. Possibly related posts: (automatically generated)Configuring Flex Builder to use the HellFire […]

  3. […] Compiler Daemon, hfcd, IntelliJ IDEA I’ve just produced some performance benchmark for HFCD Ant tasks and would like to share one test result with […]

  4. […] Ant Tasks for HFCD Now Available […]

  5. I am tried clicking the generate Ant build file and it creates a build.xml file in Eclipse, but the file is empty… no ant syntax at all.

    Jason

    December 1, 2010 at 4:45 pm


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: