【问题标题】:What is the correct way to use linecontainsregexp in Ant build?在 Ant 构建中使用 linecontainsregexp 的正确方法是什么?
【发布时间】:2023-03-12 15:35:01
【问题描述】:

我添加了

<linecontainsregexp negate="true">
                 <regexp pattern="src=&quot;http://*"/>
            </linecontainsregexp>

&lt;replaceregexp&gt; 任务中,我收到错误消息 replaceregexp doesn't support the nested "linecontainsregexp" element.

【问题讨论】:

    标签: java ant build build-process build-automation


    【解决方案1】:

    &lt;linecontainsregexp&gt; 仅在 &lt;filterchain&gt; 内部有效。反过来,任务&lt;replaceregexp&gt; 不支持&lt;filterchain&gt;s。仅由任务支持

    &lt;replaceregexp&gt; 通常在复制文件后应用。 &lt;filterchain&gt;s 被应用同时复制被执行。

    基本上,您有两种选择:

    1. 使用更复杂的正则表达式修改您的 &lt;replaceregexp&gt; 任务,该表达式只匹配您想要的,可能会求助于环视。
    2. &lt;filterchain&gt; 添加到您用于从源管理系统复制这些文件的&lt;copy&gt;&lt;move&gt; 任务中。根据需要包括过滤器&lt;tokenfilter&gt;,很可能有一个孩子&lt;filetokenizer/&gt;,以及孩子&lt;containsregex&gt;&lt;replaceregex&gt;。这要灵活得多。有几十个过滤器和标记器可供选择。

    【讨论】:

    • 使用replaceregexp,我试图将一个参数附加到我的jsps中的所有脚本标签。但我只需要对内部脚本执行此操作。即,如果 src 引用像 &lt;script type="text/javascript" src="http://ajax.googleapis.com"&gt; 这样的外部脚本,则不需要该操作。我认为可以通过添加&lt;linecontainsregexp negate="true"&gt; 并添加正则表达式以将 src 与“http://....”匹配来完成,所以 rt 无法完成?
    • @user1266172 相应地更改了我的答案。如果您提供更多内部和外部脚本的案例(或区分正则表达式)以及替换,如果您愿意,我可以提供更多帮助。
    • 谢谢@Mario Rossi。我选择了第一个选项,改变了常规的 epression 以满足我的需要。
    • @user1266172 很高兴听到这个消息:-)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-02-20
    • 1970-01-01
    • 2015-05-05
    • 2019-04-02
    • 2014-02-03
    相关资源
    最近更新 更多