/**
* 功能说明:SVN检出功能工具类
*
* @date 2016-3-29
* @author malin
*
*/
public class DoCheckOutUtil {
//声明SVN客户端管理类
private static SVNClientManager ourClientManager;
public static void main(String[] args) throws Exception {
//初始化支持svn://协议的库。 必须先执行此操作。
Properties properties = System.getProperties();
properties.setProperty("svnkit.http.methods", "Basic,Digest,NTLM");
DAVRepositoryFactory.setup();
//相关变量赋值
SVNURL repositoryURL = null;
try {
repositoryURL = SVNURL.parseURIEncoded("SVN检出地址initsql/base/lib");
} catch (SVNException e) {
//
}
String name = "用户名";
String password = "登录密码";
ISVNOptions options = SVNWCUtil.createDefaultOptions(true);
//实例化客户端管理类
ourClientManager = SVNClientManager.newInstance(
(DefaultSVNOptions) options, name, password);
//要把版本库的内容check out到的目录
File wcDir = new File("e:/svntest/wc");
//通过客户端管理类获得updateClient类的实例。
SVNUpdateClient updateClient = ourClientManager.getUpdateClient();
/*
* sets externals not to be ignored during the checkout
*/
updateClient.setIgnoreExternals(false);
//执行check out 操作,返回工作副本的版本号。
long workingVersion= updateClient
.doCheckout(repositoryURL, wcDir, SVNRevision.HEAD, SVNRevision.HEAD, SVNDepth.INFINITY,false);
System.out.println("把版本:"+workingVersion+" check out 到目录:"+wcDir+"中。");
}
SVN的API查询官网在http://svnkit.com/javadoc/overview-summary.html
目前是1。8
=====================
后面的处理:/**
* 设置环境
*/
public static void setupLibrary() {
DAVRepositoryFactory.setup();
SVNRepositoryFactoryImpl.setup();
FSRepositoryFactory.setup();
try {
repository = SVNRepositoryFactory.create(SVNURL
.parseURIEncoded(url));
} catch (SVNException e) {
System.out.println(e.getErrorMessage());
}
// 身份验证
ISVNAuthenticationManager authManager = SVNWCUtil
.createDefaultAuthenticationManager(name, password);
repository.setAuthenticationManager(authManager);
}
/**
* 过滤条件
* @throws Exception
*/
public static void filterCommitHistory() throws Exception {
final Set set=new HashSet();
long endRevision = -1;// 表示最后一个版本
//final List<String> history = new ArrayList<String>();
// String[] 为过滤的文件路径前缀,为空表示不进行过滤
// repository.l
repository.log(new String[] { "" }, startRevision, endRevision, true,
true, new ISVNLogEntryHandler() {
@Override
public void handleLogEntry(SVNLogEntry svnlogentry)
throws SVNException {
// 依据提交时间进行过滤
//if (svnlogentry.getDate().after(begin)&& svnlogentry.getDate().before(end)) {
// 依据提交人过滤
if (!"".equals(author)) {
if (author.equals(svnlogentry.getAuthor())) {
fillResult(svnlogentry);
}
} else {
fillResult(svnlogentry);
}
//}
}
public void fillResult(SVNLogEntry svnlogentry) {
// getChangedPaths为提交的历史记录MAP key为文件名,value为文件详情
Iterator<?> it = svnlogentry.getChangedPaths().keySet()
.iterator();
if (it.hasNext()) {
SVNLogEntryPath entryPath = (SVNLogEntryPath) svnlogentry
.getChangedPaths().get(it.next());
String str=entryPath.getPath().substring(6);//路径
if("D".equals(String.valueOf(entryPath.getType()))){
str=str+" 删除";
}
if(!set.contains(str)&&svnlogentry.getMessage().contains(ModifedNum)){
set.add(str);
System.out.println(str);
}
}
}
});
}
public static void main(String[] args) {
System.setProperty("svnkit.http.methods", "Basic,Digest,NTLM");
setupLibrary();
try {
filterCommitHistory();
} catch (Exception e) {
e.printStackTrace();
}
}
}
svnkit.jar 这个lib