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?
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