ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From David Weintraub <qazw...@gmail.com>
Subject Re: fail <tar> when file does not exist
Date Fri, 13 Feb 2009 20:50:57 GMT
>  Again, we need to detect any specified file(s) which are not present when the tarball
is being created.

In that case, simply use <available> to check for those files before
running your tarball.

Or, even better, combine the <fail> task with the <available> condition:

<fail message="No tarball for you!">
   <condition>
       <not>
          <and>
             <available file="${foo}" type="file"/>
             <available file="${bar}" type="file"/>
             <available file="${barfoo}" type="file"/>
         </and>
      </not>
   </condition>
</fail>
<tar destfile="product.tar.gz" compression="gzip">

The above will fail if any of those three files don't exist.

On Fri, Feb 13, 2009 at 12:41 PM, Mike K. Cepek
<Mike.Cepek@visionshareinc.com> wrote:
> 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:
> https://issues.apache.org/bugzilla/show_bug.cgi?id=32526
> 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 [mailto:qazwart@gmail.com]
> 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"
>    file="release/prod/spring/menu.xml"
>    type="file"/>
>
> <target name="tar"
>   if="tarfile.exists">
>   <tar>
>     <blah, blah, blah>
>   </tar>
> </target>
>
> 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/**"/>
> </patternset>
>
> <resourceCount property="atleast.one.file.to.tar"
>     count="1"
>     when="ge">
>
> <target name="tar"
>    depends="atleast.one.file.to.tar">
>    <tar destfile="product.tar.gz" compression="gzip">
>        <tarfileset dir="release/prod>
>             <patternset refid="tar.fileset"/>
>    </tarfileset>
>    </tar>
> </target>
>
>
> ---- On Fri, Feb 13, 2009 at 10:56 AM, Mike K. Cepek
> <Mike.Cepek@visionshareinc.com> 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.
> I
>> 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",
> which
>> 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
> illustrate
>> how to use Resources and Resource Collections?
>>
>> Thanks.
>
> --
> David Weintraub
> qazwart@gmail.com
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
> For additional commands, e-mail: user-help@ant.apache.org
>
>



-- 
--
David Weintraub
qazwart@gmail.com

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org


Mime
View raw message