2010-08-10 81 views
8

我用我的構建腳本如下所示的propertyfile任務:從Apache的螞蟻PropertyFile刪除日期評論任務

<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變量不發生變化,導致了沒有必要提交到版本控制由以下的diff只:

--- 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文件?我在propertyfile嵌套的entry元素中考慮了一個刪除操作,但是需要一個鍵值。

回答

5

這不是一個很好的解決方案,但如何一起刪除評論呢?

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

優秀的解決方法! – javacavaj 2010-08-13 18:19:50

+1

通過省略byline =「true」保留其他評論 – Tarnschaf 2012-06-21 08:03:07

+0

這是真的。好點子。 – JasonMArcher 2012-06-25 21:03:52

0

嘗試:<propertyfile file="..." comment="">

編輯:可能不會工作:(它看起來像哪個罪魁禍首居然是Properties.store(OutputStream, String)

接下來,註釋行總是 寫,由一個ASCII# 字符,當前日期和時間 (好像由當前時間的日期的toString方法 生成)和由 Writer生成的 行分隔符

+0

嗯。我查看了源代碼,似乎沒有辦法解決這個問題。 LayoutPreservingProperties類(默認使用)和Properties類(當useJDKProperties設置爲true時使用)都在它們的存儲方法中有這個。 – javacavaj 2010-08-11 17:25:26

1

如果你需要把一個單一的財產在一個文件中只是使用echo:

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