Ant命令比较字符串
Ant command to compare string
我是 Ant 的新手,你能帮我解决以下问题吗?
我正在尝试比较文件中的字符串并附加新字符串并保留现有字符串。假设我的输入是
项目=vinoth, raghu, ram
我有一个名为 ram.properties 的文件。文件如下所示
这是理解 Ant 概念的文件
项目=Vinoth,raghu
通过比较输入和文件,项目值只缺少 ram。
我需要在 file.I 的项目值中追加 ram 可以编写一个如下所示的简单循环来查找,但我如何追加这些值。
非常感谢您的帮助。
谢谢
这是一个使用资源的 ant 快速尝试,你需要 ant >= 1.9.3 用于 if/unless feature :
<project
xmlns:if="ant:if"
xmlns:unless="ant:unless"
>
<!-- Propertyfile containing the property to be compared against -->
<property file="ram.properties"/>
<!-- create macrodef for reuse -->
<macrodef name="stringcompare">
<attribute name="property"/>
<attribute name="string"/>
<attribute name="update"/>
<sequential>
<resources id="property">
<tokens>
<stringtokenizer delims=", "/>
<string value="${@{property}}"/>
</tokens>
</resources>
<resources id="string">
<tokens>
<stringtokenizer delims=", "/>
<string value="@{string}"/>
</tokens>
</resources>
<difference id="diff">
<resources refid="property"/>
<resources refid="string"/>
</difference>
<echo> Diff ? => ${toString:diff}</echo>
<replace file="@{update}" token="${@{property}}" value="${@{property}} ,${toString:diff}" unless:blank="${toString:diff}"/>
</sequential>
</macrodef>
<stringcompare property="Project" string="vinoth, raghu, ram" update="ram.properties"/>
</project>
注意:macrodef 属性 属性 使用 属性 名称(property="Project"),
而内部逻辑使用 属性 值 ${@{property}}
!
编辑 评论后
Required attribute property not set
表示您调用了没有属性 属性、f.e 的宏定义。 :
<stringcompare string="vinoth, raghu, ram" update="ram.properties"/>
我试过像这样的 ram.properties 片段:
Project=vinoth, raghu
输出:
[echo] Diff ? => ram
ram.properties 之后:
Project=vinoth, raghu ,ram
我是 Ant 的新手,你能帮我解决以下问题吗?
我正在尝试比较文件中的字符串并附加新字符串并保留现有字符串。假设我的输入是
项目=vinoth, raghu, ram
我有一个名为 ram.properties 的文件。文件如下所示
这是理解 Ant 概念的文件 项目=Vinoth,raghu
通过比较输入和文件,项目值只缺少 ram。 我需要在 file.I 的项目值中追加 ram 可以编写一个如下所示的简单循环来查找,但我如何追加这些值。 非常感谢您的帮助。
谢谢
这是一个使用资源的 ant 快速尝试,你需要 ant >= 1.9.3 用于 if/unless feature :
<project
xmlns:if="ant:if"
xmlns:unless="ant:unless"
>
<!-- Propertyfile containing the property to be compared against -->
<property file="ram.properties"/>
<!-- create macrodef for reuse -->
<macrodef name="stringcompare">
<attribute name="property"/>
<attribute name="string"/>
<attribute name="update"/>
<sequential>
<resources id="property">
<tokens>
<stringtokenizer delims=", "/>
<string value="${@{property}}"/>
</tokens>
</resources>
<resources id="string">
<tokens>
<stringtokenizer delims=", "/>
<string value="@{string}"/>
</tokens>
</resources>
<difference id="diff">
<resources refid="property"/>
<resources refid="string"/>
</difference>
<echo> Diff ? => ${toString:diff}</echo>
<replace file="@{update}" token="${@{property}}" value="${@{property}} ,${toString:diff}" unless:blank="${toString:diff}"/>
</sequential>
</macrodef>
<stringcompare property="Project" string="vinoth, raghu, ram" update="ram.properties"/>
</project>
注意:macrodef 属性 属性 使用 属性 名称(property="Project"),
而内部逻辑使用 属性 值 ${@{property}}
!
编辑 评论后
Required attribute property not set
表示您调用了没有属性 属性、f.e 的宏定义。 :
<stringcompare string="vinoth, raghu, ram" update="ram.properties"/>
我试过像这样的 ram.properties 片段:
Project=vinoth, raghu
输出:
[echo] Diff ? => ram
ram.properties 之后:
Project=vinoth, raghu ,ram