-----Original Message-----
From: Shawn Castrianni [mailto:[EMAIL PROTECTED] 
Sent: Monday, June 09, 2008 6:23 AM
To: 'Ant Users List'
Subject: appending to fileset

/*
Is there a way to incrementally add files to a fileset?  I am building a
fileset by looping through an XML file and need to add files to a named
fileset one by one if they meet certain criteria.  Is this possible
without converting everything into paths or strings or stuff like that?
*/

quick shot, untested, seems a bit long winded
maybe there's a better/shorter solution ?!

don't know your xml, so i took an example structure =
...
<file>
<file.1>
<name>...</name>
</file.1>
<file.2>
<name>...</name>
</file.2>
...

<!-- Import AntContrib -->
<taskdef resource="net/sf/antcontrib/antlib.xml" />
<!-- Import XMLTask -->
<taskdef name="xmltask"
classname="com.oopsconsultancy.xmltask.ant.XmlTask"/>

<target name="...">

<patternset id="basic_files" includes="*.txt **/*.properties"/>
    
   <fileset dir="Y:/test" id="namedfileset">
    <patternset refid="basic_files"/>
   </fileset>

  <var name="filelist" value=""/>

  <xmltask source="your.xml">
    <call path="//file/*">
      <param path="name/text()" name="fname" />
      <actions>
        <if>
          <your condition(s) goes here ... />
            <then>
            <var name="filelist_tmp" value="${filelist}"/>
            <var name="filelist" unset="true"/>
            <var name="filelist" value="${filelist_tmp} @{fname}"/>
            </then>
        </if>
      </actions>
    </call>
  </xmltask>    

<patternset id="ext_files" includes="${filelist}"/>

<fileset dir="Y:/test" id="ext_namedfileset">
  <patternset refid="ext_files"/>
  <patternset refid="basic_files"/>
</fileset>
  
</target>


notes =
when using patternset you are more flexible
with the appropriate xpath expression and your condition(s) between
<actions>  <if> ... </if> ...</actions> you take control what is matched
and
whether the matched gets included in the space separated patternset
(don't know whether the blank at the end of ${filelist} is a problem !?)
Beside that you can put other tasks into the <actions .../> scope if
needed

then later construct a fileset with the same dir as your first fileset
and include
both patternsets via refid= ... and finally you have your extended
fileset.

you need =
[1] http://www.oopsconsultancy.com/software/xmltask/
[2] http://ant-contrib.sourceforge.net/


Regards, Gilbert

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

Reply via email to