-----Original Message-----
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] 
Sent: Wednesday, May 30, 2007 9:02 AM
To: user@ant.apache.org
Subject: AW: iterate a fileset

/*
I would go another way: collect all files which does NOT have the tag
and display them.

<pathconvert><fileset><not><contains>
<echo>
<fail if>
*/

what if he needs some finer control / results, don't know how to get
that
more ' Ant like ', maybe there is a much simpler approach without
scripting ?!


i.e. he needs =

 for processing them later :

all good files with the version tag in a list
all bad files without the version tag in a list

or for conditions :

counting the good and the bad files


<scriptdef name="checkFiles" language="ruby">
    <attribute name="dir" />
    <attribute name="extension" />
    <attribute name="regex" />
   <!-- the good ones -->
    <attribute name="foundfilespos" />    
    <attribute name="countfilespos" />
    <attribute name="foundfilesneg" />
  <!-- the bad ones -->
    <attribute name="countfilesneg" />
    <attribute name="separator" /> 
    <![CDATA[
        filesfoundneg=Array.new
        filesfoundpos=Array.new
        regex=/#{$attributes.get("regex")}/
 
Dir[$attributes.get("dir")+'/'+$attributes.get("extension")].each do
|path|
            if File.open(path).read.scan(regex).length > 0
                filesfoundpos<<path<<$attributes.get("separator")
                else
                filesfoundneg<<path<<$attributes.get("separator")
            end        
        end
        
    # ony logged in debug mode
    $project.log filesfoundpos.to_s,4
    $project.log filesfoundneg.to_s,4

    $project.setNewProperty $attributes.get("foundfilespos"),
filesfoundpos.to_s.chop
    $project.setNewProperty $attributes.get("countfilespos"),
filesfoundpos.length.to_s
    $project.setNewProperty $attributes.get("foundfilesneg"),
filesfoundneg.to_s.chop
    $project.setNewProperty $attributes.get("countfilesneg"),
filesfoundneg.length.to_s
 ]]>
</scriptdef>


and for example =

<checkFiles 
   dir="Y:/"
   extension="**/*.jsp" 
   regex="\d\d_\d\d_\d\d"
   foundfilespos="jspfilesOK"
   countfilespos="countjspOK"
   foundfilesneg="jspfileNOK"
   countfilesneg="countjspNOK"
   separator=","
 />

recursive or not rescursive via *.jsp or **/*.jsp

later :

maybe other files with extension jsp and without versiontag are
not allowed or only a specific number of files

<condition property="checkfilesOK">
  <equals arg1="${countjspNOK}" arg2="0" />
</condition>
<fail unless="checkfilesOK" message="Error = found ${countjspNOK} jsp
files without tag ..." />



Regards, Gilbert

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to