2011-02-23 101 views
1

我在ant中编写了一个构建脚本。我的项目源代码版本为svn。subwcrev需要什么?

由于我的项目的一部分,我不得不写一个Java类,包含从颠覆信息。一般来说,构建脚本工作正常。所有需要的信息将被收集,除了一个。这是作者谁承诺在reporitory最后的变化的名称。虽然我读了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="@[email protected]" value="${app.name}" /> 
     <replacefilter token="@[email protected]" value="${build.number}" /> 
     <replacefilter token="@[email protected]" 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添加什么。 (我觉得/思想$ $作者和$编号$是变量)

+0

你是否从ANT调用SubWCRev命令行程序?一种方法是从您在ANT中收集的信息中编写一个属性文件,并拥有一个读取属性文件的Java类。然而,我不清楚你需要什么帮助,或者这是你打算做的事情......你能发布一些你的ANT脚本吗? – mwolfetech 2011-08-26 13:04:21

+0

你好,在这么长时间之后我还没有预料到会有什么反应:-)。但我更新了我的初始帖子。希望这会有所帮助。 – reporter 2011-08-26 13:40:00

回答

2

忘掉SubWCRev和思考颠覆。这就是你的工作。

在Subversion,您需要设置一个叫做svn:keywords属性,该值设置为你想要使用的关键字。这在Subversion的在线手册Keyword Substitution中有解释。

通过使用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:keywordsinformation.txt文件:

$ 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格式获得你想要的属性。然后你可以使用<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>任务抢颠覆信息,并把它的物业${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> 

希望这是你在找什么。

+0

感谢您的回答。我会尝试一下,但我需要更多时间(目前我正在一个项目中工作)。 PS:我忘了提及的是,我需要这些信息在网页上显示,这就是为什么我想使用Java类。 – reporter 2011-08-29 07:25:42

+0

我认为这个概念仍然适用...使用关键字扩展将版本,作者获取到Java程序可以轻松读取的文件中 - 如XML或属性文件。 – mwolfetech 2011-09-01 11:01:23