如何将Ant属性转换为Ant资源?

时间:2012-03-20 23:55:15

标签: ant groovy

我想转换类似的内容:

<property name='aoeu' value='a,o,e,u'/>

为:

<path id='ueoa'>
    <pathelement location="a/file"/>
    <pathelement location="o/file"/>
    <pathelement location="e/file"/>
    <pathelement location="u/file"/>
</path>

aoeu的值可以包含任意数量的逗号分隔元素。

我可以使用groovy Ant任务,但不能使用ant-contrib。

到目前为止,我有以下内容:

<groovy>
    properties['aoeu'].tokenize(',').each() {
        properties["ueoa-${it}"] = "${it}/file"
    }
</groovy>

<propertyset id='ueoa'>
    <propertyref prefix='ueoa-'/>
</propertyset>

创建ueoa为:

ueoa=ueoa-a=a/file, ueoa-o=o/file, ueoa-e=e/file, ueoa-u=u/file

当我真正想要的是:

ueoa=/path/to/a/file:/path/to/o/file:/path/to/e/file:/path/to/u/file

如何让这种转换发挥作用?或者,如何在groovy Ant任务中创建资源?

1 个答案:

答案 0 :(得分:3)

以下工作:

<groovy>
    ant.path(id:'ueoa') {
        properties['aoeu'].tokenize(',').each() {
            pathelement(location:"${it}/file")
        }
    }
</groovy>