To search for multiple 'searchStrings' in a fileset the following ANT seems to do the job.
<taskdef resource="net/sf/antcontrib/antlib.xml">
<classpath>
<pathelement location="/usr/share/java/ant-contrib.jar"/>
</classpath>
</taskdef>
<loadfile property="list" srcFile="searchStrings.txt"/>
<echo>.:${list}:.</echo>
<target name="main">
<for list="${list}" param="search4" delimiter="${line.separator}">
<sequential>
<fileset id="existing" dir="../src">
<patternset id="files">
<include name="**/*.xul"/>
</patternset>
</fileset>
<resourcecount property="count">
<fileset id="matches" dir="../src">
<patternset refid="files" />
<contains text="@{search4};" />
</fileset>
</resourcecount>
<echo message="Found '@{search4}' in files : '${count}'"/>
</sequential>
</for>
</target>
But for each individual searchString I need the number of occurrences. The echo message "Found ..." only gives the very first result and more worse, it repeats that number for all files.
Tried to add an echo inside the resourcecount block, but that fails.
How can this be modified to get a list for all searchStrings?
ANT is not a scripting language, I would recommend embedding something like groovy
Example
This example counts the occurances of search terms, stored in the "searchStrings.txt" file, contained files stored under the "src" directory.
Run as follows
build.xml
searchStrings.txt
src/test*.xul
Dummy data files:
Update 1
To make this work with Eclipse, alter the taskdef to include the path to the downloaded "groovy-all.jar".
Note:
Update 2:
The solution can be easily enhanced to write the search results to a file:
Groovy is powerful.