Reputation: 6052
I have a set of files that I want to run a perl script on. The problem is they are not in the same directory. In fact they are all part of an ordered but complex directory hierarchy.
I wrote a Bash script that does what I want:
if [ ${HOME:+1} ]; then
for A in ${HOME}/a/b/*; do
for B in ${A}/c/*; do
for C in ${B}/*; do
if [ -f $C/somefile ]; then
some_perl_script $C/somefile;
fi
done;
done;
done;
fi
So that works, and it's not too complicated. However, I need that functionality to be available using Ant. Of course I could just call that script from Ant, but I want to know if there is anyway of having Ant do it in the first place, which seems like a more straightforward way of doings things. Essentially, I want something similar to the following build.xml:
<project name="application" basedir=".">
<target name="apply_to_all">
<exec executable="perl" dir="${basedir}">
<arg value="some_perl_script.pl"/>
<arg value="a/b/**/c/**/**/somefile"/>
</exec>
</target>
</project>
I found this SO post. However, I'd like to do it without ant-contrib.
Upvotes: 0
Views: 723
Reputation: 10377
Use the apply task to invoke your perlscript on all files that are included in the nested fileset(s) :
<apply executable="perl">
<arg value="-your args.."/>
<fileset dir="/some/dir">
<patternset>
<include name="**/*.pl"/>
</patternset>
</fileset>
<fileset refid="other.files"/>
</apply>
Optionally use the attribute parallel = true, means run the command only once, appending all files as arguments. If false, command will be executed once for every file, default =false => see Ant manual on apply
You may use include / exclude patterns and one or more filesets. F.e. you may use **/*.pl
for
all your perl scripts.
Upvotes: 3