1. util.DefaultSVNAnnotateHandler.java
package util; import java.io.File; import java.util.Date; import java.util.HashMap; import java.util.Map; import org.tmatesoft.svn.core.SVNException; import org.tmatesoft.svn.core.wc.ISVNAnnotateHandler; public class DefaultSVNAnnotateHandler implements ISVNAnnotateHandler { private Map<Integer,String> lineAuthorMap = new HashMap<Integer,String>(); public void handleEOF() throws SVNException { // TODO Auto-generated method stub } public void handleLine(Date date, long revision, String author, String line) throws SVNException { } public void handleLine(Date date, long revision, String author, String line, Date mergedDate, long mergedRevision, String mergedAuthor, String mergedPath, int lineNumber) throws SVNException { lineAuthorMap.put(lineNumber, author); } public boolean handleRevision(Date date, long revision, String author, File contents) throws SVNException { // TODO Auto-generated method stub return false; } public Map<Integer, String> getLineAuthorMap() { return lineAuthorMap; } }
2. util.SVNUtil.java
package util; import java.io.File; import java.io.FileOutputStream; import java.io.IOException; import java.util.Map; import java.util.logging.Logger; import org.tmatesoft.svn.core.SVNException; import org.tmatesoft.svn.core.SVNURL; import org.tmatesoft.svn.core.auth.BasicAuthenticationManager; import org.tmatesoft.svn.core.auth.ISVNAuthenticationManager; import org.tmatesoft.svn.core.io.SVNRepository; import org.tmatesoft.svn.core.wc.SVNClientManager; import org.tmatesoft.svn.core.wc.SVNRevision; public class SVNUtil { private static Logger logger = Logger.getLogger(SVNUtil.class.getName()); private static SVNClientManager getSVNClientManager(){ SVNClientManager svnClientManager = SVNClientManager.newInstance(); ISVNAuthenticationManager authManager = new BasicAuthenticationManager("xiao", "xiao"); svnClientManager.setAuthenticationManager(authManager ); return svnClientManager; } public static File getFileFromSVN(String filePath, long revision,String destFilePath) { File file = new File(destFilePath); SVNURL reponsitoryURL = null; FileOutputStream fos = null; try { reponsitoryURL = SVNURL.parseURIEncoded(filePath); fos = new FileOutputStream(file); SVNRepository reponsitory = getSVNClientManager().createRepository(reponsitoryURL, false); reponsitory.getFile("", revision, null, fos); } catch (Exception e) { throw new RuntimeException(e); }finally{ if(fos!=null){ try { fos.close(); } catch (IOException e) { logger.warning(e.getMessage()); } } } return file; } public static Map<Integer,String> getFileInfo(String filePath,long revision) throws SVNException{ SVNURL url = SVNURL.parseURIEncoded(filePath); SVNRevision pegRevision = SVNRevision.create(revision); SVNRevision startRevision = SVNRevision.create(0); SVNRevision endRevision = SVNRevision.create(revision); DefaultSVNAnnotateHandler handler = new DefaultSVNAnnotateHandler(); getSVNClientManager().getLogClient().doAnnotate(url, pegRevision, startRevision, endRevision, handler); return handler.getLineAuthorMap(); } }
pom.xml
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>svn</groupId> <artifactId>svn</artifactId> <packaging>jar</packaging> <version>0.0.1-SNAPSHOT</version> <name>svn</name> <url>http://maven.apache.org</url> <dependencies> <dependency> <groupId>org.tmatesoft.svnkit</groupId> <artifactId>svnkit</artifactId> <version>1.8.5</version> </dependency> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>3.8.1</version> <scope>test</scope> </dependency> </dependencies> </project>
相关推荐
svn版本库控制管理工具,安装及简单功能使用文档
SVN简单使用手册SVN简单使用手册SVN简单使用手册SVN简单使用手册SVN简单使用手册SVN简单使用手册
SVN使用SVN使用SVN使用
SVN使用教程SVN使用教程SVN使用教程SVN使用教程SVN使用教程SVN使用教程SVN使用教程SVN使用教程SVN使用教程SVN使用教程SVN使用教程SVN使用教程SVN使用教程SVN使用教程SVN使用教程SVN使用教程SVN使用教程SVN使用教程
eclipse中svn插件的使用
svn简单使用svn简单使用svn简单使用
SVN现在是个很热门的东西,本节就向大家讲解一下SVN使用教程简易入门,希望通过本节的学习对你学习SVN有所提高。 每个程序员都应该参与团队合作项目,我想您也会参加的,如果参加过你是否遇到过这样的情况:当你正在...
SVN管理员使用指南,SVN管理员使用指南
Svn Connector 内含: Native JavaHL 1.6 1.7 Svn connector Svn kit 1.3.8 Svn kit 1.7.10
SVN代码管理使用 SVN代码管理使用
svn中文使用手册 svn中文使用手册 svn中文使用手册
SVN安装与使用教程,简单介绍了SVN的安装与使用
SVN客户端图形使用 SVN客户端图形使用 SVN客户端图形使用
使用它我们可以做到随时随地的进行项目开发,摆脱了开发过程中空间的限制(当然,随时随地的条件是可以上网),同时解决了团队合作中的一个令人头疼的问题--修改冲突。以前我们用SourceSafe进行项目控制时,经常发生...
Svn安装和使用教程 Svn安装和使用教程 Svn安装和使用教程
svn用户使用指南 svn用户使用指南 svn用户使用指南
svn windows客户端使用说明
资源库SVN简易使用手册
针对SVN的资源使用,让新手更加容易理解怎么使用SVN,并熟悉其操作过程
svn一个简单的项目,介绍svn的使用,初步了解svn的原理;