1

I am using ant exec command to implement the less utility to view the source code of a bunch of .java files. (I know that there are other ways to do this like using concat)

So the call ant view works if I specify only one file:

<target name="view">
    <exec executable="less" dir=".">
        <arg value="Main.java"/>
    </exec>
</target>

But if I change my code to <arg value="*.java"/> to view all files, it actually searches for a file named *.java.

Apparently I can put a bunch of arg's for each file, but is there a way to do this with one arg ?

xhienne
  • 5,738
  • 1
  • 15
  • 34
PTN
  • 1,658
  • 5
  • 24
  • 54

2 Answers2

3

The * glob is expanded by the shell on Unix-likes, that's why less doesn't do it itself.

Apart from <exec> there is <apply> which works on a resource collection:

<apply executable="less" dir="." parallel="true" relative="true">
  <fileset dir="." includes="*.java"/>
</apply>
Stefan Bodewig
  • 3,260
  • 15
  • 22
2

You can use foreach which requires ant-contrib

<target name="view">
  <foreach target="call-less" param="file">
    <fileset dir="${src}" includes="**/*.java" />
  </foreach>
</target>

<target name="call-less">
    <exec executable="less">
        <arg value="${file}" />
    </exec>
</target>
Oleg Pavliv
  • 20,462
  • 7
  • 59
  • 75