我用 ant 写了一个构建脚本。我的项目的源代码在 svn 中进行了版本控制。
作为我项目的一部分,我必须编写一个 java 类,其中包含来自 subversion 的信息。一般来说,构建脚本工作正常。所有需要的信息都将被收集,除了一个。这是提交库中最后一次更改的作者的姓名。虽然我读了manual ,我仍然想出任何想法。
我要问你的问题是:是否存在一种通过 ant 脚本获取此详细信息的方法?
谢谢
编辑:
<target name="version" description="set version number">
<echo message="Setting version information ..." />
<copy file="build/Version.java.template"
tofile="./cq/apps/src/de/anna/util/Version.java" />
<tstamp>
<format property="TODAY_De"
pattern="yyyy/MM/dd HH:mm:ss"
locale="de,De"/>
</tstamp>
<replace file="./cq/apps/src/de/anna/util/Version.java">
<replacefilter token="@APPNAME@" value="${app.name}" />
<replacefilter token="@BUILDVERSION@" value="${build.number}" />
<replacefilter token="@BUILDDATE@" value="${TODAY_De}" />
</replace>
<exec executable="${version.tool}" spawn="false" dir=".">
<arg line=". cq/apps/src/de/anna/Util/Version.java cq/apps/src/de/anna/Util/Version.java" />
</exec>
</target>
我想在文件 Version.java 中添加什么,谁是最后一次提交的作者和更改条目的 ID。 (我认为/认为 $Author$ 和 $Id$ 是变量)
最佳答案
忘掉 SubWCRev,想想 Subversion。这就是您的工作对象。
在 Subversion 中,您需要设置一个名为 svn:keywords
的属性,并将该值设置为您要使用的关键字。这在 Keyword Substitution 中的在线 Subversion 手册中进行了解释。 .
通过使用 svn:keywords
属性,您可以让 Subversion 存储库为您处理变量名称。例如,您有一个名为 information.txt
的文件看起来像这样:
The last person to check in the file is $Author$ and the last version was $Version$.
将该文件检入 Subversion 不会改变 $Author$
或 $Revision$
.
现在,您设置属性 svn:keywords
在 information.txt
上文件:
$ svn propset svn:keywords "Author Date" information.txt
$ svn commit -m"Setting svn:keywords to set the information in information.txt"
您也可以通过 TortoiseSVN 通过上下文菜单 TortoiseSVN-->Properties
现在,当您查看文件时,字段发生了变化:
$ cat information.txt
The last person to check in the file is $Author:David$ and the last version was $Revision:123$.
不是你想要的?您可以做的另一件事是简单地执行 svn info
并以 XML 格式获取所需的属性。然后你可以使用 <xmlProperties>
将它们作为属性读入的任务:
<project>
<property name="target.dir" value="${basedir}/target"/>
<mkdir dir="${target.dir}"/>
<exec executable="svn"
outputProperty="svn.info">
<arg line="info --xml"/>
</exec>
<echo message="${svn.info}"
file="${target.dir}/info.txt"/>
<xmlproperty file="${target.dir}/info.txt"
keeproot="no"
prefix="svn"/>
<echo message="Author = "${svn.entry.commit.author}""/>
<echo message="Date = "${svn.entry.commit.date}""/>
<echo message="Revision = "${svn.entry(revision)}""/>
</project>
我使用 <exec>
获取 Subversion 信息并将其放入属性 ${svn.info}
中的任务.然后我使用 <echo>
任务将其输出到 ${target.dir}/info.txt
文件。之后,我可以通过 <xmlproperty>
读取文件任务并提取以下信息。
从那里,我现在拥有存储在各种属性中的所有 Subversion 修订和存储库信息。
如果您了解资源集合,您实际上可以在不先将文件写入 ${target}/info.txt
的情况下执行此操作
<project>
<exec executable="svn"
outputProperty="svn.info">
<arg line="info --xml"/>
</exec>
<xmlproperty keeproot="no"
prefix="svn">
<propertyresource name="svn.info"/>
</xmlproperty>
<echo message="Author = "${svn.entry.commit.author}""/>
<echo message="Date = "${svn.entry.commit.date}""/>
<echo message="Revision = "${svn.entry(revision)}""/>
</project>
希望这就是您要找的。p>
关于svn - subwcrev 需要什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5093713/