Search code examples
antant-contrib

In Ant, how can I test if a property ends with a given value?


In Ant, how can I test if a property ends with a given value?

For example

 <property name="destdir" 
     value="D:\FeiLong Soft\Essential\Development\repository\org\springframework\spring-beans" />

how can I test if ${destdir} ends with "spring-beans"?

additional:

In my ant-contrib-1.0b3.jar, without 'endswith' task~~


Solution

  • As Matteo, Ant-Contrib contains a lot of nice stuff, and I use it heavily.

    However, in this case can simply use the <basename> task:

    <basename property="basedir.name" file="${destdir}"/>
    <condition property="ends.with.spring-beans">
       <equals arg1="spring-beans" arg2="${basedir.name}"/>
    <condition>
    

    The property ${ends.with.spring-beans} will contain true if ${destdir} ends with string-beans and false otherwise. You could use it in the if or unless parameter of the <target> task.