You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@ant.apache.org by Vladimir Egorov <ve...@bea.com> on 2006/10/27 18:29:15 UTC

a construct to ensure existence of files in collection?

Hi Ant Users,

I am using FileList to specify collection of files one by one. I need to
ensure that the specified files exist.

According to FileList doc, "FileLists are useful for specifying files
that may or may not exist". I checked some other path-like structures,
but did not find a straight-forward way to do this.

Is there something obvious I am missing? Any recommendations besides two
approaches listed below?

One approach is to enhance FileList with a 'failonerror' attribute, e.g.

<filelist dir='some/dir' failonerror='true'>
  <file name='some.file'/>
</filelist>

(also for individual <file name='some.file' failonerror='true'/>).

Another approach is to provide an assert task for the same, e.g.

<assertFilesExist>
  <filelist dir='some/dir'>
    <file name='some.file'/>
  </filelist>
</assertFileExist>

(also for reference <assertFilesExist refid='someref'/>).

Thank you,

--Vladimir
_______________________________________________________________________
Notice:  This email message, together with any attachments, may contain
information  of  BEA Systems,  Inc.,  its subsidiaries  and  affiliated
entities,  that may be confidential,  proprietary,  copyrighted  and/or
legally privileged, and is intended solely for the use of the individual
or entity named in this message. If you are not the intended recipient,
and have received this message in error, please immediately return this
by email and then delete it.

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


RE: a construct to ensure existence of files in collection?

Posted by Vladimir Egorov <ve...@bea.com>.
> -----Original Message-----
> From: Peter Reilly [mailto:peter.kitt.reilly@gmail.com]
> Sent: Friday, October 27, 2006 9:45 AM
> To: Ant Users List
> Subject: Re: a construct to ensure existence of files in collection?
> 
> On 10/27/06, Vladimir Egorov <ve...@bea.com> wrote:
> > Hi Ant Users,
> >
> > I am using FileList to specify collection of files one by one. I
need to
> > ensure that the specified files exist.
> >
> > According to FileList doc, "FileLists are useful for specifying
files
> > that may or may not exist". I checked some other path-like
structures,
> > but did not find a straight-forward way to do this.
> >
> > Is there something obvious I am missing? Any recommendations besides
two
> > approaches listed below?
> 
> I do not know any.

Thank you, good to know.

> >
> > One approach is to enhance FileList with a 'failonerror' attribute,
e.g.
> >
> > <filelist dir='some/dir' failonerror='true'>
> >   <file name='some.file'/>
> > </filelist>
> >
> > (also for individual <file name='some.file' failonerror='true'/>).
> >
> > Another approach is to provide an assert task for the same, e.g.
> >
> > <assertFilesExist>
> >   <filelist dir='some/dir'>
> >     <file name='some.file'/>
> >   </filelist>
> > </assertFileExist>
> Here is an implemenation of this:
>   <macrodef name="assertFilesExist" backtrace="no"
>      xmlns:ac="antlib:net.sf.antcontrib">
>     <element name="filelist" implicit="yes"/>
>     <sequential>
>       <ac:for param="file">
>         <filelist/>
>         <sequential>
>           <ac:if>
>             <available file="@{file}"/>
>             <else>
>               <fail>File @{file} does not exist</fail>
>             </else>
>           </ac:if>
>         </sequential>
>       </ac:for>
>     </sequential>
>   </macrodef>
> 
> (Just one problem, need a backtrace="no" attribute for <ac:for>).

This is more than I expected :) Thank you! Are you planning to add this
to your library of antunit asserts?

We are using ant-1.6.5 and the 'backtrace' attribute is not supported. I
will check what it means in terms of error reporting.
_______________________________________________________________________
Notice:  This email message, together with any attachments, may contain
information  of  BEA Systems,  Inc.,  its subsidiaries  and  affiliated
entities,  that may be confidential,  proprietary,  copyrighted  and/or
legally privileged, and is intended solely for the use of the individual
or entity named in this message. If you are not the intended recipient,
and have received this message in error, please immediately return this
by email and then delete it.

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


Re: a construct to ensure existence of files in collection?

Posted by Peter Reilly <pe...@gmail.com>.
On 10/27/06, Vladimir Egorov <ve...@bea.com> wrote:
> Hi Ant Users,
>
> I am using FileList to specify collection of files one by one. I need to
> ensure that the specified files exist.
>
> According to FileList doc, "FileLists are useful for specifying files
> that may or may not exist". I checked some other path-like structures,
> but did not find a straight-forward way to do this.
>
> Is there something obvious I am missing? Any recommendations besides two
> approaches listed below?

I do not know any.

>
> One approach is to enhance FileList with a 'failonerror' attribute, e.g.
>
> <filelist dir='some/dir' failonerror='true'>
>   <file name='some.file'/>
> </filelist>
>
> (also for individual <file name='some.file' failonerror='true'/>).
>
> Another approach is to provide an assert task for the same, e.g.
>
> <assertFilesExist>
>   <filelist dir='some/dir'>
>     <file name='some.file'/>
>   </filelist>
> </assertFileExist>
Here is an implemenation of this:
  <macrodef name="assertFilesExist" backtrace="no"
     xmlns:ac="antlib:net.sf.antcontrib">
    <element name="filelist" implicit="yes"/>
    <sequential>
      <ac:for param="file">
        <filelist/>
        <sequential>
          <ac:if>
            <available file="@{file}"/>
            <else>
              <fail>File @{file} does not exist</fail>
            </else>
          </ac:if>
        </sequential>
      </ac:for>
    </sequential>
  </macrodef>

(Just one problem, need a backtrace="no" attribute for <ac:for>).

Peter

>
> (also for reference <assertFilesExist refid='someref'/>).
>
> Thank you,
>
> --Vladimir
> _______________________________________________________________________
> Notice:  This email message, together with any attachments, may contain
> information  of  BEA Systems,  Inc.,  its subsidiaries  and  affiliated
> entities,  that may be confidential,  proprietary,  copyrighted  and/or
> legally privileged, and is intended solely for the use of the individual
> or entity named in this message. If you are not the intended recipient,
> and have received this message in error, please immediately return this
> by email and then delete it.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
> For additional commands, e-mail: user-help@ant.apache.org
>
>

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


RE: a construct to ensure existence of files in collection?

Posted by Vladimir Egorov <ve...@bea.com>.
Matt,

Thank you for your reply.

Peter Reilly also provided an implementation of assertFilesExist macro.
I am not sure if you saw his email, so I posted it below.

Regards,

--Vladimir


> <assertFilesExist>
>   <filelist dir='some/dir'>
>     <file name='some.file'/>
>   </filelist>
> </assertFileExist>
Here is an implemenation of this:
  <macrodef name="assertFilesExist" backtrace="no"
     xmlns:ac="antlib:net.sf.antcontrib">
    <element name="filelist" implicit="yes"/>
    <sequential>
      <ac:for param="file">
        <filelist/>
        <sequential>
          <ac:if>
            <available file="@{file}"/>
            <else>
              <fail>File @{file} does not exist</fail>
            </else>
          </ac:if>
        </sequential>
      </ac:for>
    </sequential>
  </macrodef>

(Just one problem, need a backtrace="no" attribute for <ac:for>).

> -----Original Message-----
> From: Matt Benson [mailto:gudnabrsam@yahoo.com]
> Sent: Friday, October 27, 2006 12:53 PM
> To: Ant Users List
> Subject: Re: a construct to ensure existence of files in collection?
> 
> --- Vladimir Egorov <ve...@bea.com> wrote:
> 
> > Hi Ant Users,
> >
> > I am using FileList to specify collection of files
> > one by one. I need to
> > ensure that the specified files exist.
> 
> There are different things you can do here.  Are you
> using a predefined "files" attribute, in a property
> perhaps?  In current versions of Ant (I think it was
> you who said you couldn't upgrade):
> 
> <project>
>   <property name="files" value="foo,bar,baz" />
> 
>   <fileset id="fs" dir="${basedir}"
> includes="${files}" />
>   <filelist id="fl" dir="${basedir}" files="${files}"
> />
> 
>   <pathconvert property="fs" dirsep="" pathsep=""
> refid="fs">
>     <mergemapper to="." />
>   </pathconvert>
> 
>   <pathconvert property="fl" dirsep="" pathsep=""
> refid="fl">
>     <mergemapper to="." />
>   </pathconvert>
> 
>   <fail>
>     <condition>
>       <not>
>         <equals arg1="${fs}" arg2="${fl}" />
>       </not>
>     </condition>
>   </fail>
> </project>
> 
> You can replace <fail><condition /></fail>, etc. with
> antunit assertions if you like...
> 
> In Ant 1.7, it's slightly more straightforward:
> 
> <project>
>   <property name="files" value="foo,bar,baz" />
> 
>   <filelist id="fl" dir="${basedir}" files="${files}"
> />
> 
>   <fail>
>     <condition>
>       <resourcecount when="gt" count="0">
>         <restrict>
>           <filelist dir="${basedir}" files="${files}"
> />
>           <not
> xmlns="antlib:org.apache.tools.ant.types.resources.selectors">
>             <exists />
>           </not>
>         </restrict>
>       </resourcecount>
>     </condition>
>   </fail>
> </project>
> 
> HTH,
> Matt
> 
> 
> __________________________________________________
> Do You Yahoo!?
> Tired of spam?  Yahoo! Mail has the best spam protection around
> http://mail.yahoo.com
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
> For additional commands, e-mail: user-help@ant.apache.org

_______________________________________________________________________
Notice:  This email message, together with any attachments, may contain
information  of  BEA Systems,  Inc.,  its subsidiaries  and  affiliated
entities,  that may be confidential,  proprietary,  copyrighted  and/or
legally privileged, and is intended solely for the use of the individual
or entity named in this message. If you are not the intended recipient,
and have received this message in error, please immediately return this
by email and then delete it.

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


Re: a construct to ensure existence of files in collection?

Posted by Matt Benson <gu...@yahoo.com>.
--- Vladimir Egorov <ve...@bea.com> wrote:

> Hi Ant Users,
> 
> I am using FileList to specify collection of files
> one by one. I need to
> ensure that the specified files exist.

There are different things you can do here.  Are you
using a predefined "files" attribute, in a property
perhaps?  In current versions of Ant (I think it was
you who said you couldn't upgrade):

<project>
  <property name="files" value="foo,bar,baz" />

  <fileset id="fs" dir="${basedir}"
includes="${files}" />
  <filelist id="fl" dir="${basedir}" files="${files}"
/>

  <pathconvert property="fs" dirsep="" pathsep=""
refid="fs">
    <mergemapper to="." />
  </pathconvert>

  <pathconvert property="fl" dirsep="" pathsep=""
refid="fl">
    <mergemapper to="." />
  </pathconvert>

  <fail>
    <condition>
      <not>
        <equals arg1="${fs}" arg2="${fl}" />
      </not>
    </condition>
  </fail>
</project>

You can replace <fail><condition /></fail>, etc. with
antunit assertions if you like...

In Ant 1.7, it's slightly more straightforward:

<project>
  <property name="files" value="foo,bar,baz" />

  <filelist id="fl" dir="${basedir}" files="${files}"
/>

  <fail>
    <condition>
      <resourcecount when="gt" count="0">
        <restrict>
          <filelist dir="${basedir}" files="${files}"
/>
          <not
xmlns="antlib:org.apache.tools.ant.types.resources.selectors">
            <exists />
          </not>
        </restrict>
      </resourcecount>
    </condition>
  </fail>
</project>

HTH,
Matt


__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 

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