67,513
社区成员
发帖
与我相关
我的任务
分享
public static void main(String[] args) {
// 初始化支持svn://协议的库。 必须先执行此操作。
SVNRepositoryFactoryImpl.setup();
/*
* 相关变量赋值
*/
String url = "xxxxxxxx";
String name = "xxxxxx";
String password = "xxxxxxxxx";
// 定义svn版本库的URL。
SVNURL repositoryURL = null;
// 定义版本库。
SVNRepository repository = null;
/*
* 实例化版本库类
*/
try {
// 获取SVN的URL
repositoryURL = SVNURL.parseURIEncoded(url);
// 根据URL实例化SVN版本库
repository = SVNRepositoryFactory.create(repositoryURL);
} catch (SVNException svne) {
/*
* 打印版本库实例创建失败的异常
*/
System.err.println("创建版本库实例时失败,版本库的URL是 '" + url + "': "
+ svne.getMessage());
System.exit(1);
}
/*
* 对版本库设置认证信息
*/
ISVNAuthenticationManager authManager = SVNWCUtil
.createDefaultAuthenticationManager(name, password);
repository.setAuthenticationManager(authManager);
try {
listEntries(repository, "");
} catch (SVNException svne) {
System.err.println("打印版本树时发生错误: " + svne.getMessage());
System.exit(1);
}
/*
* 获得版本库的最新版本树
*/
long latestRevision = -1;
try {
latestRevision = repository.getLatestRevision();
} catch (SVNException svne) {
System.err.println("获取最新版本号时出错: " + svne.getMessage());
System.exit(1);
}
System.exit(0);
}
/*
* 此函数递归的获取版本库中某一目录下的所有条目。
*/
@SuppressWarnings("unchecked")
public static void listEntries(SVNRepository repository, String path)
throws SVNException {
// 获取版本库的path目录下的所有条目。参数-1表示是最新版本。
Collection entries = repository.getDir(path, -1, null,
(Collection) null);
Iterator iterator = entries.iterator();
while (iterator.hasNext()) {
//只获取文件夹的名字,如果类型非dir退出本次循环
if(entry.getKind() != SVNNodeKind.DIR){
continue;
}
SVNDirEntry entry = (SVNDirEntry) iterator.next();
System.out.println("/" + (path.equals("") ? "" : path + "/")
+ entry.getName() + " (author: '" + entry.getAuthor()
+ "'; revision: " + entry.getRevision() + "; date: "
+ entry.getDate() +"ENTRY MESS"+entry.getCommitMessage()+ ")");
/*
* 检查此条目是否为目录,如果为目录递归执行
*/
if (entry.getKind() == SVNNodeKind.DIR) {
listEntries(repository, (path.equals("")) ? entry.getName()
: path + "/" + entry.getName());
}
}
}