【问题标题】:Removing Date Comment from Apache's Ant PropertyFile Task从 Apache 的 Ant PropertyFile 任务中删除日期注释
【发布时间】:2011-03-27 23:57:10
【问题描述】:

我正在构建脚本中使用下面显示的属性文件任务:

<target name="build-brand" depends="-init" description="Adds version information to branding files.">
    <propertyfile file="${basedir}/branding/core/core.jar/org/netbeans/core/startup/Bundle.properties">
        <entry key="currentVersion" value="${app.windowtitle} ${app.version}" />
    </propertyfile>
</target>

任务按预期工作,除了每次构建项目时,Bundle.properties 文件的日期注释行都会更新为当前时间戳。即使 app.version 变量没有更改并导致对仅包含以下差异的版本控制的不必要提交也会发生这种情况:

--- Base (BASE)
+++ Locally Modified (Based On LOCAL)
@@ -1,4 +1,4 @@
-#Thu, 22 Jul 2010 15:05:24 -0400
+#Tue, 10 Aug 2010 13:38:27 -0400

如何防止在 .properties 文件中添加或删除此日期注释?我考虑过属性文件嵌套条目元素中的删除操作,但需要一个键值。

【问题讨论】:

    标签: java ant


    【解决方案1】:

    这不是一个很好的解决方案,但是一起删除评论怎么样?

    <target name="build-brand" depends="-init" description="Adds version information to branding files.">
        <propertyfile file="${basedir}/branding/core/core.jar/org/netbeans/core/startup/Bundle.properties">
            <entry key="currentVersion" value="${app.windowtitle} ${app.version}" />
        </propertyfile>
        <replaceregexp file="${basedir}/branding/core/core.jar/org/netbeans/core/startup/Bundle.properties" match="^#.*\n" replace=""/>
    </target>
    

    【讨论】:

    • 通过省略 byline="true" 保留其他 cmets
    • JasonMArcher:replaceregexp 仍然留下一个空行。你能告诉我如何在不留空行的情况下删除该行吗?
    • @Anand 我编辑了replaceregexp 行以完全删除日期行。通过此更改,如果您的属性文件已包含新条目,则除了更改时间戳外,不会对其进行任何更改。所有其他 cmets(包括文件开头的 cmets)都将被保留。
    【解决方案2】:

    如果您需要将单个属性放入文件中,只需使用 echo:

    <echo output="somefiles.properties">lastmodified=${lastmodified}</echo>
    

    【讨论】:

      【解决方案3】:

      试试:&lt;propertyfile file="..." comment=""&gt;

      编辑:这可能行不通:(。看起来罪魁祸首实际上是Properties.store(OutputStream, String):

      接下来,注释行总是 书面,由 ASCII # 组成 字符,当前日期和时间 (好像是由 toString 方法产生的 当前时间的日期),以及 由生成的行分隔符 作家。

      【讨论】:

      • 嗯。我检查了来源,似乎没有办法解决这个问题。 LayoutPreservingProperties 类(默认使用)和 Properties 类(useJDKProperties 设置为 true 时使用)在它们的 store 方法中都有这个。
      猜你喜欢
      • 2013-10-06
      • 2011-07-02
      • 2013-08-22
      • 1970-01-01
      • 2011-02-01
      • 1970-01-01
      • 2019-05-15
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多