Download the SWC Packager ANT task here (source included)

Often, my project workflows include checkouts of other remote code repositories. This means I can directly edit the code and have it immediately compiled into my project, without having to compile an SWC and copy it into my project. This can lead to problems when the project needs to be rolled back to a previous revision (there is no easy way of knowing which revision the remote repositories shuold be checked out at), and issues with remote repositories that are moved/removed.

In the past I have used the SVN externals to achieve this (including using the ‘-r’ option to pin externals to specific revisions), but this solution still didn’t get around repositories that are moved/removed.

I ended up writing an ANT task which can build an SWC based on a Flash Builder project file. This way I could integrate regular SWC creation into my deployment process, backing up all external code.
The ANT task also has the option to export a manifest XML file detailing all of the classes included in the SWC.

These are the compilation arguments taken from the project file:

  • All classpaths & SWC paths
  • Accessibility setting
  • Target flash player

These are the additional options:

  • sdk – a path to the sdk folder. This is used to find the frameworks directory and the compiler.
  • projectPath – a path to the root folder of the project.
  • sourceExceptions (optional) – a comma separated list of source paths to exclude from the SWC (they will still be compiled against, just not included)
  • linkReport (optional) – a path to a link report XML file (as output by the mxmlc compiler), this can be used to specify a list of classes to include. By including the link-report argument in your main project then passing this path to the SWC Packager your SWC will only include classes currently used in your project.
  • includeMainSource (optional) – a boolean specifying whether the main source path should be included in the SWC. Defaults to false.
  • manifestOutput (optional) – a path specifying where the manifest XML file should be saved.
  • computeDigest (optional) – a boolean specifying whether a catalog.xml file should be generated (for use by RSL). Defaults to false.
  • outputAsDirectory (optional) – a boolean specifying whether the compiler should output a folder with AS files instead of an SWC file. Defaults to false.
  • additionalArgs (optional) – additional compiler arguments can be passed through here.
  • configXML (optional) – a string pointing to an additional config XML file.
  • compileDebug (optional) – a boolean specifying whether the debug compiler option should be used. Defaults to false.
  • verbose (optional) – setting this to true will make the SWC Packager print out the full compiler command before executing it. Defaults to false.

When includeMainSource is set to true and a link-report is specified, only classes that meet both conditions will be included.

Here is an example of how the task can be used in your ANT script:

<project name="SWC Packager" basedir="../">
    <property name="FLEX_HOME" value="C:\FlexSDKs\4.5.0" />

    <taskdef name="swcPackager" classpath="${basedir}\build\SWCPackager.jar" classname="org.farmcode.antTasks.SWCPackager"/>
    <target name="Package All Source" description="Builds all AS code into an SWC.">
        <swcPackager sdk="${FLEX_HOME}" projectPath="${basedir}"
                includeMainSource="true" swcOutput="${basedir}/build/allCode.swc" configXML="config.xml"/>
    <target name="Package All Third-party Source" description="Builds all AS code except main src dir into an SWC.">
        <swcPackager sdk="${FLEX_HOME}" projectPath="${basedir}" includeMainSource="false"
                includeMainSource="true" swcOutput="${basedir}/build/thirdPartyCode.swc" configXML="config.xml"/>
    <target name="Package All Referenced Source" description="Builds all referenced AS code except main src dir into an SWC.">
        <swcPackager sdk="${FLEX_HOME}" projectPath="${basedir}" linkReport="${basedir}/build/linkReport.xml"
                includeMainSource="true" swcOutput="${basedir}/build/allReferencedCode.swc" configXML="config.xml"/>

Download the SWC Packager ANT task here (source included)