Jul 24, 2014

Java with SVNKit to programmatically checkout and update files

Q. What is SVNKit?
A. SVNKit is an Open Source, pure Java software library for working with the Subversion version control system.

Q. What libraries are required?

Use the latest version from the SVNKit website or Maven repository.

Here is the sample code:

package test;


import org.tmatesoft.svn.core.SVNDepth;
import org.tmatesoft.svn.core.SVNURL;
import org.tmatesoft.svn.core.auth.BasicAuthenticationManager;
import org.tmatesoft.svn.core.auth.ISVNAuthenticationManager;
import org.tmatesoft.svn.core.wc.SVNClientManager;
import org.tmatesoft.svn.core.wc.SVNRevision;
import org.tmatesoft.svn.core.wc.SVNUpdateClient;
import org.tmatesoft.svn.core.wc.SVNWCUtil;

public class SVNTest {
 private static SVNClientManager ourClientManager;

 public static void main(String[] args) throws Exception {
  SVNURL url = SVNURL.parseURIDecoded("http://svn-host/svn/myapp/artifacts/trunk/XSD/");
  ISVNAuthenticationManager authManager = new BasicAuthenticationManager("NTADMIN\\name", "pwd");
  ourClientManager = SVNClientManager.newInstance(SVNWCUtil.createDefaultOptions(true));
  SVNUpdateClient updateClient = ourClientManager.getUpdateClient();
  File dstPath = new File("c:\\Temp\\myapp");
  SVNRevision pegRevision = SVNRevision.HEAD;
  SVNRevision revision = SVNRevision.HEAD;
  SVNDepth depth = SVNDepth.IMMEDIATES;
  boolean allowUnversionedObstructions = true;
  long res = 0;
  if (new File("c:\\Temp\\wts").list().length == 0) {
   res = updateClient.doCheckout(url , dstPath , pegRevision , revision, depth , allowUnversionedObstructions );
  } else { 
   res = updateClient.doUpdate(dstPath, revision, depth, allowUnversionedObstructions, true);


The above code is quick and dirty for familiarization with SVNKit.

Q. Where to use SVNKit?

  • SVNKit is widely used in different development tools like IDEs (IntelliJ IDEA, Eclipse Subversion integrations, SmartSVN, JDeveloper, etc) and SDLC tools like Atlassian JIRA and FishEye to name a few. 
  • You can use it on your own home grown  automation activities relating SDLC, one off data migration tasks and batch jobs. 



Post a Comment

Subscribe to Post Comments [Atom]

<< Home