java操作svn--部分方法

刺骨的言语ヽ痛彻心扉 2022-08-13 16:43 175阅读 0赞
  1. package com.svnutil;
  2. import java.io.File;
  3. import java.text.DateFormat;
  4. import java.util.ArrayList;
  5. import java.util.Collection;
  6. import java.util.Iterator;
  7. import java.util.List;
  8. import java.util.Map;
  9. import org.tmatesoft.svn.core.SVNDepth;
  10. import org.tmatesoft.svn.core.SVNDirEntry;
  11. import org.tmatesoft.svn.core.SVNURL;
  12. import org.tmatesoft.svn.core.auth.ISVNAuthenticationManager;
  13. import org.tmatesoft.svn.core.internal.io.svn.ISVNConnector;
  14. import org.tmatesoft.svn.core.internal.io.svn.SVNRepositoryFactoryImpl;
  15. import org.tmatesoft.svn.core.internal.wc.DefaultSVNOptions;
  16. import org.tmatesoft.svn.core.io.SVNRepository;
  17. import org.tmatesoft.svn.core.io.SVNRepositoryFactory;
  18. import org.tmatesoft.svn.core.wc.ISVNConflictHandler;
  19. import org.tmatesoft.svn.core.wc.ISVNOptions;
  20. import org.tmatesoft.svn.core.wc.SVNClientManager;
  21. import org.tmatesoft.svn.core.wc.SVNRevision;
  22. import org.tmatesoft.svn.core.wc.SVNUpdateClient;
  23. import org.tmatesoft.svn.core.wc.SVNWCUtil;
  24. @SuppressWarnings("all")
  25. public class ReadDirFromSVN {
  26. //从svn中拿到一个目录的子目录
  27. public static List<String> getFileDir(String username,String password,String SVNRoot){
  28. List<String> lists=new ArrayList<String>();
  29. try{
  30. SVNRepository repository=SVNRepositoryFactory.create(SVNURL.parseURIEncoded(SVNRoot));//找到svn的url
  31. ISVNAuthenticationManager authManager=SVNWCUtil.createDefaultAuthenticationManager(username,password);//用户验证
  32. repository.setAuthenticationManager(authManager);
  33. Collection entries=repository.getDir("", -1, null, (Collection)null);
  34. Iterator iterators=entries.iterator();
  35. while(iterators.hasNext()){
  36. SVNDirEntry entry=(SVNDirEntry)iterators.next();
  37. lists.add(entry.getName());
  38. }
  39. }catch(Exception e){
  40. e.printStackTrace();
  41. }
  42. return lists;
  43. }
  44. //从项目中checkout代码
  45. public static void checkout(String sourceRoot,String targetRoot,String username,String password){
  46. // SVNRepositoryFactoryImpl.setup();
  47. // ISVNOptions options=SVNWCUtil.createDefaultOptions(true);
  48. //SVNClientManager client=SVNClientManager.newInstance((DefaultSVNOptions)options,username,password);//拿到客户端并进行验证
  49. SVNClientManager client=SVNClientManager.newInstance();//拿到客户端
  50. ISVNAuthenticationManager authManager=SVNWCUtil.createDefaultAuthenticationManager(username,password);//用户验证参数
  51. client.setAuthenticationManager(authManager);//进行用户验证
  52. try{
  53. SVNUpdateClient updateClient = client.getUpdateClient();
  54. client.setIgnoreExternals(false);
  55. System.out.println("checkout...");
  56. updateClient.doCheckout(SVNURL.parseURIEncoded(sourceRoot), new File(targetRoot),
  57. SVNRevision.HEAD, SVNRevision.HEAD, true);
  58. System.out.println("checkout complement!");
  59. }catch(Exception e){
  60. e.printStackTrace();
  61. }
  62. }
  63. //测试
  64. public static void main(String[] args) {
  65. // List<String> lists=ReadDirFromSVN.getFileDir("admin", "admin", "https://192.168.1.188/svn/svndemo/javacore/");
  66. // for (String string : lists) {
  67. // System.out.println(string);
  68. // }
  69. ReadDirFromSVN.checkout("https://192.168.1.188/svn/svndemo/javacore/", "E:\\checkout", "admin", "admin");
  70. }
  71. }

发表评论

表情:
评论列表 (有 0 条评论,175人围观)

还没有评论,来说两句吧...

相关阅读

    相关 SVN操作概述

    一、SVN定义         SVN(Subversion)是近年来崛起的 [版本管理][Link 1]工具。目前,绝大多数的 [开源软件][Link 2]都使用svn作为

    相关 SVN操作

            上一章讲解的SVN的基本知识即:是什么,干什么,如何来的等问题这一章咱们来讲解一下是如何应用的。       SVN的操作:      服务器:

    相关 SVN基本操作

    如果在没有系统地看过SVN相关书籍的情况下,就开始使用SVN的话,是会有一些摸不着头脑的(比如我啦……)。经过较长时间的使用后,将一些浅显的认知记录如下: 1、SVN是项目管

    相关 svn 理论部分

    SVN:集中式版本控制系统 svn版本是集中式的数据管理,存在一个中央版本库,所有开发人员本地开发所使用的代码都是来自于这个版本库,提交代码也都必须提交到这个中央版本库。