ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Mike K. Cepek" <>
Subject RE: fail <tar> when file does not exist
Date Fri, 13 Feb 2009 17:41:24 GMT
Thanks for the suggestions, David.  In all of our cases we are using
<tar> to bundle many files.  There are dozens of <include>s specifying a
single file each, and those need to fail if the file doesn't exist.
Additional <include>s use wildcards, and ideally those would also fail
if they didn't resolve to any actual files.

Counting the number of files for each <tarfileset> is an interesting
approach.  But since our <tarfileset>s often include both individually
named files and wildcarded sets of files, maintaining that exact value
would not be feasible.  And an approximate value doesn't accomplish the
goal.  Again, we need to detect any specified file(s) which are not
present when the tarball is being created.

In this bug report:
I suggested something simpler, like a WHENEMPTY or FAILONERROR attribute
for <tarfileset> or elsewhere.  Matt Benson closed that bug report
suggesting that Resource Collections can do this.  I'm just trying to
learn HOW they can do this.  Thanks.

-----Original Message-----
From: David Weintraub [] 
Sent: Friday, February 13, 2009 11:22 AM
To: Ant Users List
Subject: Re: fail <tar> when file does not exist

If you're just tarring up a single file, then you can use available to
see if that file actually exists:

<available property="tarfile.exists"

<target name="tar"
     <blah, blah, blah>

If you have more than one file and you want to make sure you have at
least one file to tar up, you can save your tarfileset as a
patternset, then use resourceCount against that.

Then, when you setup your tarfileset, you can refer to the patternset
ID. Something like this:

<patternset id="tar.fileset">
    <include name="sprint/**"/>

<resourceCount property=""

<target name="tar"
    <tar destfile="product.tar.gz" compression="gzip">
        <tarfileset dir="release/prod>
             <patternset refid="tar.fileset"/>

---- On Fri, Feb 13, 2009 at 10:56 AM, Mike K. Cepek
<> wrote:

> I'd like my <tar> task to fail if the files I specify don't exist.  I
> currently make use of the prefix, username, group and (sometimes) mode
> attributes of <tarfileset>, so I can't lose that functionality.
> From the Ant Manual, it looks like the new Resource Collection support
> can handle this.  But as a mere Ant user, and not Ant expert, I'm
> struggling with how to reformulate my <tar> task to accomplish this.
> couldn't seem to locate any examples or tutorials for Resources.  So I
> thought I'd write here for help.
> Here's a reduced version of the task I want to fail.  If the menu.xml
> file doesn't exist, I'd like the <tar> to abort:
> <tar destfile="product.tar.gz" compression="gzip">
>  <tarfileset dir="release/prod" prefix="conf" username="admin"
> group="admin">
>    <include name="spring/menu.xml"/>
>  </tarfileset>
> </tar>
> Normally each <tar> has multiple <tarfileset>s which in turn have
> multiple <include>s.
> I tried adding <restrict> and <rsel:exist> and <control> and <resource
> name="*">, but Eclipse (v3.4) doesn't seem to like my syntax, as it
> claims "The prefix 'rsel' for element 'rsel:exist' is not bound",
> only confuses me more.  So...
> 1) Can I accomplish what I want to do with Resources and/or Resource
> Collections?  If so, how should the above be rewritten?
> 2) Are there other resources, ideally with examples, to help
> how to use Resources and Resource Collections?
> Thanks.

David Weintraub

To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message