我一直在努力弄清楚如何根据在命令行上设置的属性在ant构建中有条件地包含Flex库。我已经尝试了使用<condition/>任务的许多方法,但到目前为止还没有让它工作。这就是我目前所在的位置。
我有一个init目标,它包含如下条件任务:
<condition property="automation.libs" value="automation.qtp">
<equals arg1="${automation}" arg2="qtp" casesensitive="false" trim="true"/>
</condition>此任务的目的是设置一个属性,该属性确定在mxmlc或compc任务上声明隐式文件集时要使用的模式集的名称。上面引用的模式集定义为:
<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大小并不表示已经编译了额外的自动化库。我希望能够指定一个命令行属性来确定将哪个模式集用于各种类型的构建。
有没有人对如何做到这一点有什么想法?谢谢!
发布于 2010-01-13 07:27:18
如果你不能让<patternset>正常工作,你可能想看看由<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>,则可以消除其中的一些重复。
发布于 2016-04-14 08:48:10
mxmlc任务支持加载configuration files <load-config filename="path/to/flex-config.xml" />。因此,通过组合echoxml任务和if-then-else,动态生成配置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之前编写一个脚本来生成配置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>https://stackoverflow.com/questions/2052453
复制相似问题