2011-07-07 31 views
1

を更新するときに、私はこのiniファイルによる蟻ファイル内のデータを更新アリファイルが更新されていると削除コメントiniファイル

#Thu, 07 Jul 2011 06:54:54 -0500 
を次のように先頭にそれがコメントを持っています

私はこのファイルにparse_iniを使ってアクセスしているので、このコメントは欲しくない。私はiniファイル内のコメントを取得することはできませんように。これによりコメントに私は失敗

Comments starting with '#' are deprecated in build.ini on line 1 

を取得するので、どのような方法があります。

ありがとうございました。

EDIT:

<propertyfile file="build.ini"> 
    <entry key="build-number" type="int" operation="+" value="1" /> 
</propertyfile> 

これはあなたがreplaceregexpを使ってコメントを削除する方法に+1

+0

iniファイルに書き込むビルドファイルにターゲットを表示します。 – sudocode

+1

[ApacheのAnt PropertyFileタスクからの日付コメントの削除]の可能な複製(http://stackoverflow.com/questions/3452122/removing-date-comment-from-apaches-ant-propertyfile-task) –

+0

@martin clayton - そうではありません私のiniファイルと同じように私のために働いています – lAH2iV

答えて

3

マーティンのコメントポイントで私のiniファイルのビルド番号を更新します。 (私はあなたに似たようなアイデアを示していましたが、move、filterchain、striplinecommentsを使用していましたが、replaceregexpはもっとコンパクトです)。

私は、iniファイルを編集しているので、そのためには、PropertyFileタスクを使用するのではなく、専用です。仕事をするかもしれない蟻の貢献にIniFileタクがあります。

あなたのファイルは、その中に他の#のコメントがあり、それだけで一番上の行を削除するためreplaceregexpがあなたのために動作しない場合は、この方法を試してください。

<target name="test"> 
    <propertyfile file="test.properties"> 
    <entry key="key" value="value"/> 
    </propertyfile> 
    <move file="test.properties" tofile="test.properties.tmp"> 
    <filterchain> 
     <headfilter lines="-1" skip="1"/> 
    </filterchain> 
    </move> 
    <move file="test.properties.tmp" tofile="test.properties"/> 
</target> 

出力:

$ cat test.properties 
one=1 
# existing comment 

$ ant 
Buildfile: C:\tmp\ant\build.xml 

test: 
[propertyfile] Updating property file: C:\tmp\ant\test.properties 
    [move] Moving 1 file to C:\tmp\ant 
    [move] Moving 1 file to C:\tmp\ant 

BUILD SUCCESSFUL 

Total time: 0 seconds 

$ cat test.properties 
one=1 
# existing comment 

key=value 
+0

これは私がant-contrib jarファイルを追加しなければならないと私はユーザに合併を望んでいません – lAH2iV

+0

あなたのサポートのために皆さんありがとう... :) – lAH2iV

関連する問題