0

This ANT delete task functions perfectly if the directory contains either FOO.xml or BAR.xml (or both), but will not return successfully if they do not exist.

<delete includeemptydirs="true" followsymlinks="false">
    <fileset dir="${apache.base}" erroronmissingdir="false">
        <include name="**/*"/>
        <exclude name="**/FOO.xml **/BAR.xml"/>
     </fileset>
</delete>  

Is there a way I could have it work regardless of whether the exclude section of the fileset is empty or not?

Mr S
  • 458
  • 3
  • 7
  • 15

1 Answers1

1

Your exclude pattern contains incorrect syntax. When using nested include or exclude elements, file name patterns need to be listed separately, as such:

<delete includeemptydirs="true" followsymlinks="false">
    <fileset dir="${apache.base}" erroronmissingdir="false">
        <exclude name="**/FOO.xml"/>
        <exclude name="**/BAR.xml"/>
        <include name="**/*"/>
    </fileset>
</delete>

However, if you use fileset's includes or excludes attributes, a comma-delimited list will actually work;

<delete includeemptydirs="true" followsymlinks="false">
    <fileset
        dir="${apache.base}"
        includes="**/*"
        excludes="**/FOO.xml,**/BAR.xml"
    />
</delete>
CAustin
  • 4,525
  • 13
  • 25
  • Though this may be a separate issue, this does not fix my problem. The code above still results in a failure if neither FOO.xml or BAR.xml exist, and my code, with the possible syntax error, functions correctly if FOO.xml or BAR.xml exist. – Mr S Apr 02 '18 at 21:11
  • @MrS Can you edit your question to include the exact error message you're getting? I'm not able to reproduce your problem. – CAustin Apr 02 '18 at 23:43
  • I have added the error and also the fact the issue is happening via jenkins. I am not sure if that would be contributing. – Mr S Apr 03 '18 at 16:23
  • I am an idiot and when I tried to implement your suggested changes I never actually deployed them. They work. Thank you very much. – Mr S Apr 04 '18 at 16:52