• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Ant check existence for a set of files and take action

 
Greenhorn
Posts: 8
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello All,

I have a very urgent requirement which I need help & guidance, user passes a list of files in an XML file,below will be the sample

<property-bundle name = "abc">
<action>clean</action>
<target-location>/vst/property/pog/</target-location>
<file-name>test1.props</file-name>
<file-name>test2.props</file-name>
<file-name>test3.props</file-name>
</property-bundle>

Now based on that action remove, I have to incorporate logic in build.xml to delete the files in the directory , but for that I want to perform a validation only if the file exists and the list does not contain any special characters then remove files or else throw the build failure error. I was able to read the values from the user input XML and takes those files into a file list property
<property name="file.list" value="test1.props,test2.props,test3.props"/>
<target name = "clean">
<delete>
<fileset dir="${target.location}" includes = "${file.list}"/>
</delete>
</target>

But with the clean target it only validates if the directory exists since it is fileset but does not do the validation if file exists , I read that filelist does validation for file exists but filelist can not work with delete.
we are using ANT version that comes with our WebSphere in our environment and the version 1.6.5 becuse we are using some of the WebSphere Custom defined ANT tasks, We could not update ANT as it is tightly coupled with our WebSphere upgrade.

I am open to use ant-contrib or any other extenral libraries to solve this , Can you please kindly help me to acheieve this requirement
 
author & internet detective
Posts: 41860
908
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Welcome to CodeRanch!

I think you need ant-contrib. It has a foreach loop. That lets you iterate through the filenames to check if they exists. It also contains propertyregexp which lets you check for special characters in your list of filenames.
 
korukanti rao
Greenhorn
Posts: 8
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
@Jeanne- Thank you , I have tried with using ant-contrib, but the issue is it does not set any information if the file does not exist , I have used the below approaches

Can you please help if i am doing anything wrong

Approach 1

In this if a file from the list does not exist in the target location , the condition property(is.validifile) is not getting set to true so there is no failure error



Approach 2

In this approach also the same error as Aproach 1



Approach 3

In this approach , it never goes to else condition if the file does not exist


 
Jeanne Boyarsky
author & internet detective
Posts: 41860
908
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Approach three is really close. The problem is that by using a fileset, you are limiting yourself to files that exist.

Try this minor modification of approach three. It goes through each file in file.list and checks if it exists.

 
korukanti rao
Greenhorn
Posts: 8
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
@Jeanne - Awesome , you are the best .... It worked like a charm.

Thank you very much , I had been struggling with this from more than a week , you saved my day.

Thanks a lot , I really appreciate all your help and guidance.

Regards
 
Jeanne Boyarsky
author & internet detective
Posts: 41860
908
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You're welcome. I'm giving a cow for being patient and working through it. We really like seeing people learn and by writing most of it yourself, we got to see that.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic