svn 检出代码库到目标路径
svn 检出代码库到目标路径
public static boolean checkout(String url, String user, String password, File targetDir) {
//url:svn 仓库地址,user:用户名;password:密码;targetDir:保存的目标路径
DAVRepositoryFactory.setup();
/*
\* For using over svn:// and svn+xxx://
*/
SVNRepositoryFactoryImpl.setup();
/*
\* For using over file:///
*/
FSRepositoryFactory.setup();
// 相关变量赋值
SVNURL repositoryURL = null;
try {
repositoryURL = SVNURL.parseURIEncoded(url);
} catch (SVNException e) {
return false;
}
ISVNOptions options = SVNWCUtil.createDefaultOptions(true);
// 实例化客户端管理类
SVNClientManager ourClientManager = SVNClientManager.newInstance((DefaultSVNOptions) options, user, password);
// 通过客户端管理类获得updateClient类的实例。
SVNUpdateClient updateClient = ourClientManager.getUpdateClient();
updateClient.setIgnoreExternals(false);
// 执行check out 操作,返回工作副本的版本号。
long workingVersion = -1;
try {
workingVersion = updateClient.doCheckout(repositoryURL, targetDir, SVNRevision.HEAD, SVNRevision.HEAD,
SVNDepth.INFINITY, false);
} catch (SVNException e) {
return false;
} catch (Exception e) {
return false;
}
System.out.println("把版本:" + workingVersion + " check out 到目录:" + targetDir + "中。");
return true;
}