将值从 Ant 属性 文件中的 属性 复制到另一个 属性
Copy the value from a property in an Ant propertyfile to another property
我需要将 属性 文件中一个 属性 的值复制到第二个 属性 中,并将其添加到 属性 文件中。
例如,如果我有一个 属性 文件 Test.properties 包含
2018=jan;feb;mar
2019=jan;feb;mar
2020=jan;feb;mar
********************************
name=john,math,sudha
我的输入 属性 是“2020”,输出是“2021”,在 运行 Ant Test.properties 之后应该包含
2018=jan;feb;mar
2019=jan;feb;mar
2020=jan;feb;mar
2021=jan;feb;mar
********************************
name=john,math,sudha
不改变顺序我怎么能这样做?
您或许可以使用基于以下内容的内容:
思路是读取属性文件,然后用两个<propertyset>
instances with the <echoproperties>
task更新文件。
<property name="prop.file" value="Test.properties" />
<property name="input" value="2020" />
<property name="output" value="2021" />
<property name="pf" value="prefix" />
<property name="input.prop" value="${pf}.${input}" />
<loadproperties srcfile="${prop.file}" prefix="${pf}" />
<echoproperties destfile="${prop.file}">
<propertyset>
<propertyref prefix="${pf}" />
<mapper type="glob" from="${pf}.*" to="*" />
</propertyset>
<propertyset>
<propertyref name="${input.prop}" />
<mapper type="glob" from="${input.prop}*" to="${output}*" />
</propertyset>
</echoproperties>
其中的代码比您预期的要多:“前缀”用于确保从文件加载的属性不会与 Ant 构建文件中的任何属性发生冲突,因为属性是不可变的。
propertysets
在 echoproperties
任务中的顺序很重要,尤其是当您正在更新的文件中已经有 属性“2021”的值时。如果属性出现在两个集合中,则最后 属性 集合中的值“获胜”并回显到输出文件。
<property name="prop.file" value="test.properties" />
<property name="input" value="2020" />
<property name="output" value="2021" />
<replaceregexp file="${prop.file}"
match="${input}(=)(.*)"
replace="${input}=${line.separator}${output}="
flags="gi"
byline="true" />
我需要将 属性 文件中一个 属性 的值复制到第二个 属性 中,并将其添加到 属性 文件中。
例如,如果我有一个 属性 文件 Test.properties 包含
2018=jan;feb;mar
2019=jan;feb;mar
2020=jan;feb;mar
********************************
name=john,math,sudha
我的输入 属性 是“2020”,输出是“2021”,在 运行 Ant Test.properties 之后应该包含
2018=jan;feb;mar
2019=jan;feb;mar
2020=jan;feb;mar
2021=jan;feb;mar
********************************
name=john,math,sudha
不改变顺序我怎么能这样做?
您或许可以使用基于以下内容的内容:
思路是读取属性文件,然后用两个<propertyset>
instances with the <echoproperties>
task更新文件。
<property name="prop.file" value="Test.properties" />
<property name="input" value="2020" />
<property name="output" value="2021" />
<property name="pf" value="prefix" />
<property name="input.prop" value="${pf}.${input}" />
<loadproperties srcfile="${prop.file}" prefix="${pf}" />
<echoproperties destfile="${prop.file}">
<propertyset>
<propertyref prefix="${pf}" />
<mapper type="glob" from="${pf}.*" to="*" />
</propertyset>
<propertyset>
<propertyref name="${input.prop}" />
<mapper type="glob" from="${input.prop}*" to="${output}*" />
</propertyset>
</echoproperties>
其中的代码比您预期的要多:“前缀”用于确保从文件加载的属性不会与 Ant 构建文件中的任何属性发生冲突,因为属性是不可变的。
propertysets
在 echoproperties
任务中的顺序很重要,尤其是当您正在更新的文件中已经有 属性“2021”的值时。如果属性出现在两个集合中,则最后 属性 集合中的值“获胜”并回显到输出文件。
<property name="prop.file" value="test.properties" />
<property name="input" value="2020" />
<property name="output" value="2021" />
<replaceregexp file="${prop.file}"
match="${input}(=)(.*)"
replace="${input}=${line.separator}${output}="
flags="gi"
byline="true" />