Hello,
sorry for the outdated documentation we have. Since version 1.7 SVNKit now has a newer API based on SvnOperationFactory class and it should be preferred over older SVNClientManager-based API.
For programmatic “svn info” you can write:
final SvnOperationFactory svnOperationFactory = new SvnOperationFactory();
try {
final SvnGetInfo getInfo = svnOperationFactory.createGetInfo();
getInfo.setSingleTarget(SvnTarget.fromFile(workingCopyDirectory));
final SvnInfo info = getInfo.run();
if (info != null) {
System.out.println("revision = " + info.getRevision());
}
} finally {
svnOperationFactory.dispose();
}
If you want to run “svn info” on the URL, you can use SvnTarget.fromURL(…). If you want to run single “svn info” on several targets, you can use getInfo.addTarget(...);
instead of getInfo.setSingleTarget(...)
, this is rarely needed, though. Finally, you can use getInfo.setReceiver(...);
to set a handler that would react on each object returned. This is rarely needed for “svn info” command but could be useful for some other commands like
final SvnList list = svnOperationFactory.createList();
...
list.setReceiver(...);
list.run();
I hope, this API is more intuitive to use.
If you want to use credentials from ~/.subversion
directory, you can configure svnOperationFactory
:
svnOperationFactory.setAuthenticationManager(SVNWCUtil.createDefaultAuthenticationManager());
There’re also variations for read-only access to ~/.subversion
or for using an alternative directory as credentials storage. Alternatively, you can use any other ISVNAuthenticationManager
implementation, e.g. BasicAuthenticationManager
class that would explicitly enumerate credentials. By default, no authentication manager is used, i.e. SVNKit will only work with open-source repositories, failing for operations requiring authentication.
Finally I would like you to note that SVNKit contains ‘jsvn’ utility which is a Java-based implementation of Subversion. The sources of this utility are located in
package org.tmatesoft.svn.cli.svn;
package. And SVNCommandEnvironment
class contains common code for all the commands, in particular SVNCommandEnvironment#createClientAuthenticationManager
creates authentication manager for ‘jsvn’ utility. So you can always refer to this class as the example. Or you can run
org.tmatesoft.svn.cli.SVN.main(...)
in the debugger and see how SVNKit internals are used.
And also you can look at SVNXXXClient classes (i.e. the older API) to see how they are implemented via the newer SvnOperationFactory API. This will give you understanding how the old and the new APIs are related.
What about “svnadmin verify”, there’s only one API for “svnadmin” in SVNKit, it is based on SVNAdminClient
class.
final SVNClientManager clientManager = SVNClientManager.newInstance();
try {
final SVNAdminClient adminClient = clientManager.getAdminClient();
adminClient.setEventHandler(new ISVNAdminEventHandler() {
@Override
public void handleAdminEvent(SVNAdminEvent event, double progress) throws SVNException {
//handle the verification event here
}
@Override public void handleEvent(SVNEvent event, double progress) throws SVNException {}
@Override public void checkCancelled() throws SVNCancelException {}
});
adminClient.doVerify(repositoryDirectory);
} finally {
clientManager.dispose();
}
Finally you can look at SVNKit tests as the example of usage of some operations.
I hope this information helps.