构建之后,我需要修改一个HTML文件,指向客户端下载新应用程序.
我搜索一个令牌; 用链接和令牌替换它:
<replace file="index.html" >
<!-- this searches for literal text ${MyTOKEN} -->
<!-- does not "expand" ${MyTOKEN} before searching -->
<replacetoken>${MyTOKEN}</replacetoken>
<replacevalue>"some link" <br> ${MyTOKEN}</replacevalue>
</replace>
Run Code Online (Sandbox Code Playgroud)
此代码不能移动到模板构建脚本中,因为replacetoken和replacevalue标签将文本作为文字 - 它们不在expandproperties我的ANT版本中.
我想使用属性来定义"some link"和MyTOKEN值.
使用属性的解决方法"some link"是filterchain在替换后使用a 并复制文件:
<copy file="index.html" tofile="index2.html" >
<filterchain>
<!-- this converts the ${xxx} properties into their values -->
<expandproperties />
</filterchain>
</copy>
Run Code Online (Sandbox Code Playgroud)
但是这replace已经完成了 - 所以这意味着我仍然需要将MyTOKEN值直接硬编码到构建脚本中.
更新:我应该创建自己replace使用的任务copy,filterreader和filterchain?我真的不太了解这种方法,但看起来就像这样.
更新扩展已接受的答案:我最初使用<replacetoken>&<replacevalue>方法,因为我需要我的值跨越多行.
通过使用token&value,我无法找到一种方法来换行.
放置换行符的解决方案是${line.separator}用作换行符.请参阅有关Echo任务的文档.
另外,这是一个更有用(非主题)ANT属性的页面:内置Ant属性.
使用token和value属性在这里工作.这适用于Ant 1.7.1:
build.properties
token=FOO
tokval=some ${token}
Run Code Online (Sandbox Code Playgroud)
build.xml文件
<project>
<property file="build.properties" />
<target name="repl">
<replace file="test.txt" token="${token}" value="${tokval}" />
</target>
</project>
Run Code Online (Sandbox Code Playgroud)
希望有所帮助.