0

I am trying to delete list of files using Ant 1.6.5 , but I have to put a condition that if only the file exists delete it or else throw a build failure error to user, I have got the below snipped from the forums here , but when i modify accordingly in my environment it is not working.

  <property name="file.list" value="test1.props,test2.props,test3.props"/>
  <target name="file.missing" depends="validate.dir">
    <echo message = " The Filelist is : ${file.list} "/>
    <condition property="is.missing">
      <resourcecount when="ne" count="0">
        <difference id="is.missing">
          <intersect>
            <filelist id="required" dir="${target.location}" files="${file.list}"/>
            <fileset id="existing" dir="${target.location}" includes="*.*"/>
          </intersect>
          <filelist refid="required"/>
        </difference>
      </resourcecount>
    </condition>
    <fail if="is.missing" message= " File ${toString:missing} is missing from the list of files provided for removing, please recheck and submit correct "/>
  </target>

  <target name = "clean" unless="is.missing" depends="file.missing">
        <delete>
               <fileset dir="${target.location}" includes  = "${file.list}"/>
         </delete>
  </target>

i am getting a compile time error with this code , and the error is Class org.apache.tools.ant.taskdefs.ConditionTask doesn't support the nested "resourcecount" element.

Can some one please guide me on this

AlBlue
  • 23,254
  • 14
  • 71
  • 91

2 Answers2

2

<resourcecount> was introduced in Ant 1.7.

Further, Resource Collections such as <difference> and <intersect> weren't available until Ant 1.7 as well.

Chad Nouis
  • 6,861
  • 1
  • 27
  • 28
  • Thank you Chad, I was also going through it and noticed , Can you please guide me if there is any other way to achieve it , I am very much new to this ANT and it is very much bureaucratic & painful process to upgrade ANT in my work place , So some how I am trying to find a solution if I can implement this in ANT 1.6.5 . – user3403584 Mar 13 '14 at 15:05
1

Simply using delete task with nested fileset and attribute failonerror="true" will be sufficient.

<delete failonerror="true">
 <fileset dir="some/path"/>
</delete>

You will get a BUILD FAILED if the directory does not exist.

Rebse
  • 10,307
  • 2
  • 38
  • 66
  • Rebse- I have already tested that condition, but I am mainly looking to achieve if file is a not a found among the list of files then throw a build failure error. This is because user will specify list of files to be cleared in a separate property file and my ANT scrip should read the list of files specified by user and first search for them if they exist in the path then only delete – user3403584 Mar 13 '14 at 21:48