命名根据不同文件的内容在Apache Ant的文件 [英] Naming a file in Apache Ant based on contents of different file
本文介绍了命名根据不同文件的内容在Apache Ant的文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有foo.js,这导致foo.min.js Ant构建过程。
I've got foo.js, and an ant build process that results in foo.min.js.
foo.js有一个头注释,包括:
foo.js has a header comment that includes:
* $Id: foo.js 12345 2011-10-04 14:35:23Z itoltz $
在哪里12345是当致力于SVN文件的修订工作。
Where 12345 is the revision of the file when committed to SVN.
我要复制到foo.min.js foo.min.12345.js
I'd like to copy foo.min.js to foo.min.12345.js
推荐答案
您可以使用的loadFile和正则表达式提取修订版本号的属性。然后,你可以使用属性复制的文件。
You can extract the revision number into a property using loadfile and regex. Then you can copy the file using the property.
<project default="rename">
<target name="rename" depends="get-rev">
<copy file="foo.min.js" toFile="foo.min.${revision.number}.js"/>
</target>
<target name="get-rev">
<loadfile srcFile="foo.js" property="revision.number">
<filterchain>
<linecontainsregexp>
<regexp pattern="\* \$Id: foo.js"/>
</linecontainsregexp>
<tokenfilter>
<replaceregex pattern="\* \$Id: foo.js (\d+).*" replace="\1"/>
</tokenfilter>
<striplinebreaks/>
</filterchain>
</loadfile>
<echo message="revision.number: ${revision.number}"/>
</target>
</project>
输出:
$ ls
build.xml foo.js foo.min.js
$
$ ant
Buildfile: C:\tmp\build.xml
get-rev:
[echo] revision.number: 12345
rename:
[copy] Copying 1 file to C:\tmp
BUILD SUCCESSFUL
Total time: 0 seconds
$
$ ls
build.xml foo.js foo.min.12345.js foo.min.js
这篇关于命名根据不同文件的内容在Apache Ant的文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文