Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to replace newline in ant in outputfilterchain?

Tags:

ant

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&#xa;closure/b.js&#xa;closure/c.js"/>
            <redirector>
                <outputfilterchain>
                    <replacestring from="${line.separator}" to=" "/>
                    <!-- None of these do anything either:
                    <replacestring from="\n" to=" "/>
                    <replacestring from="&#xa;" to=" "/>
                    <replaceregex pattern="&#xa;" 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>
like image 530
yonran Avatar asked Oct 31 '10 06:10

yonran


2 Answers

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.

like image 120
martin clayton Avatar answered Nov 04 '22 20:11

martin clayton


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>
like image 31
yonran Avatar answered Nov 04 '22 21:11

yonran