Skip to content

Instantly share code, notes, and snippets.

@cliffdarling
Created April 11, 2012 17:46
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save cliffdarling/2360866 to your computer and use it in GitHub Desktop.
Save cliffdarling/2360866 to your computer and use it in GitHub Desktop.
SVNKit export from Subversion example
import java.io.File;
import org.tmatesoft.svn.core.SVNDepth;
import org.tmatesoft.svn.core.SVNException;
import org.tmatesoft.svn.core.SVNURL;
import org.tmatesoft.svn.core.auth.ISVNAuthenticationManager;
import org.tmatesoft.svn.core.io.SVNRepository;
import org.tmatesoft.svn.core.io.SVNRepositoryFactory;
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 SvnExportExample {
public static void main(String... args){
final String url = "svn://cavcops01.global.local/skunkworks";
final String destPath = "c:/temp/svntest";
SVNRepository repository = null;
try{
//initiate the reporitory from the url
repository = SVNRepositoryFactory.create(SVNURL.parseURIDecoded(url));
//create authentication data
ISVNAuthenticationManager authManager =
SVNWCUtil.createDefaultAuthenticationManager("cliff.darling", "svnuser");
repository.setAuthenticationManager(authManager);
//output some data to verify connection
System.out.println( "Repository Root: " + repository.getRepositoryRoot( true ) );
System.out.println( "Repository UUID: " + repository.getRepositoryUUID( true ) );
//need to identify latest revision
long latestRevision = repository.getLatestRevision();
System.out.println( "Repository Latest Revision: " + latestRevision);
//create client manager and set authentication
SVNClientManager ourClientManager = SVNClientManager.newInstance();
ourClientManager.setAuthenticationManager(authManager);
//use SVNUpdateClient to do the export
SVNUpdateClient updateClient = ourClientManager.getUpdateClient( );
updateClient.setIgnoreExternals( false );
updateClient.doExport( repository.getLocation(), new File(destPath),
SVNRevision.create(latestRevision), SVNRevision.create(latestRevision),
null, true, SVNDepth.INFINITY);
} catch (SVNException e) {
e.printStackTrace();
}finally {
System.out.println("Done");
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment