【问题标题】:What does subwcrev need?subwcrev 需要什么?
【发布时间】:2011-07-02 21:32:24
【问题描述】:

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

作为我项目的一部分,我必须编写一个 java 类,其中包含来自颠覆的信息。一般来说,构建脚本工作正常。将收集所有需要的信息,除了一个。这是在存储库中提交最后一次更改的作者的姓名。尽管我阅读了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$ 是变量)

【问题讨论】:

  • 您是从 ANT 调用 SubWCRev 命令行程序吗?一种方法是根据您在 ANT 中收集的信息编写一个属性文件,并使用一个 Java 类来读取该属性文件。但是,我不清楚您需要什么帮助,或者这是否是您打算做的……您能发布一些您的 ANT 脚本吗?
  • 你好,我没想到这么长时间后会有反应:-)。但是我更新了我的初始帖子。希望它会有所帮助。

标签: svn ant build


【解决方案1】:

忘记 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$

现在,您在information.txt 文件上设置属性svn:keywords

$ svn propset svn:keywords "Author Date" information.txt
$ svn commit -m"Setting svn:keywords to set the information in information.txt"

您也可以通过 TortoiseSVN 通过上下文菜单执行此操作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 格式获取您想要的属性。然后您可以使用&lt;xmlProperties&gt; 任务将它们作为属性读入:

<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>

我使用&lt;exec&gt; 任务来获取Subversion 信息并将其放在属性${svn.info} 中。然后我使用&lt;echo&gt; 任务将其输出到${target.dir}/info.txt 文件。之后,我可以通过&lt;xmlproperty&gt;任务读取文件,并拉出下面的信息。

从那里,我现在将所有 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>

希望这就是你要找的。​​p>

【讨论】:

  • 感谢您的回答。我会尝试一下,但我需要更多时间(目前我正在做一个项目)。 PS:我忘了说的是,我需要这些信息才能在网页中显示,这就是我想使用java类的原因。
  • 我认为这个概念仍然适用...使用关键字扩展来获取版本,将其写入 Java 程序可以轻松读取的文件——如 XML 或属性文件。
猜你喜欢
  • 2019-06-09
  • 1970-01-01
  • 2015-01-26
  • 2020-12-14
  • 2012-03-11
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-09-16
相关资源
最近更新 更多