开发者

Reading SVN (Subclipse) rev number from java code

开发者 https://www.devze.com 2023-03-28 10:25 出处:网络
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开发者_如

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开发者_如何学Go 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:

  • Eclipse Version: 3.6.2, Build id: M20110210-1200
  • Windows 7 32-bit
  • Subclipse 1.6.18 (JavaHL 1.6.17)

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


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/


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


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.

0

精彩评论

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

关注公众号