如何重置 ANT 中的属性?

发布于 2024-09-24 01:07:28 字数 629 浏览 2 评论 0原文

我正在编写一个速度宏,其中有一些蚂蚁任务。在速度宏的 #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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

淡淡的优雅 2024-10-01 01:07:28

您可以使用 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

记忆消瘦 2024-10-01 01:07:28

使用 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.

邮友 2024-10-01 01:07:28

以下代码片段说明了我认为没有记录的 ant 属性。 属性是不可变的,但引用是可变的。因此,任何没有名称但有引用的数据类型都是可变的。例如文件集。但今天我找到了一种拥有可变属性的方法。与 local 任务或其他一些技巧相结合,它可能是在 ant 中拥有变量的一种方式。

<property name="a" value="aaa" id="refa" />
<property name="b" refid="refa" />
<echo>${b}</echo>
<property name="c" value="ccc" id="refa" />
<property name="d" refid="refa" />
<echo>${d}</echo>

输出为:

aaa
ccc

尽管在这两种情况下都会打印参考 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 with local task or some other tricks it may be a way of having variables in ant.

<property name="a" value="aaa" id="refa" />
<property name="b" refid="refa" />
<echo>${b}</echo>
<property name="c" value="ccc" id="refa" />
<property name="d" refid="refa" />
<echo>${d}</echo>

The output is:

aaa
ccc

Although in both cases a reference refa is printed.

Here is a post about it. And another one.

恰似旧人归 2024-10-01 01:07:28

使用 Ant Plugin Flaka 中的 for + let 任务组合来覆盖现有属性。
请参阅此处的一些代码段

Use a combination of for + let task from Ant Plugin Flaka to overwrite existing properties.
See some snippets here.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文