我们一直在努力试图找出如何以有条件地包括在基于被在命令行上设置属性Ant构建的Flex库。我已经尝试了<condition/>
任务的一些方法,但到目前为止还没有使用它。这是我目前的地方。
我有一个初始目标,包括这样的条件任务:
<condition property="automation.libs" value="automation.qtp">
<equals arg1="${automation}" arg2="qtp" casesensitive="false" trim="true"/>
</condition>
此任务的目的是设置确定声明上的mxmlc的或compc命令任务隐式文件集时要使用的patternset的名称的属性。上面引用的模式集定义为:
<patternset id="automation.qtp">
<include name="automation*.swc"/>
<include name="qtp.swc"/>
</patternset>
然后,mxmlc或compc任务会引用命名的模式集,如下所示:
<compc>
<compiler.include-libraries dir="${FLEX_HOME}/frameworks/libs" append="true">
<patternset refid="${automation.libs}"/>
</compiler.include-libraries>
</compc>
这似乎不起作用。至少SWC大小并不表明额外的自动化库已经被编译,我希望能够指定一个命令行的属性,确定哪些patternset使用各种类型的构建。
有没有人对如何做到这一点有任何想法?谢谢!
答案 0 :(得分:2)
如果无法让<patternset>
正常工作,您可能需要查看ant-contrib提供的<if>
<then>
和<else>
任务。我们最终做了这样的事情:
<target name = "build">
<if>
<equals arg1="automation.qtp" arg2="true"/>
<then>
<!--
- Build with QTP support.
-->
</then>
<else>
<!--
- Build without QTP support.
-->
</else>
</if>
</target>
在if和else分支之间存在一些构建逻辑的重复,但是如果用<mxmlc>
包装宏定义,则可以将其中的一部分考虑在内。
答案 1 :(得分:0)
mxmlc任务支持加载configuration files <load-config filename="path/to/flex-config.xml" />
。因此,通过组合echoxml任务和if-then-else,动态生成config xml。
<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>
如果您的需求更复杂,您甚至可以生成多个xml配置并<load-config ... />
。
就我个人而言,我发现使用Ant的条件编写任何逻辑非常简洁和丑陋,或者if-then-else,XML不是一种用于编程的漂亮语言。幸运的是,在调用mxmlc之前,可以使用更灵活的方法 - 编写脚本来生成config xml。例如。将script任务与您喜欢的脚本语言
一起使用<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>