subwcrev需要什么?

时间:2011-02-23 16:26:03

标签: svn ant build

我在ant中编写了一个构建脚本。我的项目的源代码在svn。

中版本化

作为我项目的一部分,我必须编写一个java类,其中包含来自subversion的信息。通常,构建脚本工作正常。除了一个之外,将收集所有需要的信息。这是作者提交了最后一次更改的作者姓名。虽然我读过manual,但我仍然想出任何想法。

我的问题是:是否有办法用蚂蚁脚本获取这个细节?

由于

修改

<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 $是变量)

1 个答案:

答案 0 :(得分:3)

忘记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 - &gt; 属性

通过TortoiseSVN执行此操作

现在,当您查看该文件时,字段已更改:

$ 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 = &quot;${svn.entry.commit.author}&quot;"/>
    <echo message="Date = &quot;${svn.entry.commit.date}&quot;"/>
    <echo message="Revision = &quot;${svn.entry(revision)}&quot;"/>
</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 = &quot;${svn.entry.commit.author}&quot;"/>
    <echo message="Date = &quot;${svn.entry.commit.date}&quot;"/>
    <echo message="Revision = &quot;${svn.entry(revision)}&quot;"/>
</project>

希望这是你正在寻找的。

相关问题