Stop Coding!

The Unofficial Flex Compiler Blog

Posts Tagged ‘Apache Ant

HFCD 3 Is Now Officially Available! HFCD 4 Coming Soon.

Hi, I’m pleased to announce that HFCD 3 is now officially available. I have moved the product pages, downloads and documentation to the official product site:

http://bytecode-workshop.com

Bytecode Workshop, Inc. is now responsible for developing, marketing and supporting HFCD.

As I mentioned previously, HFCD 4 will remain in beta.

Advertisements

Written by Clement Wong

March 19, 2010 at 5:11 pm

Flex Compiler Code For HFCD Now Available Under MPL

I think all of you know that the Flex compiler code is licensed under Mozilla Public License. That means if you change the code and use it in your product, you have to make your change available under MPL. Just a moment ago, I put my source code changes (as a zip file) into the RC2 installers. If you have previously downloaded the RC2 installer and are not interested in the source code, please disregard this notice. If you are interested in the code change, especially if you’ve also made changes to the compiler code yourself for your work and want to use HFCD, please download the RC2 installers again.

The following is only applicable to HFCD 3.

In the HFCD/3.x.x directory, you should find ‘server_sdk_diff.zip’. Unzip this file and you should see these source files:

modules/compiler/src/java/flex2/compiler/Source.java
modules/compiler/src/java/flex2/compiler/as3/BytecodeEmitter.java
modules/compiler/src/java/flex2/compiler/io/FileUtil.java
modules/compiler/src/java/flex2/tools/flexbuilder/BuilderApplication.java
modules/compiler/src/java/flex2/tools/flexbuilder/BuilderConfiguration.java
modules/compiler/src/java/flex2/tools/flexbuilder/BuilderLibrary.java
modules/compiler/src/java/flex2/tools/oem/Application.java
modules/compiler/src/java/flex2/tools/oem/Builder.java
modules/compiler/src/java/flex2/tools/oem/Configuration.java
modules/compiler/src/java/flex2/tools/oem/Library.java
modules/compiler/src/java/flex2/tools/oem/PathResolver.java
modules/compiler/src/java/flex2/tools/oem/Toolkit.java
modules/compiler/src/java/flex2/tools/oem/VirtualLocalFile.java
modules/compiler/src/java/flex2/tools/oem/VirtualLocalFileSystem.java
modules/compiler/src/java/flex2/tools/oem/internal/ApplicationCompilerConfiguration.java
modules/compiler/src/java/flex2/tools/oem/internal/OEMConfiguration.java
modules/compiler/src/java/flex2/tools/oem/internal/OEMPathResolver.java
modules/compiler/src/java/flex2/tools/oem/internal/OEMReport.java
modules/compiler/src/java/flex2/tools/oem/internal/OEMUtil.java
modules/swfutils/src/java/flash/swf/SwfEncoder.java

Copy all of these files on top of a fresh copy of Flex SDK compiler. Apply your own compiler changes on top of my changes and rebuilt mxmlc.jar, flex-compiler-oem.jar and swfutils.jar. Put these three jar files into HFCD/3.x.x/server/lib and you’re all set.

Note:

  1. Uninstall HFCD before you run the installer again.
  2. You don’t rebuild the jars if you’ve never modified the compiler for your work.
  3. The change works for HFCD but it may not work for your other situations. Don’t use it for anything other than incorporating your compiler changes into HFCD.

Happy hacking.

Written by Clement Wong

March 12, 2010 at 3:44 pm

HFCD 3 Release Candidate 2 Ready.

Hi guys,

I’ve just upgraded HFCD 3 to Release Candidate 2 and the official release is… “right around the corner”. 🙂 I’ve also updated stopcoding.org. Please check it out. The installation guide and user guide are also available.

Installation Guide: http://stopcoding.org/hfcd/doc/HFCD-3-Installation-Guide.pdf

User Guide: http://stopcoding.org/hfcd/doc/HFCD-3-User-Guide.pdf

HFCD 4 will remain in beta status, but I will start finalizing it when Flex 4 becomes available.

HFCD 3 will be priced at $59. per-developer license.

If you purchase a copy of HFCD 3 before the HFCD 4 official release, you will be eligible to get a free HFCD 4 upgrade. This upgrade promotion will end when HFCD 4 becomes officially available.

If you have any questions, please email me (hfcd@stopcoding.org).

Written by Clement Wong

March 10, 2010 at 11:24 am

HFCD Ant Tasks Outperform Adobe Flex Ant Tasks…

with 2 comments

I’ve just produced some performance benchmark for HFCD Ant tasks and would like to share one test result with you.

There is a build.xml file in the Flex SDK/frameworks directory. Developers can use this build.xml to build the Flex framework:

  • flex.swc
  • framework.swc
  • framework_rb.swc
  • airframework.swc
  • airframework_rb.swc
  • rpc.swc
  • rpc_rb.swc
  • haloclassic.swc
  • utilities.swc

This build.xml file uses the Flex <compc> ant task to build the SWCs. On my MacBookPro, it takes 52 seconds to build. Here is the screenshot:

Then I rewrite this file using the HFCD <library> ant task. On the same machine, it takes 25 seconds to build. It’s 2X faster than the Adobe Flex ant tasks.

Shweeeet!

Written by Clement Wong

January 29, 2010 at 3:41 pm

Configuring FDT to use the HellFire compiler

with 14 comments

Now that HFCD supports Apache Ant, Flex IDEs other than Flex Builder (e.g. FDT and IntelliJ IDEA) can take advantage of some of the core functionalities of HFCD to improve build performance. In this post I’m going to briefly describe how to configure FDT to use HFCD. I hope to do IntelliJ IDEA in the next post.

First of all, the HFCD installers target Flex Builder. So, if you use FDT, you have to install HFCD manually. Well, it’s really not that bad. Instead of downloading the installers, you download the zip archive (hfcd_3.x.x.zip or hfcd_4.x.x.zip) from stopcoding.org.

Unzip the archive file and run ‘ant client server’ from the command-line.

To start the HFCD server, run ‘hfcd’ in the HFCD_HOME/server/bin directory.

Now, start FDT.

Some developers are already familiar with using Ant in FDT. So, it’s not absolutely necessary to follow my instructions here. But I would do it like the following:

1. Assume that my FDT workspace is empty. For this demo, create the legendary HelloWorld project.

2. Create a generic project called “HFCD Build”. Add a file called “build.xml” to the “HFCD Build” project.

After step 1-2, your FDT workspace directory structure should look like this:

3. build.xml is empty. Let’s add the following code to build.xml.

<?xml version="1.0"?>
<project name="FDT" default="main" basedir=".">
    <taskdef name="hfcd" classname="hellfire.tools.ant.HFCD"/>
    <property name="helloworld.dir" value="${basedir}/../HelloWorld"/>
    <target name="main">
        <hfcd>
            <watcher>
                <fileset dir="${helloworld.dir}"/>
            </watcher>
            <application id="HelloWorld.swf"
                output="${basedir}/HelloWorld.swf"
                description="Building HelloWorld.swf">
                <fileset file="${helloworld.dir}/src/HelloWorld.mxml"/>
                <configuration>
                    --default-size 550 400
                    --default-frame-rate 31
                    --default-background-color 0xFFFFFF
                </configuration>
            </application>
        </hfcd>
    </target>
    <target name="clean">
        <delete failonerror="false">
            <fileset file="${basedir}/HelloWorld.swf"/>
        </delete>
        <hfcd clean="true"/>
    </target>
    <target name="close">
        <hfcd close="true" gc="true"/>
    </target>
</project>

4. Add build.xml to the “Ant” view. Since build.xml uses a 3rd-party ant task, you have to configure how FDT runs the build script and where to locate the ant task definition. Right-click on the build file in the “Ant” view and select “2 Ant Build…”.

5. The “Main” tab shows that ${workspace_loc:/HFCD Build/build.xml} is the build file.

6. In the “Refresh” tab, check “Refresh resources upon completion.” and select “The entire workspace”.

7. In the “Build” tab, disable “Build before launch”.

8. In the “Classpath” tab, click “Add External JARs…” and select hfcd-ant-tasks.jar in the HFCD_HOME/client/lib directory.

9. In the “JRE” tab, select “Run in the same JRE as the workspace”.

Now, you’re all set. Check again to make sure that hfcd is actually running. Then in the “Ant” view, double-click the “main” target. You should see the ant output in the “Console” view…

and HelloWorld.swf in the “HFCD Build” directory. Note that in the “HFCD Build” directory, there is a new directory called “build.hfcd”. This directory stores the list of files that have already been uploaded to HFCD and the build reports. If you delete this directory, all the files and directories specified in the <watcher> task will be uploaded again the next time you run the build script.

As you add more projects to the FDT workspace, you should add <application> and <library> tasks to the same build.xml file – add the tasks within the same <hfcd> task in the “main” target. For more information on the ant task syntax, please check out my previous post.

Written by Clement Wong

January 19, 2010 at 4:52 pm

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!

Written by Clement Wong

January 15, 2010 at 7:18 pm

Coming Soon: Ant Tasks for HFCD

with 2 comments

Since the last update, I’ve been working on bugs and of the many bugs I fixed, 4 of them are critical enough that I think I should update HFCD again this weekend. One of them has been around forever and the rest of them are Windows-related (I really should spend more time on Windows!).

Also, I’ve been working on some Ant tasks for HFCD. The testing is almost done so I think they are likely to be included in the next HFCD update.

So, what it’s like in build.xml? Take a look:

<project name="MyProject" default="main" basedir=".">
    <taskdef name="hfcd" classname="hellfire.tools.ant.HFCD"/>
    <property name="helloworld.dir" value="${basedir}/helloworld"/>
    <property name="myLib.dir" value="${basedir}/myLib"/>
    <target name="main">
        <hfcd>
            <watcher>
                <fileset dir="${basedir}" includes="**/*">
                    <exclude name="build.hfcd/**/*"/>
                    <exclude name="apps/**/*"/>
                    <exclude name="libs/**/*"/>
                    <exclude name="build.xml"/>
                </fileset>
            </watcher>
            <application id="helloworld" depends="myLib"
                    output="${basedir}/apps/helloworld.swf"
                    description="Building apps/helloworld.swf">
                <fileset file="${helloworld.dir}/src/helloworld.mxml"/>
                <configuration>
                    -library-path "${basedir}/libs/myLib.swc"
                </configuration>
            </application>
            <library id="myLib" output="${basedir}/libs/myLib.swc">
                <components>
                    com.foo.Bar
                    com.foo.Baz
                </components>
                <components>
                    <uri>http://www.foobar.com/myLib</uri>
                </components>
                <components>
                    <fileset file="${myLib.dir}/src/com/foo/Foo.as"/>
                </components>
                <configuration>
                    -accessible=true
                    -namespace http://www.foobar.com/myLib
                                 "${myLib.dir}/manifest.xml"
                    -source-path "${myLib.dir}/src"
                <configuration>
            </library>
        </hfcd>
    <target>
    <target name="clean">
        <delete file="${basedir}/apps/helloworld.swf" />
        <delete file="${basedir}/libs/myLib.swc" />
        <hfcd clean="true" />
    <target>
</project>

Don’t worry about the syntax. Once it’s out there, I’ll blog about it in more details.

What’s cool about this is that you can now hook up HFCD with your favorite Flex IDE (as long as your favorite IDE supports Apache Ant)!

Written by Clement Wong

December 16, 2009 at 6:21 pm