api调用svn下载

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.internal.io.svn.SVNRepositoryFactoryImpl;
import org.tmatesoft.svn.core.internal.wc.DefaultSVNOptions;
import org.tmatesoft.svn.core.wc.ISVNOptions;
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;

/**
 * api调用svn下载
 *
 * @date 2016-06-14
 *
 * 实现api调用svn下载功能,至少需要以下jar包:
 * svnkit-1.8.12.jar
 * svnkit-cli-1.8.12.jar
 * antlr-runtime-3.4.jar
 * sequence-library-1.0.3.jar
 * sqljet-1.1.10.jar
 *
 */
public class SVNUtil {
 public static void main(String[] args) throws SVNException {
  long checkoutResult= svnCheckout("https://192.168.0.1:8443/svn/svntest", "xxx", "123456", "D:/MySVNTest");
  System.out.println(checkoutResult);
 }
 /**
  * api调用svn下载,返回所下载项目版本的版本号
  * @param SVNUrl svn地址
  * @param userName svn用户名
  * @param password svn密码
  * @param savePath 下载后的项目存储路径
  * @return
  * @throws SVNException
  */
 public static long svnCheckout(String SVNUrl,String userName,String password,String savePath) throws SVNException{
  //版本号
  long checkoutResult = 0;
  SVNRepositoryFactoryImpl.setup();
  SVNURL sVNURL = SVNURL
    .parseURIEncoded(SVNUrl);
  ISVNOptions options = SVNWCUtil.createDefaultOptions(true);
  SVNClientManager ourClientManager = SVNClientManager.newInstance(
    (DefaultSVNOptions) options, userName, password);
  File localFileDir = new File(savePath);
  if (localFileDir.exists()) {
  // System.err.println("copypath already exist");
  } else {
   localFileDir.mkdirs();
  }
  try {
   SVNUpdateClient updateClient = ourClientManager.getUpdateClient();
   updateClient.setIgnoreExternals(false);
   //返回的是所下载项目版本的版本号
   checkoutResult = updateClient.doCheckout(sVNURL, localFileDir, SVNRevision.HEAD,SVNRevision.HEAD, SVNDepth.INFINITY, true);
  } catch (Exception e) {
   System.out.println(e.getMessage());
   e.printStackTrace();
  }
  return checkoutResult;
 }

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值