2

I think this may be easiest explained by an example, so here goes:

<target name="test">
    <fileset id="fileset" dir="target">
        <include name="*"/>
    </fileset>
    <echo>${toString:fileset}</echo>
    <touch file="target/test"/>
    <echo>${toString:fileset}</echo>
</target>

Outputs:

test:
     [echo] 
    [touch] Creating target/test
     [echo] test

What I ideally want is to have the fileset stay the same so I can have a before/after set (in order to get a changed set using <difference>, so if you know of a way to skip right to that...).

I've tried using <filelist> instead, but I can't get this correctly populated and compared in the <difference> task (they're also hard to debug since I can't seem to output their contents). I also tried using <modified/> to select files in the fileset, but it doesn't seem to work at all and always returns nothing.

Even if there is an alternative approach I would appreciate a better understanding of what ANT is doing in the example above and why.

Vala
  • 5,628
  • 1
  • 29
  • 55

3 Answers3

2

A fileset is something like a selector. It's a set of "instructions" (inclusions, exclusions, patterns) allowing to get a set of files.

Each time you actually do something with the fileset (like printing the files it "references"), the actual set of files is computed based on the "instructions" contained in the fileset.

JB Nizet
  • 678,734
  • 91
  • 1,224
  • 1,255
2

The path selector is evaluated on the fly. When a file is added, it will reflect in the set when you use it.

You may able to evaluate and keep it in variable using pathconvert. Then this can be converted back to filest using pathtofilest

Jayan
  • 18,003
  • 15
  • 89
  • 143
  • Converting it back to a fileset is useless for my purposes, but since pathconvert stores it as a string property that makes it easy to make filelists that I can then use in the `` task. Thanks. – Vala Sep 17 '12 at 10:11
1

As Jayan pointed out it might be worth posting the final outcome as an answer, so here's a simplified version with the key parts:

<fileset id="files" dir="${target.dir}"/>
<pathconvert property="before.files" pathsep=",">
    <fileset refid="files"/>
</pathconvert>
<!-- Other Ant code changes the file-system. -->
<pathconvert property="after.files" pathsep=",">
    <fileset refid="files"/>
</pathconvert>
<filelist id="before.files" files="${before.files}"/>
<filelist id="after.files" files="${after.files}"/>
<difference id="changed.files">
    <filelist refid="before.files"/>
    <filelist refid="after.files"/>
</difference>
Vala
  • 5,628
  • 1
  • 29
  • 55