2012-03-20 92 views
2

我想的東西轉換,如:如何將Ant屬性轉換爲Ant資源?

<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任務中創建資源?

回答

3

以下工作:

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