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 17:21:50 GMT
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.
>
>
> ---------------------------------------------------------------------
> 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