如何重置 ANT 中的属性?
我正在编写一个速度宏,其中有一些蚂蚁任务。在速度宏的 #foreach 循环中,我有一个 pathconvert 任务:
#foreach(<iterate through something>)
<pathconvert property='filename' refid='swf.file'>
<mapper>
<chainedmapper>
<flattenmapper/>
<globmapper from='*-d.swf' to='*'/>
</chainedmapper>
</mapper>
</pathconvert>
#end
我遇到的问题是“filename”属性在第一次迭代期间仅设置一次,因为 ANT 中的属性是不可变的。 但我需要在每次迭代期间设置文件名。有办法完成这件事吗?
如果有办法重置属性,我可以在每次迭代结束时执行此操作。或者有更好的方法来做到这一点吗? 任何帮助将不胜感激!
提前致谢, 阿南德
I'm writing a velocity macro within which I have some ant tasks. Within a #foreach loop in the velocity macro, I have a pathconvert task:
#foreach(<iterate through something>)
<pathconvert property='filename' refid='swf.file'>
<mapper>
<chainedmapper>
<flattenmapper/>
<globmapper from='*-d.swf' to='*'/>
</chainedmapper>
</mapper>
</pathconvert>
#end
The problem I have is that the 'filename' property gets set only once, during the first iteration, since properties in ANT are immutable.
But I need the filename to be set during each iteration. Is there a way to get this done?
If there was a way to reset the property, I could do that at the end of each iteration. Or is there a better way to do this?
Any help would be highly appreciated!
Thanks in advance,
Anand
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
您可以使用 ant-contrib 的变量。它们的行为就像可变属性。
http://ant-contrib.sourceforge.net/tasks/tasks/variable_task。 html
You could use ant-contrib's variables. They act like mutable properties.
http://ant-contrib.sourceforge.net/tasks/tasks/variable_task.html
使用 Ant 1.8 中新的词法作用域属性:
“词法作用域本地属性,即仅在目标、顺序块或类似环境内定义的属性。”
公告。
Ant 中的属性被设计为不可变的,但它们屈服于大众的需求并给出了我们的变量。您的替代方案是编写自定义任务(使用 Java 或动态语言),但这似乎是一个很好的折衷方案。
Use the new lexically scoped properties in Ant 1.8:
"Lexically scoped local properties, i.e. properties that are only defined inside a target, sequential block or similar environment."
Annoucement.
Properties in Ant were designed to be immuatable, but they gave in to popular demand and gave us variables. Your alternative is to write a custom task ( in Java or a Dynamic Language) but this seems like a good compromise.
以下代码片段说明了我认为没有记录的 ant 属性。 属性是不可变的,但引用是可变的。因此,任何没有名称但有引用的数据类型都是可变的。例如
文件集
。但今天我找到了一种拥有可变属性的方法。与local
任务或其他一些技巧相结合,它可能是在 ant 中拥有变量的一种方式。输出为:
尽管在这两种情况下都会打印参考
refa
。这是 一篇文章关于它。和 另一个。
The following snippet illustrates an ant property which I guess is not documented. Properties are immutable, but references are mutable. So any data type which has no name, but a reference, is mutable. For example a
fileset
. But today I found a way to have a kind of mutable property. Connected withlocal
task or some other tricks it may be a way of having variables in ant.The output is:
Although in both cases a reference
refa
is printed.Here is a post about it. And another one.
使用 Ant Plugin Flaka 中的 for + let 任务组合来覆盖现有属性。
请参阅此处的一些代码段。
Use a combination of for + let task from Ant Plugin Flaka to overwrite existing properties.
See some snippets here.