views:

503

answers:

1

I have been struggling trying to figure out how to conditionally include Flex libraries in an ant build based on a property that is set on the command line. I have tried a number of approaches with the <condition/> task, but so far have not gotten it to work. Here is where I am currently.

I have an init target that includes condition tasks like this:

 <condition property="automation.libs" value="automation.qtp">
  <equals arg1="${automation}" arg2="qtp" casesensitive="false" trim="true"/>
 </condition>

The purpose of this task is to set a property that determines the name of the patternset to be used when declaring the implicit fileset on a mxmlc or compc task. The pattern set referenced above is defined as:

 <patternset id="automation.qtp">
  <include name="automation*.swc"/>
  <include name="qtp.swc"/>
 </patternset>

The named patternset is then referenced by the mxmlc or compc task like this:

<compc>
 <compiler.include-libraries dir="${FLEX_HOME}/frameworks/libs" append="true">
  <patternset refid="${automation.libs}"/>
 </compiler.include-libraries>
</compc>

This doesn't appear to work. At least the SWC size does not indicate that the additional automation libraries have been compiled in. I want to be able to specify a command line property that determine which patternset to use for various types of builds.

Does anyone have any ideas about how to accomplish this? Thanks!

+2  A: 

If you can't get <patternset> to work correctly, you might want to take a look at the <if> <then> and <else> tasks provided by ant-contrib. We ended up doing something like this:

<target name = "build">
    <if>
        <equals arg1="automation.qtp" arg2="true"/>
        <then>
            <!--
               - Build with QTP support.
               -->
        </then>
        <else>
            <!--
               - Build without QTP support.
               -->
        </else>
    </if>
</target>

There is some duplication of build logic between the if and else branch, but you can factor some of that out if you wrap <mxmlc> with a macrodef.

Erich Douglass
This is a great suggestion. I followed a similar approach earlier naively thinking that <if> would be allowed within the <mxmlc> task, which of course it wasn't. I hadn't considered wrapping the mxmlc in an <if>. That would probably work, however, there are about 15 modules that are build in this script, and I'd have wrap it that many times. I was looking for an approach that would allow me to set the include libraries once and have it picked up automatically across all the <mxmlc> tasks in the ant project. If I don't hear any alternatives, I'll have to give this a try. Thanks.
lje
We worked around some of the duplication by creating a build-all target that used ant-contrib's <foreach> task and matched all *.mxml files in a particular directory. The <foreach> then called our build-single target which would conditionally include the QTP libs.
Erich Douglass