You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@ant.apache.org by Philippe Bonnardel <ph...@winsoft.fr> on 2003/06/05 09:44:28 UTC

RE: append line to a list of file : The solution

Here is a solution

Thanks to Peter and all of you for your help

Philippe

<target name="updateLocHeaderFiles" if="isWin" depends="init">
  <path id="headerspath" >
  <fileset id="headerfiles" dir="${toDir}" includes="**/headers/*.h"
excludes="**/ENU/*.h"/>
  </path>

  <script language="javascript"> <![CDATA[
        importPackage(Packages.org.apache.tools.ant.types);
        importPackage(Packages.org.apache.tools.ant.taskdefs);
        importPackage(java.util);
        importPackage(java.io);
        prj = self.getProject();
        var fileSeparator =
self.getProject().getProperty("file.separator");

        // Get the DirectoryScanner
        // project is an object defined by script task
        tDirectoryScanner = headerfiles.getDirectoryScanner(project);
        // Get the source files (array)
        srcFiles = tDirectoryScanner.getIncludedFiles();

        echo = prj.createTask("echo");
        echo.setMessage(" ================== file update Start");
        echo.execute();
        for (var i1=0;i1<srcFiles.length;i1++)
        {
           filename = toDir + fileSeparator + srcFiles[i1];

           antcall=project.createTask("antcall");
           antcall.init();
           antcall.setTarget("addCR");
           antcallParam=antcall.createParam();
           antcallParam.setName("filename");
           antcallParam.setValue( filename); // just filename..not full
path :(
           antcall.execute();
        }
        echo.setMessage(" ================== updated "+srcFiles.length+"
files");
        echo.execute();

    ]]> </script>
</target>

  <target name="addCR" >
   <echo message="updating ${filename}"/>
   <echo file="${filename}" append ="true" message="${line.separator}
${line.separator}"/>
  </target>


-----Original Message-----
From: Magesh Umasankar [mailto:umagesh@apache.org] 
Sent: Wednesday, June 04, 2003 7:27 PM
To: Ant Users List
Subject: Re: append line to a list of file


Write a filterreader to do your custom file-by-file manipulation and use
it inside the fileset compatible 
<copy> or <move> tasks.

----- Original Message ----- 
From: "Philippe Bonnardel" <ph...@winsoft.fr>
To: "'Ant Users List'" <us...@ant.apache.org>
Sent: Wednesday, June 04, 2003 1:10 PM
Subject: RE: append line to a list of file


> Meaning how can we access to each element of a fileset or a filelist?
> 
> Philippe
> 
> -----Original Message-----
> From: Philippe Bonnardel [mailto:philippe.bonnardel@winsoft.fr]
> Sent: Wednesday, June 04, 2003 7:05 PM
> To: 'Ant Users List'
> Subject: RE: append line to a list of file
> 
> 
> Hi Peter
> 
> Ok I got this, but how to you access to each file in this case in 
> order to append to each file something?
> 
> Philippe
> 
> 
> -----Original Message-----
> From: peter reilly [mailto:peter.reilly@corvil.com]
> Sent: Wednesday, June 04, 2003 6:54 PM
> To: Ant Users List
> Subject: Re: append line to a list of file
> 
> 
> Use Pathconvert:
>   <filelist dir="." files="build.xml,k.xml" id="filelist"/>
>   <pathconvert property="converted" pathsep="${line.separator}"
>                refid="filelist"/>
>   <echo message="converted is ${line.separator}${converted}"/>
> 
> Peter
> On Wednesday 04 June 2003 16:11, Philippe Bonnardel wrote:
> > Hi all
> >
> > I'm guetting an head-ach on this.
> > I'd like to add new lines to a list of file.
> > I was thinking about using fileset and echo but how to get the file 
> > one by one in order to echo my carriage returns in each file of the 
> > fileset. Should I use antcall? If so, how?
> >
> > Hope somebody was facing a kind of same issue.
> >
> > Thanks for any answer
> >
> > Regards
> >
> > Philippe Bonnardel.
> > --------------------------------------------------------------------
> > -
> > E-Paper Software Engineer
> > Winsoft S.A. ( <http://www.winsoft.fr/> http://www.winsoft.fr)
> > <ma...@winsoft.fr> philippe.bonnardel@winsoft.fr
> > Tel: +33 438 022 231  Fax: +33 438 022 211
> > --------------------------------------------------------------------
> 
> 
> ---------------------------------------------------------------------
> 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
> 
> 
> ---------------------------------------------------------------------
> 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


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


Re: append line to a list of file : The solution

Posted by peter reilly <pe...@corvil.com>.
Cool,
However I do not like modifing files in-place
as it messes up timestamps, and it is difficult
to control (that said, in-place modification does
have it's place for generated files).

What I would do in this case is use copy to
copy the files to a generated directory, with
a custom filter to add the nl.

Peter.


On Thursday 05 June 2003 08:44, Philippe Bonnardel wrote:
> Here is a solution
>
> Thanks to Peter and all of you for your help
>
> Philippe
>
> <target name="updateLocHeaderFiles" if="isWin" depends="init">
>   <path id="headerspath" >
>   <fileset id="headerfiles" dir="${toDir}" includes="**/headers/*.h"
> excludes="**/ENU/*.h"/>
>   </path>
>
>   <script language="javascript"> <![CDATA[
>         importPackage(Packages.org.apache.tools.ant.types);
>         importPackage(Packages.org.apache.tools.ant.taskdefs);
>         importPackage(java.util);
>         importPackage(java.io);
>         prj = self.getProject();
>         var fileSeparator =
> self.getProject().getProperty("file.separator");
>
>         // Get the DirectoryScanner
>         // project is an object defined by script task
>         tDirectoryScanner = headerfiles.getDirectoryScanner(project);
>         // Get the source files (array)
>         srcFiles = tDirectoryScanner.getIncludedFiles();
>
>         echo = prj.createTask("echo");
>         echo.setMessage(" ================== file update Start");
>         echo.execute();
>         for (var i1=0;i1<srcFiles.length;i1++)
>         {
>            filename = toDir + fileSeparator + srcFiles[i1];
>
>            antcall=project.createTask("antcall");
>            antcall.init();
>            antcall.setTarget("addCR");
>            antcallParam=antcall.createParam();
>            antcallParam.setName("filename");
>            antcallParam.setValue( filename); // just filename..not full
> path :(
>            antcall.execute();
>         }
>         echo.setMessage(" ================== updated "+srcFiles.length+"
> files");
>         echo.execute();
>
>     ]]> </script>
> </target>
>
>   <target name="addCR" >
>    <echo message="updating ${filename}"/>
>    <echo file="${filename}" append ="true" message="${line.separator}
> ${line.separator}"/>
>   </target>
>
>
> -----Original Message-----
> From: Magesh Umasankar [mailto:umagesh@apache.org]
> Sent: Wednesday, June 04, 2003 7:27 PM
> To: Ant Users List
> Subject: Re: append line to a list of file
>
>
> Write a filterreader to do your custom file-by-file manipulation and use
> it inside the fileset compatible
> <copy> or <move> tasks.
>
> ----- Original Message -----
> From: "Philippe Bonnardel" <ph...@winsoft.fr>
> To: "'Ant Users List'" <us...@ant.apache.org>
> Sent: Wednesday, June 04, 2003 1:10 PM
> Subject: RE: append line to a list of file
>
> > Meaning how can we access to each element of a fileset or a filelist?
> >
> > Philippe
> >
> > -----Original Message-----
> > From: Philippe Bonnardel [mailto:philippe.bonnardel@winsoft.fr]
> > Sent: Wednesday, June 04, 2003 7:05 PM
> > To: 'Ant Users List'
> > Subject: RE: append line to a list of file
> >
> >
> > Hi Peter
> >
> > Ok I got this, but how to you access to each file in this case in
> > order to append to each file something?
> >
> > Philippe
> >
> >
> > -----Original Message-----
> > From: peter reilly [mailto:peter.reilly@corvil.com]
> > Sent: Wednesday, June 04, 2003 6:54 PM
> > To: Ant Users List
> > Subject: Re: append line to a list of file
> >
> >
> > Use Pathconvert:
> >   <filelist dir="." files="build.xml,k.xml" id="filelist"/>
> >   <pathconvert property="converted" pathsep="${line.separator}"
> >                refid="filelist"/>
> >   <echo message="converted is ${line.separator}${converted}"/>
> >
> > Peter
> >
> > On Wednesday 04 June 2003 16:11, Philippe Bonnardel wrote:
> > > Hi all
> > >
> > > I'm guetting an head-ach on this.
> > > I'd like to add new lines to a list of file.
> > > I was thinking about using fileset and echo but how to get the file
> > > one by one in order to echo my carriage returns in each file of the
> > > fileset. Should I use antcall? If so, how?
> > >
> > > Hope somebody was facing a kind of same issue.
> > >
> > > Thanks for any answer
> > >
> > > Regards
> > >
> > > Philippe Bonnardel.
> > > --------------------------------------------------------------------
> > > -
> > > E-Paper Software Engineer
> > > Winsoft S.A. ( <http://www.winsoft.fr/> http://www.winsoft.fr)
> > > <ma...@winsoft.fr> philippe.bonnardel@winsoft.fr
> > > Tel: +33 438 022 231  Fax: +33 438 022 211
> > > --------------------------------------------------------------------
> >
> > ---------------------------------------------------------------------
> > 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
> >
> >
> > ---------------------------------------------------------------------
> > 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
>
>
> ---------------------------------------------------------------------
> 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