如何在outputfilterchain中替换ant中的换行符?

yon*_*ran 5 ant

在我的build.xml中,我想做相当于cmd1 | xargs cmd2(并且还将文件列表存储cmd1到变量中${dependencies}),其中cmd1给出了换行符分隔的路径列表.我无法弄清楚如何在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>
Run Code Online (Sandbox Code Playgroud)

mar*_*ton 6

此过滤器可能适用于第一部分 - 它假设您的所有文件都不以空格字符开头.

<outputfilterchain>
    <prefixlines prefix=" " />
    <striplinebreaks />
    <trim />
</outputfilterchain>
Run Code Online (Sandbox Code Playgroud)

它为每一行添加一个空格前缀,然后删除换行符 - 给出一行,所有文件名由单个空格分隔,但在开头有一个空格.所以trim用来切断它.