开发者

What does subwcrev need?

I wrote a build script in ant. The source code of my project is versioned in svn.

As a part of my project I had to write a java class, that contains information from subversion. In general, the build script works fine. All needed information will be gathered, except one. This is the name of the author who commited the last change in the reporsitory. Though I read the manual, I still come up with any ideas.

My question to you is: does exist a way to get also this detail with an ant script?

Thanks

EDIT:

<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 toke开发者_JS百科n="@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>

What I want to add in file Version.java, who is the author of last commit and the id of the change entry. (I think/thought $Author$ and $Id$ were the variables)


Forget about SubWCRev and think about Subversion. That's what your working with.

In Subversion, you need to set a property called svn:keywords, and set that value to the keywords you want to use. This is explained in the on line Subversion manual in Keyword Substitution.

By using the svn:keywords property, you have the Subversion repository handle the variable names for you. For example, you have a file called information.txt that looks like this:

The last person to check in the file is $Author$ and the last version was $Version$.

Checking that file into Subversion doesn't change $Author$ or $Revision$.

Now, you set the property svn:keywords on the information.txt file:

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

You can do this through TortoiseSVN too via the Context Menu TortoiseSVN-->Properties

Now, when you look at the file, the fields changed:

$ cat information.txt
The last person to check in the file is $Author:David$ and the last version was $Revision:123$.

Not what you want? Another thing you can do is simply execute svn info and get the properties you want in XML format. Then you can use the <xmlProperties> task to read them in as properties:

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

I use the <exec> task to grab the Subversion information and put it in the property ${svn.info}. I then use the <echo> task to output it to the ${target.dir}/info.txt file. After that, I can read the file via the <xmlproperty> task and pull out the information below.

From there, I now have all the Subversion revision and repository information stored in various properties.

If you know resource collections, you can actually do this without first writing the file to ${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>

Hope this is what you're looking for.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜