开发者

How to replace newline in ant in outputfilterchain?

开发者 https://www.devze.com 2023-01-22 13:21 出处:网络
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

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>


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

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号