<?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>
这里是第二个echo打印1,3,4,5,6,6,8但是如何删除冗余?
答案 0 :(得分:2)
通过Bean Scripting Framework在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>