You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@ant.apache.org by North Alex <Al...@tapiola.fi> on 2003/04/02 12:02:14 UTC

RE: [A solution] Inserting text at start of file

>From: Stefan Bodewig [mailto:bodewig@apache.org] 

>> I have come up with a complicated-well-over-the-top way of copying 
>> files and using the concat task.
>
>Why copy?

Because I have an existing file.

This is what I came up with:

    <!-- pre-pend text to a file -->
    <!-- prerequisites: text.to.prepend, file.to.prepend -->
    <target name="prepend.text.to.file">
        <dirname property="prepend.dir" file="${file.to.prepend}"/>
        <copy file="${file.to.prepend}"
tofile="${prepend.dir}/temp.txt"/>
        <concat
destfile="${file.to.prepend}">${text.to.prepend}${line.separator}</conca
t>
        <concat destfile="${file.to.prepend}"
append="true">${line.separator}</concat>
        <concat destfile="${file.to.prepend}" append="true">
            <fileset file="${prepend.dir}/temp.txt"/>
        </concat>
        <delete>
            <fileset dir="${prepend.dir}" includes="temp.txt"/>
        </delete>
    </target>

This solution is simpler than the one I had before and is usable from
all of our projects now (as it is in a common script).  It still seems
incredibly painful for something that should maybe be part of the concat
task or maybe even a sister task.

Thanks Jan, Peter, and Stefan very much for your input! :)

<= Alex =>

Re: [A solution] Inserting text at start of file

Posted by Stefan Bodewig <bo...@apache.org>.
On Wed, 2 Apr 2003, North Alex <Al...@tapiola.fi> wrote:

> It still seems incredibly painful for something that should maybe be
> part of the concat task or maybe even a sister task.

Reread my answer, especially the part on the new <header> nested
element in Ant 1.6 ;-)

Stefan