phing
phing copied to clipboard
Cannot add line to file
I'm trying to add a final new line at the end of a file. I tried to do so with AppendTask.
<append destFile="my-file.txt" text="${line.separator}"/>
The problem is this doesn't work because text
is "sanitized" after:
https://github.com/phingofficial/phing/blob/0824c1412420df3dd1101effc50886718bd43d78/src/Phing/Task/System/AppendTask.php#L350-L355
I don't understand the rationale behind sanitizeText
. But IMHO this method can be deleted, or maybe there's another way to simply append a new line ?
Thanks
Hi @jawira did you try with fixLastLine Attribute set to true?
Hi @siad007 ! Thanks for replying :) I just tried to use fixLastLine
but my build keeps failing:
BUILD FAILED
/home/jawira/PhpstormProjects/xxxxxx/build.xml:236:59 You must specify a file, use a filelist/fileset, or specify a text value.
Total time: 0.0444 seconds
I'm more curious about why sanitizeText
is required? what if I just want to append white spaces?
I can make a PR if required. Since this is not very important, you can also close this issue if you want :)
Hi @jawira - sry for that long delay.
Looking here a little bit closer, we have a bug here.
I'm more curious about why sanitizeText is required?
AFAIK This is needed against empty text arguments like <append destFile="my-file.txt" text=""/>
(related also to xml parsing)
Things that should work are at least:
<?xml version="1.0" encoding="UTF-8" ?>
<project name="test" default="one">
<target name="one">
<append destFile="my-file.txt" text="${line.separator}"/>
</target>
<target name="two">
<append destFile="my-file.txt" text="
"/>
</target>
<target name="three">
<append destFile="my-file.txt" text=" "/>
</target>
</project>
Actually, this is by design and matches the way the Concat task works in Ant. This is because adding a nested text
element may introduce additional (ignorable) whitespace. Hence the sanitizeText
call at the start of validate
. This is not well documented, and maybe we need to introduce a switch that can disable that behavior.
https://github.com/phingofficial/guide/commit/bad73583c55d5292cb8d926c2f2640240eede3a2
@mrook thanks