2010-10-31 27 views
5

Trong tệp build.xml của mình, tôi muốn làm tương đương với cmd1 | xargs cmd2 (và cũng lưu trữ danh sách tệp từ cmd1 vào biến ${dependencies}), trong đó cmd1 cung cấp danh sách đường dẫn được phân tách bằng dòng mới. Tôi không thể tìm ra cách để làm điều này trong Ant.Làm thế nào để thay thế dòng mới trong ant trong outputfilterchain?

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

Trả lời

6

Bộ lọc này có thể làm cho phần đầu tiên - giả định rằng không có tệp nào của bạn bắt đầu bằng ký tự khoảng trắng.

<outputfilterchain> 
    <prefixlines prefix=" " /> 
    <striplinebreaks /> 
    <trim /> 
</outputfilterchain> 

Nó đặt trước mỗi dòng với một khoảng trắng cách nhau bằng dấu cách đơn, nhưng với một dấu cách ở đầu. Vì vậy, trim được sử dụng để cắt nó.

2

Cảm ơn martin. Tôi cũng tìm thấy một giải pháp khác khi đọc kỹ số filterchain documentation.

<outputfilterchain> 
    <tokenfilter delimoutput=" "> 
     <!--The following line can be omitted since it is the default.--> 
     <linetokenizer/> 
    </tokenfilter> 
</outputfilterchain> 
Các vấn đề liên quan