0

By trial and error I got ANT example below working. Looks like <first> is something executed before any target invoked. E.g. ${foundSrcFiles} can be used in (any) target with found files being displayed. It's just I didn't find this documented anywhere. Anyone a link to description???

<project basedir="./example4" default="fourthTarget">
    <property name="dir.src">src</property>
    <first id="foundAnyJavaFile">
        <!-- but things you can do here are limited. -->
        <!-- property name="dir.classes"> doesn't e.g. work... -->
        <fileset dir="${dir.src}" includes="**/*.java"/>
    </first>
    <property name="foundSrcFiles" refid="foundAnyJavaFile"/>
    ...
</project>
vl106
  • 11
  • 2

1 Answers1

0

first is a type of resource collection in Ant. It takes another nested resource collection and selects the first X resources it contains. When X is not specified with the count attribute, it simply takes the single first resource.

It has nothing to do with the order in which things are executed in your build script. Any tasks that exist outside of targets (i.e. at the root project level) will be executed sequentially before any targets are invoked. In the example you posted, the property "dir.src" will be defined first, then the first resource collection will be defined with id "foundAnyJavaFile", and lastly the property "foundSrcFiles" will be defined with the reference "foundAnyJavaFile".

This resource collection is documented here: https://ant.apache.org/manual/Types/resources.html#first

CAustin
  • 4,525
  • 13
  • 25