Win a copy of Five Lines of Code this week in the OO, Patterns, UML and Refactoring forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

Creating a tar with Ant and the "includesfile" attribute.

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have an Ant script which is sitting on a remote server whose purpose is to create a tar. The file names to be tarred are manually listed in a file that will be uploaded to that server, and the name of that file will be listed in the "includesfile" attribute of the Ant tar task. There is an Ant script on my local machine which manages all of this. Occasionally the file containing the file names will be blank because nothing needs to be tarred, and I have learned the hard way, that if this is the case, all files in the base directory get tarred, and then later un-tarred, which can cause some problems. As far as I can tell, the "excludes" attribute of the tar tag trumps the "includesfile" attribute, so I can't exclude everything except what is in the given file. Is there a "clean" way to handle the blank includesfile situation so that I can have a blank file and not tar everything?

Thanks so much for your input!
Trish
 
drifter
Posts: 1364
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Not sure what your constraints are. Easy answer is to make sure some innocuous file is always listed in the includesfile.

See code below for a possible solution where you load the contents of the text file (the includesfile) into a property using loadfile task where it strips linebreaks in case any exist in "empty" file. The tar target can check to see if property set (empty file resulted in property not being set for me). This doesn't build a tar if file is empty, but if you need to do something different when the file is empty you can use unless test that's similar to the if test.



Output :
C:\>ant (file has something in it)
Buildfile: build.xml

cleanLast:
[delete] Deleting: C:\_Work\java\src\antcompile\tarball.tar

fileToProp:
[echo] File contents is 'README'

tarball:
[tar] Building tar: C:\_Work\java\src\antcompile\tarball.tar

BUILD SUCCESSFUL
Total time: 1 second
C:\>ant (empty file)
Buildfile: build.xml

cleanLast:
[delete] Deleting: C:\_Work\java\src\antcompile\tarball.tar

fileToProp:
[echo] File contents is '${tar.file.list}'

tarball:

BUILD SUCCESSFUL
Total time: 0 seconds
 
Tricia Ball
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you! That looks like it will do exactly what I need. I didn't even thing about reading in the file again.

Thanks again!
Trish
 
Consider Paul's rocket mass heater.
    Bookmark Topic Watch Topic
  • New Topic