How to replace newline in ant in outputfilterchain?
In my build.xml, I want to do the equivalent of cmd1 | xargs cmd2
(and also store the list of files from cmd1
into the variable ${dependencies}
), where cmd1
gives a newline-separated list of paths. I can't figure out how to do this in Ant.
<project default="main">
<target name="main">
<exec executable="echo"
outputproperty="dependencies">
<arg value="closure/a.js
closure/b.js
closure/c.js"/>
<redirector>
<outputfilterchain>
<replacestring from="${line.separator}" to=" "/>
<!-- None of these do anything either:
<replacestring from="\n" to=" "/>
<replacestring from="
" to=" "/>
<replaceregex pattern="
" replace=" " flags="m"/>
<replaceregex pattern="\n" replace=" " flags="m"/>
<replaceregex pattern="${line.separator}" replace=" " flags="m"/>
-->
</outputfilterchain>
</redirector>
开发者_如何学运维 </exec>
<!-- Later, I need to use each file from ${dependencies} as an argument
to a command. -->
<exec executable="echo">
<!--This should turn into 3 arguments, not 1 with newlines.-->
<arg line="${dependencies}"/>
</exec>
</target>
</project>
This filter might do for the first part - it assumes though that none of your files start with a space character.
<outputfilterchain>
<prefixlines prefix=" " />
<striplinebreaks />
<trim />
</outputfilterchain>
It prefixes each line with a space, then removes the line breaks - giving a single line with all the filenames separated by single spaces, but with one space at the beginning. So the trim
is used to chop that off.
Thanks martin. I also found another solution upon reading the filterchain documentation more carefully.
<outputfilterchain>
<tokenfilter delimoutput=" ">
<!--The following line can be omitted since it is the default.-->
<linetokenizer/>
</tokenfilter>
</outputfilterchain>
精彩评论