Reputation: 5949
This seems like something that should be obvious, but I don't think it is. Given:
<patternset>
of whitelisted patternsHow do I come up with a <fileset>
that contains all of the files in the list that match the whitelisted pattern?
Getting a list of files from the list is easy enough:
<patternset id="the-patternset" includes="${list.of.files}" /> <fileset id="the-fileset" dir="${basedir}"> <patternset refid="the-patternset" /> </fileset> <pathconvert pathsep="${line.separator}" property="the-filelist" refid="the-fileset"/> <echo>fileset: ${the-filelist}</echo>
…will happily produce a fileset with all of the files in ${list.of.files}
. But adding a filter of sorts:
<patternset id="the-filter"> <include name="includeme/**/*.java" /> <exclude name="excludeme/**/*.java" /> </patternset> <patternset id="the-patternset" includes="${list.of.files}" /> <fileset id="the-fileset" dir="${basedir}"> <patternset refid="the-patternset" /> <patternset refid="the-filter" /> </fileset> <pathconvert pathsep="${line.separator}" property="the-filelist" refid="the-fileset"/> <echo>fileset: ${the-filelist}</echo>
…will list a union of the patternsets—i.e., all files that match either the-filter
or the-patternset
.
How do I produce a fileset containing files that are in ${list.of.files}
and match the-patternset
?
Upvotes: 4
Views: 4371
Reputation: 78225
Here's a potted example. Create two filesets (or perhaps filelists) one from each of your patternsets. I'll just use fixed lists here:
<property name="list.1" value="a,b,c" />
<property name="list.2" value="b,c,d" />
<fileset dir="." id="set.1" includes="${list.1}" />
<fileset dir="." id="set.2" includes="${list.2}" />
Then use the <intersect>
resource collection to get the required 'overlap' set:
<intersect id="intersect">
<resources refid="set.1"/>
<resources refid="set.2"/>
</intersect>
Most Ant tasks will allow you to use a resource collection in place of a simple fileset.
Upvotes: 1