You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@ant.apache.org by Shawn Castrianni <Sh...@halliburton.com> on 2008/06/09 06:22:32 UTC

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?

---
Shawn Castrianni

----------------------------------------------------------------------
This e-mail, including any attached files, may contain confidential and privileged information for the sole use of the intended recipient.  Any review, use, distribution, or disclosure by others is strictly prohibited.  If you are not the intended recipient (or authorized to receive information for the intended recipient), please contact the sender by reply e-mail and delete all copies of this message.

Re: appending to fileset

Posted by Dominique Devienne <dd...@gmail.com>.
On Sun, Jun 8, 2008 at 11:22 PM, Shawn Castrianni
<Sh...@halliburton.com> wrote:
> 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?

(impressive solution Gilbert BTW. I had no idea something like this
was possible)

Shawn, I believe that incrementally adding files to a fileset is going
against the philosophy of <fileset>. A  fileset is designed to scan a
directory for *existing* files, and add a subset of them to an
internal list when requested by client tasks (I don't remember if it
caches the list or not). Forcibly adding files to a fileset, if
possible at all, should be strongly discouraged. <filelist> and <path>
are the datatypes which accept arbitrary files (i.e. not necessarily
rooted in the same directory), where the files can be non-existent,
and or better choices if you persist in the adding-files direction.
(or possible the new ResourceCollection, which I never studied)

Now if the files mentioned in your XML file do exist, a better
approach is to code in a new FileSelector which is configured with
your XML file, to have the files mentioned (by name or pattern) added
to the subset of files held by the fileset (after scanning). You
selector parses the XML as a one time initialization, building an
internal PatternSet or composite selector (you have
AbstractCompositeSelector in buildmagic already doing the plumbing),
and yea or nay scanned files using either (see MultiPresentSelector or
NonePresentSelector NonePresentSelector as examples).

Without more details, it's hard to propose any alternative solutions. --DD

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org


RE: appending to fileset

Posted by "Rebhan, Gilbert" <Gi...@huk-coburg.de>.
 

-----Original Message-----
From: Shawn Castrianni [mailto:Shawn.Castrianni@halliburton.com] 
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: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org