java操作svn--部分方法
2014-11-06 20:58
447 查看
package com.svnutil; import java.io.File; import java.text.DateFormat; import java.util.ArrayList; import java.util.Collection; import java.util.Iterator; import java.util.List; import java.util.Map; import org.tmatesoft.svn.core.SVNDepth; import org.tmatesoft.svn.core.SVNDirEntry; import org.tmatesoft.svn.core.SVNURL; import org.tmatesoft.svn.core.auth.ISVNAuthenticationManager; import org.tmatesoft.svn.core.internal.io.svn.ISVNConnector; import org.tmatesoft.svn.core.internal.io.svn.SVNRepositoryFactoryImpl; import org.tmatesoft.svn.core.internal.wc.DefaultSVNOptions; import org.tmatesoft.svn.core.io.SVNRepository; import org.tmatesoft.svn.core.io.SVNRepositoryFactory; import org.tmatesoft.svn.core.wc.ISVNConflictHandler; 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; @SuppressWarnings("all") public class ReadDirFromSVN { //从svn中拿到一个目录的子目录 public static List<String> getFileDir(String username,String password,String SVNRoot){ List<String> lists=new ArrayList<String>(); try{ SVNRepository repository=SVNRepositoryFactory.create(SVNURL.parseURIEncoded(SVNRoot));//找到svn的url ISVNAuthenticationManager authManager=SVNWCUtil.createDefaultAuthenticationManager(username,password);//用户验证 repository.setAuthenticationManager(authManager); Collection entries=repository.getDir("", -1, null, (Collection)null); Iterator iterators=entries.iterator(); while(iterators.hasNext()){ SVNDirEntry entry=(SVNDirEntry)iterators.next(); lists.add(entry.getName()); } }catch(Exception e){ e.printStackTrace(); } return lists; } //从项目中checkout代码 public static void checkout(String sourceRoot,String targetRoot,String username,String password){ // SVNRepositoryFactoryImpl.setup(); // ISVNOptions options=SVNWCUtil.createDefaultOptions(true); //SVNClientManager client=SVNClientManager.newInstance((DefaultSVNOptions)options,username,password);//拿到客户端并进行验证 SVNClientManager client=SVNClientManager.newInstance();//拿到客户端 ISVNAuthenticationManager authManager=SVNWCUtil.createDefaultAuthenticationManager(username,password);//用户验证参数 client.setAuthenticationManager(authManager);//进行用户验证 try{ SVNUpdateClient updateClient = client.getUpdateClient(); client.setIgnoreExternals(false); System.out.println("checkout..."); updateClient.doCheckout(SVNURL.parseURIEncoded(sourceRoot), new File(targetRoot), SVNRevision.HEAD, SVNRevision.HEAD, true); System.out.println("checkout complement!"); }catch(Exception e){ e.printStackTrace(); } } //测试 public static void main(String[] args) { // List<String> lists=ReadDirFromSVN.getFileDir("admin", "admin", "https://192.168.1.188/svn/svndemo/javacore/"); // for (String string : lists) { // System.out.println(string); // } ReadDirFromSVN.checkout("https://192.168.1.188/svn/svndemo/javacore/", "E:\\checkout", "admin", "admin"); } }
相关文章推荐
- java调用svn的方法(基本操作,并不全)
- Java线程操作的部分方法
- Java操作Excel的一种方法
- 使用Java操作文本文件的方法详解
- Java日期操作常用方法
- java操作Excel的一种方法
- java操作XML4中方法总结(转载)
- java操作Excel的一种方法
- Java操作MySQL的中文处理方法一则
- java中操作XML的方法
- java连接操作Oracle出现的问题及解决方法
- JAVA操作Excel的方法
- 如何使用Java操作文本文件的方法详解 (转)
- 利用JAVA操作EXCEL文件的方法
- Java操作Excel的一种方法
- Java基本的六种排序(方法部分)
- java操作Excel的一种方法
- Java日期操作常用方法(转自 csdn)
- 使用Java操作文本文件的方法详解
- Java日期操作常用方法