if-then-else Task

ModelAnt’s util package provides if-then-else task to evaluate dynamically any ANT condition and do conditional processing. The unusual of this task is that ANT actually does not allow such dynamic evaluation – it is just one time set up and evaluated. The ModelAnt’s if task is specifically designed for repeating tasks execution with different parameters, within iterative tasks for example within ModelAnt for task.

The if task dynamically evaluates the nested condition and executes the tasks provided in the nested <then> or <else> section:

  • the condition is a single one and mandatory
  • the conditions to use are standard ANT conditions
  • of course complex condition can be formulated using the standard ANT and, or and not conditions
  • the <then> and <else> tasks lists are optional

See the documentation of if-then-else task.

For example, when run in  modelant/util/test/xml directory, this fragment:

 <for>
  <fileset dir=".">
    <include name="*.xml"/>
  </fileset>
  <tasks>
    <if>
      <matches string="${this}" pattern="test-l.*$"/>
      <then>
        <echo>${this}</echo>
      </then>
    </if>
  </tasks>
</for>

produces the output:

[echo] test-list.xml 
[echo] test-local.xml

Note that this fragment is also an example of use of ModelAnt for task together with an ANT standard file set.

Leave a Reply

Your email address will not be published.

Time limit is exhausted. Please reload CAPTCHA.