【问题标题】:Phing alternative for fixlastline from ant来自 ant 的 fixlastline 的 Phing 替代品
【发布时间】:2019-04-21 07:07:30
【问题描述】:

我正在将 build.xml 文件从 Ant 重写为 Phing,一切正常,但有一个例外。 我需要在每个附加文件的末尾添加新行,但我找不到 fixlastline="true" 的任何替代品。

在 Ant 中是

 <concat destfile="${libraryFilePrefix}.js" fixlastline="yes">
     <!-- many filesets -->
 </concat>

在 Phing 中是这样的

 <append destfile="${libraryFilePrefix}.js">
     <!-- many filesets -->
 </append>

有没有类似fixlastline 的属性,或者我需要找到另一种方法来实现这一点?

【问题讨论】:

    标签: ant phing


    【解决方案1】:

    我相信,其中一种方法(可能也是唯一一种方法)是在每个文件集上应用 replaceregexp 过滤器。您只需要在开始时应用 filterchain,它就会为每个 fileset 完成这项工作,如下所示:

    <append destfile="${libraryFilePrefix}.js">
        <filterchain>
            <replaceregexp>
                <regexp pattern="([^\n])$" replace="$1${line.separator}" ignoreCase="true"/>
            </replaceregexp>
        </filterchain>
    
        <!-- many filesets -->
    </append>
    

    【讨论】:

      【解决方案2】:

      从 Phing 3.x 开始,AppendTask 知道 fixlastline 属性。您提供的 Ant 脚本现在按预期工作

          <project name="concat-supports-fixlastline" default="concat-fixed-lastline" basedir=".">
              <target name="concat-fixed-lastline">            
                  <concat destfile="${libraryFilePrefix}.js" fixlastline="yes">
                      <!-- many filesets -->
                  </concat>
              </target>
          </project>
      

      【讨论】:

        猜你喜欢
        • 2014-12-12
        • 2023-02-02
        • 2018-03-07
        • 2011-01-11
        • 1970-01-01
        • 2018-06-29
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多