<?xml version="1.0"?>
<project name="sortlist11" default="sortlist11">
<taskdef resource="net/sf/antcontrib/antcontrib.properties" />
<property name="my.list" value="z,y,x,w,v,u,t" />
<property name="my.list1" `value="5,3,6,1,8,4,6" `/>
<target name="sortlist11">
<sortlist property="my.sorted.list" value="${my.list}" delimiter="," />
<sortlist property="my.sorted.list1" value="${my.list1}" delimiter="," />
<echo message="${my.sorted.list}" />
<echo message="${my.sorted.list1}" />
</target>
</project>
这里第二回声打印1,3,4,5,6,6,8,但我怎么能消除冗余?
通过Bean脚本框架在JVM中运行的每种语言都可以在ant中使用,并且可以完全访问ant api。下面是Groovy的解决方案=
<project>
<taskdef name="groovy" classname="org.codehaus.groovy.ant.Groovy"/>
<property name="my.list" value="z,y,x,w,v,u,t"/>
<property name="my.list1" value="5,3,6,1,8,4,6"/>
<groovy>
properties.'my.sorted.list' = properties.'my.list'.split(',').sort().toString()
properties.'my.sorted.list1' = properties.'my.list1'.split(',').toList().unique().sort().toString()
</groovy>
<echo>
$${my.sorted.list} => ${my.sorted.list}
$${my.sorted.list1} => ${my.sorted.list1}
</echo>
</project>