5

the ant-contrib lastest version is ant-contrib-1.0b3.jar?

http://ant-contrib.sourceforge.net/tasks/tasks/more_conditions.html

this document show endsWith condition

But I use ant 1.8.2 And ant-contrib-1.0b3.jar, I cann't find the endsWith condition

    <if>

        <endswith string="D:\FeiLong Soft\Essential\Development\repository\org\springframework\spring-beans" with="spring-beans" />
        <then>
            <echo>equals</echo>
        </then>
        <else>
            <echo>not equals</echo>
        </else>
    </if>

But result:

BUILD FAILED
E:\Workspaces\feilong\feilong-platform\tools\feilong-tools-ant\build.xml:32: if
doesn't support the nested "endswith" element.

Total time: 1 second
aliteralmind
  • 19,847
  • 17
  • 77
  • 108
feilong
  • 721
  • 1
  • 12
  • 25
  • Could not really find it anywhere... and on top of it, it is only working allowed with assert... Nothing else – Vishal Dec 02 '12 at 19:42
  • 1
    Can look at this question for an alternative solution: [in-ant-how-can-itest-if-a-property-ends-with-a-given-value](http://stackoverflow.com/questions/13649729/in-ant-how-can-itest-if-a-property-ends-with-a-given-value) – Tim Jan 31 '13 at 04:20
  • The documentation strongly implies that `endswith` should be usable as an `if` condition. For example, the [Assert documentation](http://ant-contrib.sourceforge.net/tasks/tasks/assert_task.html) states `The 'bool' element can contain all the conditions permitted by the ConditionTask, plus the IsPropertyTrue, IsPropertyFalse, StartsWith, EndsWith, IsGreaterThan, IsLessThan, and conditions. See the If task for examples of using these conditionals.` – aliteralmind Jan 05 '15 at 00:29
  • An example attempting to use it in an if tag, and not working: http://stackoverflow.com/a/13649958/2736496 – aliteralmind Jan 05 '15 at 00:33
  • The `` task itself has a `` sub-entity that uses regular expressions. Could `` work with the ``? Those _more_ tasks are sort of hidden on the Ant Contrib webpage, and not in the standard task list. I take it their use is rather iffy. It states that these tasks can't be used with ``. – David W. Jan 05 '15 at 03:12

2 Answers2

5

When checking the sources from antcontrib (version 1.0b2 or 1.0b3) especially net/sf/antcontrib/antcontrib.properties and ../antlib.xml you'll see, there is no startsWith or endsWith condition, though it's mentioned in the antcontrib manual.

Those two conditions originate from the Antelope project, which provides a UI for running ant and several ant tasks. Years ago there were plans to merge Antelope with AntContrib, see Antelope Tasks Merging with AntContrib and Antelope project site :

The Antelope Project also provides a set of additional tasks that provide functionality not found in the standard tasks distributed with Ant. Work is underway to merge the Antelope tasks with the AntContrib project.
[...]
The Ant-Contrib project is a collection of tasks (and at one point maybe types and other tools) for Apache Ant. Some of the Antelope tasks are now part of that project.

But somehow those merging plans stagnated and never finished properly, also Antcontrib seems to be dead - latest release 1.0b3 from 2006-11-02

Anyway, you may either use the ant matches condition with antcontrib :

<project>
 <!-- Import AntContrib -->
 <taskdef resource="net/sf/antcontrib/antlib.xml"/>
 <property name="foo" value="D:\FeiLong Soft\Essential\Development\repository\org\springframework\spring-beans"/>

 <if>
 <matches string="${foo}" pattern="^.+spring-beans$"/>
  <then>
   <echo>equals</echo>
  </then>
  <else>
   <echo>not equals</echo>
  </else>
 </if>
</project>

or the Antelope ant tasks.

Rebse
  • 10,307
  • 2
  • 38
  • 66
0

I had the same problem using "startwith" and dont found a solution. I don't understood the cause of "contains" working, but "startwith" and "endwith" don't.

<if>
    <contains string="a sample string" substring="sample" />
    <then>
        <echo>match</echo>
    </then>
    <else>
        <echo>not match</echo>
    </else>
</if>
Wender
  • 991
  • 15
  • 24
  • The contains condition is an ant core condition => https://ant.apache.org/manual/Tasks/conditions.html – Rebse Apr 15 '15 at 07:03