Thanks for the suggestion; I will take a look at the scriptselector you
mention. In the meantime I came up with a solution that uses just existing
ant and ant-contrib constructs. Here it is in case others are interested:
<!--
Purpose: confirm that file path/xxx.java contains comment "@doc
/api/subpath/xxx.html".
-->
<checkApiPath
srcdir="${javasrc}"
regexp=".*(com.cleancode..*)\.java"
includes="**/*.java"
/>
<macrodef name="checkApiPath">
<attribute name="srcdir"/>
<attribute name="regexp"/>
<attribute name="includes" default="**"/>
<attribute name="excludes" default=""/>
<sequential>
<!-- collect all source files -->
<pathconvert property="apiList">
<path>
<fileset dir="@{srcdir}"
includes="@{includes}" excludes="@{excludes}">
<containsregexp expression="@doc\s+/api/" />
</fileset>
</path>
</pathconvert>
<for list="${apiList}" param="file" delimiter=";">
<sequential>
<!-- reshape file path to match API name -->
<propertyregex property="shortfile" input="@{file}"
regexp="@{regexp}" replace="\1.html"
override="true"/>
<!-- grab corresponding line from file contents -->
<loadfile srcfile="@{file}" property="apiList.text">
<filterchain>
<linecontainsregexp>
<regexp pattern="@doc\s+/api"/>
</linecontainsregexp>
</filterchain>
</loadfile>
<!-- isolate api path -->
<propertyregex
property="apiList.text" input="${apiList.text}"
regexp=".*/api/[^/]+/(.*\.html)" replace="\1"
override="true"/>
<!-- validate -->
<if>
<not>
<equals trim="true"
arg1="${shortfile}" arg2="${apiList.text}" />
</not>
<then>
<echo level="warning"
message="${shortfile}: wrong api spec:
${apiList.text}" />
</then>
</if>
<!-- vital step: make property mutable (NB: nonstandard ant) -->
<var name="apiList" unset="true"/>
<var name="apiList.text" unset="true"/>
<var name="shortfile" unset="true"/>
</sequential>
</for>
</sequential>
</macrodef>
---
[EMAIL PROTECTED] writes:
I dont know built in selector.
But you can write your own - e.g. using <scriptselector> and reuse of the
<containsselector>.
The filename and the fileobject are passed.
<project>
<pathconvert property="selected" pathsep="${line.separator}">
<fileset dir=".">
<!-- Checks if the content of the file contains the filename. -->
<scriptselector language="javascript" setbeans="true">
importClass(Packages.org.apache.tools.ant.types.selectors.ContainsSelector);
filenameWithoutSuffix = filename.substring(0,
filename.lastIndexOf("."));
cSel = new ContainsSelector();
cSel.setText(filenameWithoutSuffix);
self.setSelected( cSel.isSelected(basedir, filename, file) );
</scriptselector>
</fileset>
</pathconvert>
<echo>Selected files</echo>
<echo>${selected}</echo>
</project>
Jan
-----Ursprüngliche Nachricht-----
Von: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]
Gesendet: Mittwoch, 21. Mai 2008 17:44
An: Ant Users List
Betreff: Re: AW: AW: generate file list with parameterized regexp
My humblest apologies--I did not state my problem clearly. I
want to find a
set of files whose contents (not the file name) includes a
string based on
the name of the file containing it. That is, for each file
path/xxx.yyy, I
want to know if the file contains a string like this:
"See doc page at path/xxx.html".
So <containsregexp> seemed the most promising, as discussed,
but it uses
only a "constant" regexp, not a parameterized regexp.
[EMAIL PROTECTED] writes:
> Ok, I had a look into the source of <containsregexp>
org.apache.tools.ant.types.selectors.ContainsRegexpSelector.
> It checks the 'content' of the file ...
> - directories are always selected
> - files are selected its content matches the regexp expression
>
> I'll update the manual to make this more clear.
>
> After that I think that you want to select files which
'names' match the regexp.
> The <filename> selector supports simple pattern matching
like '*' but no real regexps.
> I havent found a builtin one, but with BSF+Java4 or Java6
you could use a scripted selector.
> <project>
> <property name="searchRegexp" value="six.*"/>
> <pathconvert property="selected" pathsep="${line.separator}">
> <fileset dir=".">
> <scriptselector language="javascript" setbeans="true">
> self.setSelected(
filename.match(searchRegexp) != null );
> </scriptselector>
> </fileset>
> </pathconvert>
> <echo>Selected files for ${search.regexp}</echo>
> <echo>${selected}</echo>
> </project>
>
>
>
> Jan
>
>
>> -----Ursprüngliche Nachricht-----
>> Von: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]
>> Gesendet: Dienstag, 20. Mai 2008 17:47
>> An: Ant Users List
>> Betreff: Re: AW: generate file list with parameterized regexp
>>
>> Yes I have tried "containsregexp". As far as I could tell,
>> there is no way
>> to parameterize the regexp within the fileset, so that
does not work.
>>
>> [EMAIL PROTECTED] writes:
>>
>> > Have you tried
>>
http://ant.apache.org/manual/CoreTypes/selectors.html#regexpselect ?
>> > Then you got the 'problem' of correctly masking the regexp.
>> >
>> > Jan
>> >
>> >> -----Ursprüngliche Nachricht-----
>> >> Von: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]
>> >> Gesendet: Dienstag, 20. Mai 2008 07:57
>> >> An: user@ant.apache.org
>> >> Betreff: generate file list with parameterized regexp
>> >>
>> >>
>> >> I am ant-challenged today: I want to find a set of files in a
>> >> tree matching
>> >> a given regular expression. The catch is that the regexp is
>> >> not constant,
>> >> but is a function of the file name. I have tried
permutations of
>> >> pathconvert, for loops, and loadfile, filterchain, and
>> >> linecontainsregexp,
>> >> stumbling when I could not change the property loaded from
>> >> loadfile after
>> >> its initial value. Any suggestio
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]