Alessandro S.
Alessandro S.

Reputation: 1043

Reading SVN (Subclipse) rev number from java code

I'd like to be able to read the current svn revision number (I'm using Subclipse) from my Java Code to output it with the rest of the things I need in my regression tests written using JUnit 4.

I googled a lot without any luck (some info pointing to javahl.jar, but I wasn't able to figure out anything useful for my case), I also tried to figure out by myself but no luck again.

Environment:

If possible I'd like to avoid to read .snv files directly and reach a "clean" solution because I have to leave this code to other people.

Thanks in advance, Alessandro

Upvotes: 4

Views: 3119

Answers (3)

Alessandro S.
Alessandro S.

Reputation: 1043

I figured out that the questions seems still open even if I solved the problem, I post here the code for clarity even if it was already inserted into a commet:

import org.tigris.subversion.javahl.*;
[...]

SVNClient svnClient = new SVNClient();
@SuppressWarnings("deprecation")
Status [] status = svnClient.status("absolutepathOfTheProject", true, false, true);

for(Status stat : status)
revNumber = (revNumber < stat.getRevisionNumber()) ? stat.getRevisionNumber() : revNumber;

Please note that this stub uses some deprecated methods, it is of course possible to replace them with other methods, but this is to be intended as a guideline for solving the original problem.

Upvotes: 0

Alistair A. Israel
Alistair A. Israel

Reputation: 6567

I would look into SVNKit, particularly the SVNWCClient#doInfo() method.

Upvotes: 1

corsair
corsair

Reputation: 668

There is a library "svnkit" - svnkit.com

On wikipage there are many examples and one of them is "For getting info on Working Copy items"

http://wiki.svnkit.com/Managing_A_Working_Copy

Also example how to use it you can find in source code of project http://code.google.com/p/svntask/

Upvotes: 2

Related Questions