ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Jan.Mate...@rzf.fin-nrw.de
Subject RE: How to pass a fileset as parameter
Date Tue, 15 Jul 2003 11:37:34 GMT
So, I have done a little example which works for me:


<?xml version="1.0" encoding="ISO-8859-1"?>
<project name="test" basedir="." default="main">
    <taskdef resource="net/sf/antcontrib/antcontrib.properties"/>
    <target name="main">
        <!-- easier access to fileset´s 'dir' -->
        <property name="fs.dir" value="."/>
        <!-- define the fileset -->
        <fileset id="fs" dir="${fs.dir}" includes="C*.pdf"/>

        <foreach target="do" param="file">
            <!-- iterate over this files -->
            <path><fileset refid="fs"/></path>
            <!-- additional params: all files and the dir -->
            <param name="fs.files" refid="fs"/>
            <param name="fs.dir"   value="${fs.dir}"/>
        </foreach>
    </target>

    <target name="do">
        <!-- recreate the fileset -->
        <path id="path"><pathelement path="${fs.files}"/></path>
        <pathtofileset name="fsNew" dir="${fs.dir}" pathrefid="path"/>

        <!-- use that fileset -->
        <pathconvert property="fs.value" refid="fsNew" targetos="windows"/>
        <echo>path = ${fs.value}</echo>
    </target>
</project>



Jan




> -----Original Message-----
> From: Daniel Joshua [mailto:daniel.joshua@gridnode.com]
> Sent: Tuesday, July 15, 2003 12:50 PM
> To: 'Ant Users List'
> Subject: RE: How to pass a fileset as parameter 
> 
> 
> >   ...
> >     <fileset id="db.sqlscripts.fileset" ... />
> >     <antcall target="record.sqlscripts" ... />
> >   ...
> >
> >   <target name="record.sqlscripts">
> >     <pathconvert property="db.sqlscripts.fileset.value"
> >                  refid="db.sqlscripts.fileset"
> >                  pathsep=","
> >     />
> >     <foreach ... list="${db.sqlscripts.fileset.value}" />
> >   </target>
> 
> This wouldn't work cause the fileset reference will not be 
> passed by the
> antcall.
> Maybe you meant this:
> 
>    ...
>      <fileset id="db.sqlscripts.fileset" ... />
>      <antcall target="record.sqlscripts" ... />
>      <pathconvert property="db.sqlscripts.fileset.value"
>                   refid="db.sqlscripts.fileset"
>                   pathsep=","
>      />
>    ...
> 
>    <target name="record.sqlscripts">
>      <foreach ... list="${db.sqlscripts.fileset.value}" />
>    </target>
> 
> However, I would like to pass a fileset and not a string of all the
> filesname.
> This is because I used the fileset in different ways which I 
> did not show in
> my email, eg:
> 
>     <apply executable="${layer.dir}/dbscript.bat">
>       <arg value="${db.exec.cmd}"/>
>       <fileset refid="db.sqlscripts.fileset"/>
>     </apply>
> 
> Although, I could always recreate the fileset using that string. Just
> thought there is a better way.
> 
> 
> 
> Regards,
> Daniel
> 
> 
> -----Original Message-----
> From: Jan.Materne@rzf.fin-nrw.de [mailto:Jan.Materne@rzf.fin-nrw.de]
> Sent: Tuesday, 15 July, 2003 6:37 PM
> To: user@ant.apache.org
> Subject: RE: How to pass a fileset as parameter
> 
> 
> > > <property name="fs.value" refid="thefileset"/>
> >
> > This seems interesting. I assume that this will work even with
> > [inheritRefs="false"]
> 
> Sure, that is a simple property, not a reference.
> 
> 
> >      <fileset id="db.sqlscripts.fileset"
> >               dir="${dbscript.dir}"
> >               includes="patch*.sql"
> >               excludes="${excludes}"/>
> >      <property name="fs.value" refid="db.sqlscripts.fileset"/>
> >      <antcall target="record.sqlscripts" inheritRefs="false"/>
> >    ...
> >
> >    <target name="record.sqlscripts">
> >      <foreach target="record.sqlscript"
> >               param="sqlscript.file"
> >               inheritall="true">
> 
> >        <path>
> >          <fileset refid="${fs.value}"/>
> >        </path>
> 
> Don´t use the <path> here. Use the 'list' attribute. The 
> property 'fs.value'
> contains all
> the files the fileset has selected. Try it with 
> <echo>${fs.value}</echo>.
> But ensure that the same file separator is used: for foreach 
> and for the
> property. You
> can set the separator with foreach´s 'delimiter' attribute or 
> you can use
> <pathconvert/> for
> setting the property.
> 
> See my example in the last post.
> 
> 
> >      </foreach>
> >    </target>
> >
> >
> >
> 
> Here again that example
> 
> 
> >   ...
> >     <fileset id="db.sqlscripts.fileset" ... />
> >     <antcall target="record.sqlscripts" ... />
> >   ...
> >
> >   <target name="record.sqlscripts">
> >     <pathconvert property="db.sqlscripts.fileset.value"
> >                  refid="db.sqlscripts.fileset"
> >                  pathsep=","
> >     />
> >     <foreach ... list="${db.sqlscripts.fileset.value}" />
> >   </target>
> >
> 
> 
> 
> Jan
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
> For additional commands, e-mail: user-help@ant.apache.org
> 

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message