SVN正确性验证

import org.tmatesoft.svn.core.SVNErrorCode;
import org.tmatesoft.svn.core.SVNErrorMessage;
import org.tmatesoft.svn.core.SVNException;
import org.tmatesoft.svn.core.SVNNodeKind;
import org.tmatesoft.svn.core.SVNURL;
import org.tmatesoft.svn.core.auth.ISVNAuthenticationManager;
import org.tmatesoft.svn.core.internal.io.dav.DAVRepositoryFactory;
import org.tmatesoft.svn.core.io.SVNRepository;
import org.tmatesoft.svn.core.io.SVNRepositoryFactory;
import org.tmatesoft.svn.core.wc.SVNWCUtil;

public class SvnUtil {

private static String STRING_EMPTY = "";
private static int NEGATIVE_ONE = -1;

/**
* 测试SVN地址是否正确
*
* @param svnUrl
* SVN地址
* @param svnUser
* SVN用户名
* @param strPassword
* SVN密码
* @throws SVNException
* SVNException
*/
public static boolean testConnection(String svnUrl, String svnUser,
String strPassword) throws SVNException {
DAVRepositoryFactory.setup(); // 对于通过使用 http:// 和 https:// 访问
SVNRepository repository = SVNRepositoryFactory.create(SVNURL
.parseURIEncoded(svnUrl));
ISVNAuthenticationManager auth = SVNWCUtil
.createDefaultAuthenticationManager(svnUser, strPassword);
repository.setAuthenticationManager(auth);
SVNNodeKind nodeKind = repository.checkPath(STRING_EMPTY, NEGATIVE_ONE);
if (nodeKind == SVNNodeKind.NONE) {
SVNErrorMessage err = SVNErrorMessage.create(SVNErrorCode.UNKNOWN,
"No project at URL");
throw new SVNException(err);

}
return true;
}

/**
* 测试SVN连接是否正常
*/
private static boolean testSvnConnection(String svnUrl, String svnUser,
String strPassword) {
try {
testConnection(svnUrl, svnUser, strPassword);
} catch (SVNException expection) {
if (expection.getMessage().startsWith(
"svn: Authentication required for")) {
System.out.println("用户名密码错误");
return false;

} else {
System.out.println("连接失败!");
return false;
}

}
System.out.println("连接成功!");
return true;
}

}


需要jar包:
svnkit-cli.jar
svnkit-javahl.jar
svnkit.jar
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值