0、功能列表
svnkit功能列表 1、遞歸獲取指定目錄下目錄和文件,以樹形展示【svn Update】 2、獲取指定文件和屬性(版本號、作者、日期、文件類型) 3、獲取指定文件或目錄的歷史記錄(版本號、作者、日期、log message)【show log...】 4、提交指定目錄(遞歸)或文件【svn commit...】 5、導出svn server指定目錄或文件到本地指定目錄【Export...】 6、復制已經存在的Repository 7、檢查文件或目錄是否存在&確定路徑是文件還是目錄 8、創建新目錄 9、將本地svn切換到另外svn 地址【Relocate...】 10、鎖定文件【get Lock/release Lock】、刪除文件【delete】、復制/移動文件
1、為了支持不同協議,需要安裝相應類庫
//為了使用 http:// and https:// DAVRepositoryFactory.setup(); //為了使用 svn:// and svn+xxx:// SVNRepositoryFactoryImpl.setup(); //為了使用 file:/// FSRepositoryFactory.setup();
2、創建SVNRepository來管理repository.
/* * 創建SVNRepository來管理repository. * SVNURL 是url的包裝對象 */ repository = SVNRepositoryFactory.create(SVNURL.parseURIEncoded(url));
3、登錄
//登錄 ISVNAuthenticationManager authManager = SVNWCUtil.createDefaultAuthenticationManager(name, password.toCharArray()); repository.setAuthenticationManager(authManager);
4、驗證entry是否存在/文件還是目錄
/* * SVNNodeKind.NONE :無此目錄或文件 * SVNNodeKind.FILE :該地址是個文件 * SVNNodeKind.DIR :該地址是個目錄 */ SVNNodeKind nodeKind = repository.checkPath("", -1);
5、獲取該倉庫的根路徑
//輸出:http://1.2.3.4/svn/sloth repository.getRepositoryRoot(true);
6、獲取指定目錄下的所有文件或目錄
Collection entries = repository.getDir(path, -1, null,(Collection) null); Iterator iterator = entries.iterator(); while (iterator.hasNext()) { SVNDirEntry entry = (SVNDirEntry) iterator.next(); System.out.println("/" + (path.equals("") ? "" : path + "/") + entry.getName() + " (author: '" + entry.getAuthor() + "'; revision: " + entry.getRevision() + "; date: " + entry.getDate() + ")"); }
7、獲取文件內容與文件屬性
SVNProperties fileProperties = new SVNProperties(); ByteArrayOutputStream baos = new ByteArrayOutputStream(); /* * 獲取文件內容和屬性。-1:最后版本。 */ repository.getFile(filePath, -1, fileProperties, baos); String mimeType = fileProperties.getStringValue(SVNProperty.MIME_TYPE); boolean isTextType = SVNProperty.isTextMimeType(mimeType); Iterator iterator = fileProperties.nameSet().iterator(); while (iterator.hasNext()) { String propertyName = (String) iterator.next(); String propertyValue = fileProperties.getStringValue(propertyName); }
8、獲取repository最后版本
latestRevision = repository.getLatestRevision();