Ant 条件 if 在宏定义中 [英] Ant conditional if within a macrodef
问题描述
在 ant 中,我有一个宏定义.
Within ant, I have a macrodef.
假设我必须使用这个宏定义,并且如果属性 special.property
存在并且为真,那么我想在该宏定义中运行一个项目,我该怎么办?
Assuming I have to use this macrodef, and there is a item inside said macrodef that I want to run if the property special.property
exists and is true, what do I do?
我现在有
<macrodef name="someName">
<sequential>
<someMacroDefThatSetsTheProerty />
<some:thingHereThatDependsOn if="special.property" />
<sequential>
</macrodef>
哪个不起作用 - some:thingHereThatDependsOn 没有if"属性,我不能向它添加一个.
Which doesn't work - the some:thingHereThatDependsOn doesnt have an "if" attribute, and I cannot add one to it.
antcontrib 不可用.
antcontrib is not available.
有了目标,我可以给目标一个如果",我可以用宏定义做什么?
With a target I can give the target an "if", what can I do with a macrodef?
推荐答案
在 Ant 1.9.1 及更高版本中,现在有 if
和 unless
的新实现 属性.这可能就是你的想法.
In Ant 1.9.1 and higher, there is now a new implementation of if
and unless
attributes. This might be what you're thinking of.
首先,您需要将它们放入您的命名空间.将它们添加到您的
标头:
First, you need to put them into your namespace. Add them to your <project>
header:
<project name="myproject" basedir="." default="package"
xmlns:if="ant:if"
xmlns:unless="ant:unless">
现在,您几乎可以将它们添加到任何 Ant 任务或子实体中:
Now, you can add them to almost any Ant task or sub entity:
<!-- Copy over files from special directory, but only if it exists -->
<available property="special.dir.available"
file="${special.dir} type="dir"/>
<copy todir="${target.dir}>
<fileset dir="${special.dir}" if:true="special.dir.available"/>
<fileset dir="${other.dir}"/>
</copy>
<!-- FTP files over to host, but only if it's on line-->
<condition property="ftp.available">
<isreachable host="${ftp.host}"/>
</condition>
<ftp server="${ftp.host}"
userid="${userid}"
passowrd="${password}"
if:true="ftp.available">
<fileset dir=".../>
</ftp>
这篇关于Ant 条件 if 在宏定义中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!