开发者

sorting as well as removing duplicacy

开发者 https://www.devze.com 2023-02-22 17:37 出处:网络
<?xml version=\"1.0\"?> <project name=\"sortlist11\" default=\"sortlist11\"> <taskdef resource=\"net/sf/antcontrib/antcontrib.properties\" />
<?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="," />
开发者_JAVA百科        <sortlist property="my.sorted.list1" value="${my.list1}" delimiter="," />
        <echo message="${my.sorted.list}" />
        <echo message="${my.sorted.list1}" />
    </target>
</project>

here second echo print 1,3,4,5,6,6,8 but how can i remove redundancy?


Every language running in JVM via Bean Scripting Framework may be used in ant with full access to the ant api. Here's a solution with Groovy for your problem =

<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>
0

精彩评论

暂无评论...
验证码 换一张
取 消