Conditionally including Flex libraries (SWCs) in mxmlc/compc ant tasks

匆匆过客 提交于 2019-12-02 00:59:42

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.

The mxmlc task supports loading configuration files <load-config filename="path/to/flex-config.xml" />. So, generate the config xml on the fly, by combining the echoxml task and if-then-else.

<echoxml file="path/to/flex-config.xml">
    <flex-config>
        <compiler>
            <library-path append="true">
                <path-element>${lib.qtp}</path-element>
            </library-path>
        </compiler>
    </flex-config>
</echoxml>

If your needs are more complicated, you could even generate several xml configs and <load-config ... /> them all.

Personally, I find any logic very terse and ugly to write using Ant's conditions or if-then-else, XML is not a pretty language to use for programming. Luckily, it's possible to use more flexible approach - write a script to produce the config xml, before calling mxmlc. E.g. use the script task with your favorite scripting language

<script language="javascript">
    <![CDATA[
        // Create your XML dynamically here.
        // Write that XML to an external file.
        // Later, feed that file to mxmlc using `<load-config ... />`.
    ]]>
</script>
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!