Reputation: 2222
I want to prepend each matching line with file name where it's found.
I tried ${file.name}
, but it does not work.
<concat destFile="report.xml">
<filterchain>
<linecontainsregexp>
<regexp pattern="somePattern"/>
</linecontainsregexp>
<prefixlines prefix="${file.name}"/>
</filterchain>
<fileset dir="${pathToDirectory}" erroronmissingdir="false">
<include name="**"/>
</fileset>
</concat>
Upvotes: 1
Views: 537
Reputation: 7051
The following code uses the <for>
task from the third-party Ant-Contrib library. <for>
iterates over every file in a fileset.
<for param="file.path">
<path>
<fileset dir="${pathToDirectory}" erroronmissingdir="false">
<include name="**"/>
</fileset>
</path>
<sequential>
<concat destFile="report.xml" append="true">
<path>
<pathelement location="@{file.path}"/>
</path>
<filterchain>
<linecontainsregexp>
<regexp pattern="somePattern"/>
</linecontainsregexp>
<prefixlines prefix="@{file.path}:"/>
</filterchain>
</concat>
</sequential>
</for>
To use Ant-Contrib, download ant-contrib-1.0b3-bin.zip, extract ant-contrib-1.0b3.jar from it, and follow the instructions on how to install Ant-Contrib.
Upvotes: 1