1、SVN服务器和客户端的安装及配置
参考http://www.cnblogs.com/xiaobaihome/archive/2012/03/20/2407610.html需注意的是:安装TortoiseSVN时最好把Command Line Client Tools也安装,否则不能在命令行里使用svn命令。
2、SVNKit
SVNKit是一个纯java的subversion客户端库,使用SVNKit无需安装任何subversion客户端,支持各种操作系统。可以编程实现TortoiseSVN的功能。http://wiki.svnkit.com/Printing_Out_Repository_History 有很多DEMO,可参考。
2.1、使用SVNKit按照时间段来获取SVN资源库的历史操作记录
// 版本库初始化
DAVRepositoryFactory.setup();
// 资源库相关登录配置信息
String url = "SVN资源库地址";
String username = "stypace";
String password = "123456";
long startRevision = 0;// 最初版本
long endRevision = -1;//最近版本
// 资源库
SVNRepository repository = null;
try {
// 时间参数
final SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
// final Date begin = format.parse(args[0]);
// final Date end = format.parse(args[1]);
final Date begin = format.parse("2015-01-27 10:30:00");
final Date end = format.parse("2015-01-27 20:00:00");
// 建立一个新的资源库
repository = DAVRepositoryFactory.create(SVNURL.parseURIEncoded(url));
// 登录确认信息
ISVNAuthenticationManager authManager = SVNWCUtil.createDefaultAuthenticationManager(
username, password);
repository.setAuthenticationManager(authManager);
// 存放结果
final Collection logEntries = new ArrayList<SVNLogEntry>();
// 执行log函数,根据时间参数获取历史记录
repository.log(new String[] { "" }, startRevision, endRevision, true, true,
new ISVNLogEntryHandler() {
public void handleLogEntry(SVNLogEntry logEntry) throws SVNException {
// 依据提交时间进行过滤
if (logEntry.getDate().after(begin) && logEntry.getDate().before(end)) {
addLogEntry(logEntry);
}
}
public void addLogEntry(SVNLogEntry logEntry) {
logEntries.add(logEntry);
}
});
// 遍历
for (Iterator entries = logEntries.iterator(); entries.hasNext();) {
SVNLogEntry logEntry = (SVNLogEntry) entries.next();
System.out.println("---------------------------------------------");
System.out.println("revision: " + logEntry.getRevision());
System.out.println("author: " + logEntry.getAuthor());
System.out.println("date: " + logEntry.getDate());
System.out.println("log message: " + logEntry.getMessage());
if (logEntry.getChangedPaths().size() > 0) {
System.out.println();
System.out.println("changed paths:");
Set changedPathsSet = logEntry.getChangedPaths().keySet();
for (Iterator changedPaths = changedPathsSet.iterator(); changedPaths.hasNext();) {
SVNLogEntryPath entryPath = logEntry.getChangedPaths().get(
changedPaths.next());
System.out
.println(" "
+ entryPath.getType()
+ " "
+ entryPath.getPath()
+ ((entryPath.getCopyPath() != null) ? " (from "
+ entryPath
.getCopyPath()
+ " revision "
+ entryPath
.getCopyRevision()
+ ")" : ""));
}
}
}
} catch (Exception ex) {
System.out.println(ex.toString());
}
System.exit(1);
}