ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "North Alex" <Alex.No...@tapiola.fi>
Subject RE: [A solution] Inserting text at start of file
Date Wed, 02 Apr 2003 10:02:14 GMT

>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 =>

Mime
View raw message