select task

The ModelAnt select task (and the corresponding ModelAnt conditions for.each and exists) is the main mechanism to query models (actually, any collection) according to certain conditions. The query may start from an existing model element, from a list of objects or start from the meta-class, this way referring any model objects of that class. The conditions refer attributes and associations or even call predicates (boolean methods) on the wrappers for the model objects this way allowing the ModelAnt scripts use the same features the other components may use in Java.

In order to evaluate this task establishes a local properties environment and binds in it property whose name is set the iterator attribute (default: this) and evaluates the nested condition for it. If the condition is satisfied the object is collected in the result list property whose name is set in name attribute (default: this). There is no name collision because the properties the iterator and name attribute refer exist in different properties environments.

NOTE: The standard Ant behavior is at the first moment of condition’s evaluation to instantiate the condition and replace any references to properties with the available values of those properties. ModelAnt’s select task and exist, for.each conditions, actually all based on ModelAnt evaluate condition redefine this behavior, allowing to evaluate the condition at any moment this is needed.

For example (modelant/util/test/xml/test-select.xml):

<select name="result">
  <fileset dir=".">
    <include name="*.xml"/>

  <matches string="${this}" pattern="test.*.xml"/>

This example statement finds those files that have names matching test.*.xml regular expression among all files the nested fileset selector.

Produces output:

[echo] [test-dynamic.xml, test-eval.xml, test-exists.xml, test-filter.xml, test-if.xml, test-list.xml, test-local.xml, test-method.xml, test-search.xml, test-select.xml

Leave a Reply

Your email address will not be published.

Time limit is exhausted. Please reload CAPTCHA.