Retrieving svn repository's UUID programmatically?

Hi folks, newbie question: how do I retrieve the UUID of a Subversion repository via the IDEA vcs api?

As background info, I'm working on a plugin that retrieves info from the various source control systems IDEA supports out of the box and svn is one of the first ones we're tackling.  I tried searching Google and the existing posts but either my search-fu is weak or no one has run into this yet.  Surely there must be some way to query info about the originating source control point for a given project (e.g. svn url/uuid)?

For reference (using a fairly bare svn checkout left over from another test):

me@host:~/svntest$ svn info
Path: .
Working Copy Root Path: /home/me/svntest
URL: file:///home/svnroot/repos/test
Relative URL: ^/
Repository Root: file:///home/svnroot/repos/test
Repository UUID: 392e206a-bc5b-4abd-8aa7-c0909348d0a2  <--- this is the bit I'd like to get at via API
Revision: 1
Node Kind: directory
Schedule: normal
Last Changed Author: me
Last Changed Rev: 1
Last Changed Date: 2015-02-10 17:10:38 -0600 (Tue, 10 Feb 2015)

This is using IDEA 14.1; presently on an x86-64 linux machine if it matters.

Thanks in advance!

Comment actions Permalink

Just in case anyone else stumbles on this, here's what I finally worked out to get this.  I never did find an elegant way to get at it purely using IDEA's api (suggestions welcome!).

String scmRepoUUID;
try {
    SVNURL svnURL = SVNURL.parseURIEncoded(scmRepoURL);
    SVNClientManager cm = SVNClientManager.newInstance();
    SVNWCClient workingCopyClient = cm.getWCClient();
    SVNInfo svnInfo = workingCopyClient.doInfo(svnURL, SVNRevision.UNDEFINED, SVNRevision.HEAD);
    scmRepoUUID = svnInfo.getRepositoryUUID();
} catch (SVNException svne) {
    log.severe("SVN error: " + svne.getMessage());

This does assume you've imported svnkit into your project; scmRepoURL is easy enough to get via pure IDEA api calls albeit a bit hackishly (fileRevision is a VcsFileRevision object):

String scmRepoURL;
String fullPath = fileRevision.getChangedRepositoryPath().toPresentableString(); // this gives the full path down to the file, so:
(fullPath.endsWith(scmPath) && fullPath.indexOf(scmPath) > 0) {
    scmRepoURL = fullPath.substring(0, fullPath.indexOf(scmPath) - 1); // -1 to trim off trailing "/"

(various minor guard logic omitted for clarity)

Comment actions Permalink

UUID is not available through common IDEA vcs-api, but you could also get it through SvnVcs instance (if you add dependency to svn4idea plugin) using SvnVcs.getInfo() and then Info.getRepositoryUUID() methods. This way you could also get repository uuid with svn command line client (if IDEA is configured correspondingly) and not just wigh SVNKit library.


Please sign in to leave a comment.