如果蚂蚁:真的。设置属性为true,将不会导致任务执行 [英] Ant if:true. Setting property to true won't cause the task to executed
问题描述
在蚂蚁1.9.1,您如果有,除非属性的大部分任务。使用的能力
In Ant 1.9.1, you have the ability to use if and unless attributes on most tasks.
我有一个宏,我定义在这里我试图运行这些任务:
I have a macro I've defined where I'm trying to run these tasks:
<property name="test.templates" value="true"/>
....
<target name="test.templates"
description="Test the autoconfiguration templates and answers">
<test.templates
if:true="test.templates"
template.root.dir="${main.dir}"
answers.dir="${main.config.dir}"/>
</target>
不过,这并不会运行我的宏 - 尽管财产 test.templates
设置为true。如果我删除这一行,我test.template宏将正常工作。
However, this won't run my Macro -- even though the property test.templates
is set to true. If I remove that line, my test.template macro will work.
有没有使用如果出了问题:真正的
在用户定义的宏?什么是解决这个问题的最佳方式是什么?
Is there a problem using if:true
in a user defined Macro? What's the best way to get around this issue?
推荐答案
蚂蚁手动:结果
由于蚂蚁1.9.1能够添加,当且除非所有属性
使用特殊的命名空间任务和嵌套元素。
Since Ant 1.9.1 it is possible to add if and unless attributes on all tasks and nested elements using special namespaces.
没有使用新的,如果,除非在macrodef属性到现在为止,但下面的代码片断如下:
Didn't use the new if and unless attributes in a macrodef until now, but the following snippet works :
<project xmlns:if="ant:if" xmlns:unless="ant:unless">
<property name="foo" value="true"/>
<macrodef name="foobar">
<attribute name="bla"/>
<attribute name="whentrue"/>
<sequential>
<echo if:true="${@{whentrue}}">@{bla}</echo>
</sequential>
</macrodef>
<echo>${ant.version}</echo>
<foobar whentrue="foo" bla="yada,yada"/>
</project>
的通知=>属性语法&LT;回声,如果:真=$ {@ {whentrue}}&GT;
,它不使用@ {时工作whentrue}只。
Notice => the property syntax <echo if:true="${@{whentrue}}">
, it doesn't work when using @{whentrue} only.
输出:结果
[echo] Apache Ant(TM) version 1.9.1 compiled on May 15 2013
[echo] yada,yada
我的另一个尝试:结果
My other try :
<macrodef name="foobar" if:true="foo">
<attribute name="bla"/>
<sequential>
<echo>@{bla}</echo>
</sequential>
</macrodef>
<echo>${ant.version}</echo>
<foobar bla="yada,yada"/>
没有工作:
... Problem: failed to create task or type foobar
Cause: The name is undefined.
Action: Check the spelling.
Action: Check that any custom tasks/types have been declared.
Action: Check that any <presetdef>/<macrodef> declarations have taken place.
还假设,类似&LT; foobar的喇嘛=亚达,亚达,如果:真=富/&GT;
将工作:结果
<project xmlns:if="ant:if" xmlns:unless="ant:unless">
<property name="foo" value="true"/>
<macrodef name="foobar">
<attribute name="bla"/>
<sequential>
<echo>@{bla}</echo>
</sequential>
</macrodef>
<echo>${ant.version}</echo>
<foobar bla="yada,yada" if:true="foo"/>
</project>
输出,没有错误,但macrodef没有得到执行:结果
output, no error but macrodef doesn't get executed :
[echo] Apache Ant(TM) version 1.9.1 compiled on May 15 2013
BUILD SUCCESSFUL
好像有在这方面还存在一些不一致的地方,因为这个功能崭新的。结果
也许我们应该提交一个bug!?结果
- 编辑(1) - 结果
刚刚发现一个评论从2007年由彼得·赖利(他已经实施中频/除非功能)在蚂蚁bug数据库提供了macrodef片段。
Seems like there are still some inconsistencies in that area, as this feature is spanking new.
Maybe we should file a bug !?
-- EDIT (1) --
Just found a comment from 2007 by Peter Reilly (he has implemented the if / unless feature) in the ant bug database providing a snippet with a macrodef.
- 编辑(2) - 结果
虽然新的Ant版本从2013年12月29日1.9.3(看阅读发布这里)固定相关的新的,如果一个bug:除非:属性(的 https://issues.apache.org/bugzilla/show_bug.cgi?id=55885 )我们的问题依然存在。因此,我开了一个bug报告,看蚂蚁bug数据库错误ID 55971 。< BR>
-- EDIT (2) --
Although the new Ant release 1.9.3 from December 29, 2013 (see releasenotes here) fixed a bug related to the new if: and unless: attributes (https://issues.apache.org/bugzilla/show_bug.cgi?id=55885) our problem still remains. Thus i opened a bug report, see ant bug database bugid 55971.
- 编辑(3) - 结果
最后的溶液中找到。除了用于错误ID 55885 蚂蚁版本1.9.3修正错误的还提供了一个修正了如果新的文档:除非:属性=> 错误ID 55359 一>显示,,如果:真=$ {PROPERTYNAME}
而不是,如果:真=PROPERTYNAME
有要使用的。结果,
结果
-- EDIT (3) --
Finally the solution is found. Beside the bugfix for Bugid 55885 the Ant Release 1.9.3 provides also a bugfix for the documentation of the new if: and unless: attributes => Bugid 55359 showing that if:true="${propertyname}"
instead of if:true="propertyname"
has to be used.
So your macro should work after upgrade on Ant 1.9.3 like that :
<property name="test.templates" value="true"/>
....
<target name="test.templates"
description="Test the autoconfiguration templates and answers">
<test.templates
if:true="${test.templates}"
template.root.dir="${main.dir}"
answers.dir="${main.config.dir}"/>
</target>
这篇关于如果蚂蚁:真的。设置属性为true,将不会导致任务执行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!