SVN正确性验证

importorg.tmatesoft.svn.core.SVNErrorCode;

importorg.tmatesoft.svn.core.SVNErrorMessage;

importorg.tmatesoft.svn.core.SVNException;

importorg.tmatesoft.svn.core.SVNNodeKind;

importorg.tmatesoft.svn.core.SVNURL;

importorg.tmatesoft.svn.core.auth.ISVNAuthenticationManager;

importorg.tmatesoft.svn.core.internal.io.dav.DAVRepositoryFactory;

importorg.tmatesoft.svn.core.io.SVNRepository;

importorg.tmatesoft.svn.core.io.SVNRepositoryFactory;

importorg.tmatesoft.svn.core.wc.SVNWCUtil;

publicclassSvnUtil{

privatestaticStringSTRING_EMPTY="";

privatestaticintNEGATIVE_ONE=-1;

/**

*测试SVN地址是否正确

*

*@paramsvnUrl

*SVN地址

*@paramsvnUser

*SVN用户名

*@paramstrPassword

*SVN密码

*@throwsSVNException

*SVNException

*/

publicstaticbooleantestConnection(StringsvnUrl,StringsvnUser,

StringstrPassword)throwsSVNException{

DAVRepositoryFactory.setup();//对于通过使用http://和https://访问

SVNRepositoryrepository=SVNRepositoryFactory.create(SVNURL

.parseURIEncoded(svnUrl));

ISVNAuthenticationManagerauth=SVNWCUtil

.createDefaultAuthenticationManager(svnUser,strPassword);

repository.setAuthenticationManager(auth);

SVNNodeKindnodeKind=repository.checkPath(STRING_EMPTY,NEGATIVE_ONE);

if(nodeKind==SVNNodeKind.NONE){

SVNErrorMessageerr=SVNErrorMessage.create(SVNErrorCode.UNKNOWN,

"NoprojectatURL");

thrownewSVNException(err);

}

returntrue;

}

/**

*测试SVN连接是否正常

*/

privatestaticbooleantestSvnConnection(StringsvnUrl,StringsvnUser,

StringstrPassword){

try{

testConnection(svnUrl,svnUser,strPassword);

}catch(SVNExceptionexpection){

if(expection.getMessage().startsWith(

"svn:Authenticationrequiredfor")){

System.out.println("用户名密码错误");

returnfalse;

}else{

System.out.println("连接失败!");

returnfalse;

}

}

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

returntrue;

}

}

需要jar包:

svnkit-cli.jar

svnkit-javahl.jar

svnkit.jar

相关推荐