Sorry for not having the right time to digg into your solution.

Two workaround come into my mind:

1. Copy your whitelisted files into a tmp directory, delete the whole src 
directory and copy the whitelisted files back

2. Use <pathconvert> to convert your whitelist to an excludes-clause and use 
<delete><fileset .. excludes="${whiteliste.excludes}"/>

 

Jan

 

Von: Jason Guild [mailto:jason.gu...@alaska.gov] 
Gesendet: Mittwoch, 18. Juli 2018 01:45
An: user@ant.apache.org
Betreff: deleting files not in whitelist

 

Hello:

I have a build file which declares a <resources> containing a list of expected 
files which are relative to some directory. I am trying to delete any files 
from that directory which /are not present/ in the <resourcelist>, and I can't 
figure out how to do that with the <delete> task and my understanding of the 
standard selectors.

Here's my resource list:

<resources id="my-whitelist">
    <resourcelist basedir="${some.dir}">
        <url url="${target.files.url}"/>
    </resourcelist>
</resources>

Basically my-whitelist is simply a list of filenames which are expected to 
exist relative to ${some.dir}.

In a target, I would like to somehow use the <delete> task to delete any files 
found in ${some.dir} which are /not listed in/ "my-whitelist", like this:

<delete dir="${some.dir}">
    <not>
        <resources refid="my-whitelist"/>
    </not>
</delete>

But this doesn't work. I also tried:

<delete>
    <restrict>
        <fileset dir="${some.dir}"/>
        <rsel:not 
xmlns:rsel="antlib:org.apache.tools.ant.types.resources.selectors">
            <resources refid="my-whitelist"/>
        </rsel:not>
    </restrict>
</delete>

Which doesn't work either.
Any help you can provide would be appreciated.



Thanks,
Jason

Reply via email to