SVNKIT操作SVN版本库的完整例子
http://www.cnblogs.com/wangjiyuan/p/svnkitwanchenglizi.html#!comments
2.SVNClientManager包括了各种Client来完成日常的SVN操作,如下图:
类 | 命令 | 备注 |
SVNLogClient.doLog() |
svn log [PATHURL] |
从库中显示log消息 |
SVNLogClient.doList() | svn list [TARGET[@REV]...] | 显示目标下的文件和目录列表 |
SVNUpdateClient.doCheckout() | svn checkout URL[@REV]... [PATH] | 检出 |
SVNUpdateClient.doUpdate() | svn update [PATH...] | 更新workcopy |
SVNUpdateClient.doExport() | svn export URLPATH PATH1 | 导出一个干净的目录树,不包含所有的受控信息。可以选择从URL或WC中导出 |
SVNWCClient.doAdd() | svn add [path] | 添加文件至workcopy |
SVNWCClient.doGetFileContents() | svn cat TARGET[@REV] | 输出指定目标的内容 |
SVNWCClient.doDelete() | svn delete PATH... | 从版本库删除 |
SVNWCClient.doInfo() | svn info [TARGET[@REV]...] | 显示指定WC和URL信息 |
SVNWCClient.doLock() | svn lock TARGET... | 加锁 |
SVNWCClient.doUnlock() | svn unlock | 释放锁 |
SVNCommitClient.doCommit() | svn commit [PATH...] | 提交 |
SVNCommitClient.doDelete() | svn delete URL | 删除服务器文件 |
SVNCommitClient.doMkDir() | svn mkdir PATHURL | 在WC或库路径创建目录 |
SVNLogClinet.doAnnotate() | svn blame Target[@REV] | 显示某个已受控文件的每一行的最后修改版本和作者 |
SVNWCClient.doCleanup() | svn cleanup [PATH...] | 递归的清理WC中过期的锁和未完成的操作 |
SVNCopyClient.doCopy() | svn copy SRC[@REV]... DST | copy操作可以从WC到WC |
SVNDiffClient.doDiff() | svn diff | 用来比较并显示修改点 |
SVNCommitClient.doImport() | svn import [PATH] URL | 导入本地一个目录到库中 |
SVNDiffClient.doMerge() |
svn merge |
合并两个受控源的不同之处,存放到一个WC里 |
SVNMoveClinet.doMove() | svn move SRC... DST | 移动 |
SVNWCClient.resovle() | svn resolve PATH | 将冲突文件标记为已解决,删掉冲突产生的临时文件 |
SVNWCClient.revert() | svn revert PATH | 还原WC中所有的本地更改 |
SVNStatusClient.doStatus() | svn status [PATH...] | 输出WC中文件和目录的状态 |
http://blog.sina.com.cn/s/blog_74d4b8a501019cx5.html
报错:
org.tmatesoft.svn.core.SVNAuthenticationException: svn: E171: Authentication required for ‘<http://ip:80>‘
at org.tmatesoft.svn.core.internal.wc.SVNErrorManager.error(SVNErrorManager.java:62)
at org.tmatesoft.svn.core.internal.wc.SVNErrorManager.error(SVNErrorManager.java:51)
at org.tmatesoft.svn.core.internal.io.dav.DAVUtil.findStartingProperties(DAVUtil.java:136)
at org.tmatesoft.svn.core.internal.io.dav.DAVUtil.getBaselineProperties(DAVUtil.java:226)
at org.tmatesoft.svn.core.internal.io.dav.DAVUtil.getBaselineInfo(DAVUtil.java:184)
at org.tmatesoft.svn.core.internal.io.dav.DAVRepository.getLatestRevision(DAVRepository.java:179)
at org.tmatesoft.svn.core.internal.wc2.ng.SvnNgRepositoryAccess.getRevisionNumber(SvnNgRepositoryAccess.java:118)
at org.tmatesoft.svn.core.internal.wc2.SvnRepositoryAccess.getLocations(SvnRepositoryAccess.java:184)
at org.tmatesoft.svn.core.internal.wc2.ng.SvnNgRepositoryAccess.createRepositoryFor(SvnNgRepositoryAccess.java:45)
at org.tmatesoft.svn.core.internal.wc2.remote.SvnRemoteExport.run(SvnRemoteExport.java:55)
at org.tmatesoft.svn.core.internal.wc2.remote.SvnRemoteExport.run(SvnRemoteExport.java:40)
at org.tmatesoft.svn.core.internal.wc2.SvnOperationRunner.run(SvnOperationRunner.java:21)
at org.tmatesoft.svn.core.wc2.SvnOperationFactory.run(SvnOperationFactory.java:1235)
at org.tmatesoft.svn.core.wc2.SvnOperation.run(SvnOperation.java:294)
at org.tmatesoft.svn.core.wc.SVNUpdateClient.doExport(SVNUpdateClient.java:897)
at tools.SVNUtil.exportFromSVN(SVNUtil.java:83)
at tools.SVNUtilTest.testExportFromSVN(SVNUtilTest.java:45)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:47)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:44)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:271)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:70)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:238)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:63)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:236)
at org.junit.runners.ParentRunner.access$(ParentRunner.java:53)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:229)
at org.junit.runners.ParentRunner.run(ParentRunner.java:309)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
Caused by: org.tmatesoft.svn.core.SVNAuthenticationException: svn: E171: Authentication required for ‘<http://ip:80>‘
at org.tmatesoft.svn.core.internal.wc.SVNErrorManager.authenticationFailed(SVNErrorManager.java:47)
at org.tmatesoft.svn.core.internal.wc.SVNErrorManager.authenticationFailed(SVNErrorManager.java:41)
at org.tmatesoft.svn.core.internal.wc.DefaultSVNAuthenticationManager.getNextAuthentication(DefaultSVNAuthenticationManager.java:218)
at org.tmatesoft.svn.core.internal.io.dav.http.HTTPConnection.request(HTTPConnection.java:696)
at org.tmatesoft.svn.core.internal.io.dav.http.HTTPConnection.request(HTTPConnection.java:375)
at org.tmatesoft.svn.core.internal.io.dav.http.HTTPConnection.request(HTTPConnection.java:363)
at org.tmatesoft.svn.core.internal.io.dav.DAVConnection.performHttpRequest(DAVConnection.java:710)
at org.tmatesoft.svn.core.internal.io.dav.DAVConnection.doPropfind(DAVConnection.java:131)
at org.tmatesoft.svn.core.internal.io.dav.DAVUtil.getProperties(DAVUtil.java:73)
at org.tmatesoft.svn.core.internal.io.dav.DAVUtil.getResourceProperties(DAVUtil.java:79)
at org.tmatesoft.svn.core.internal.io.dav.DAVUtil.getStartingProperties(DAVUtil.java:103)
at org.tmatesoft.svn.core.internal.io.dav.DAVUtil.findStartingProperties(DAVUtil.java:125)
... 37 more
解决办法: 使用自定义的ISVNAuthenticationProvider对象。 scene1:
setupLibrary();
SVNURL url = SVNURL.parseURIEncoded(this.svnUrl);
SVNRepository repository = SVNRepositoryFactory.create(url);
ISVNAuthenticationManager authManager = SVNWCUtil
.createDefaultAuthenticationManager(userName, password);
authManager.setAuthenticationProvider(new CustomSVNAuthenticationProvider(userName,password));
repository.setAuthenticationManager(authManager);
scene2:
setupLibrary();
SVNURL url = SVNURL.parseURIEncoded(svnUrl);
DefaultSVNOptions options = SVNWCUtil.createDefaultOptions(true);
ISVNAuthenticationManager authManager = SVNWCUtil.createDefaultAuthenticationManager(userName, password);
authManager.setAuthenticationProvider(new CustomSVNAuthenticationProvider(userName,password));
SVNClientManager clientManager = SVNClientManager.newInstance(options,authManager);
SVNUpdateClient updateClient = clientManager.getUpdateClient();
updateClient.setIgnoreExternals(false);
class CustomSVNAuthenticationProvider implements ISVNAuthenticationProvider{
private String userName;
private String password;
public CustomSVNAuthenticationProvider(String userName,String password) {
this.userName=userName;
this.password=password;
}
@Override
public SVNAuthentication requestClientAuthentication(String kind,
SVNURL url, String realm, SVNErrorMessage errorMessage,
SVNAuthentication previousAuth, boolean authMayBeStored) {
return new SVNPasswordAuthentication(userName,password, true, url, false);
}
@Override
public int acceptServerAuthentication(SVNURL url, String realm,
Object certificate, boolean resultMayBeStored) {
return 0;
}
}
package org.tmatesoft.svn.core;
/**
* This class contains enumeration that describes depth,
* that is used.
* The order of these depths is important: the higher the number,
* the deeper it descends. You can use it to compare two depths
* numerically to decide which goes deeper.
*
* @version 1.3
* @author TMate Software Ltd.
* @since 1.2
*/
public class SVNDepth implements Comparable {
/**
* Depth undetermined or ignored.
*/
public static final SVNDepth UNKNOWN = new SVNDepth(-2, "unknown");
/**
* Exclude (don‘t descend into) directory D.
*/
public static final SVNDepth EXCLUDE = new SVNDepth(-1, "exclude");
/**
* Just the named directory D, no entries. For instance, update will not pull in
* any files or subdirectories.
*/
public static final SVNDepth EMPTY = new SVNDepth(0, "empty");
/**
* D and its file children, but not subdirectories. For instance, updates will pull in any
* files, but not subdirectories.
*/
public static final SVNDepth FILES = new SVNDepth(1, "files");
/**
* D and its immediate children (D and its entries). Updates will pull in
* any files or subdirectories without any children.
*/
public static final SVNDepth IMMEDIATES = new SVNDepth(2, "immediates");
/**
* D and all descendants (full recursion from D). For instance, updates will pull
in any files or subdirectories recursively.
*/
public static final SVNDepth INFINITY = new SVNDepth(3, "infinity");
demo:
package svn;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.OutputStream;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.tmatesoft.svn.core.SVNDepth;
import org.tmatesoft.svn.core.SVNException;
import org.tmatesoft.svn.core.SVNNodeKind;
import org.tmatesoft.svn.core.SVNProperties;
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.internal.io.fs.FSRepositoryFactory;
import org.tmatesoft.svn.core.internal.io.svn.SVNRepositoryFactoryImpl;
import org.tmatesoft.svn.core.internal.wc.DefaultSVNOptions;
import org.tmatesoft.svn.core.io.SVNRepository;
import org.tmatesoft.svn.core.io.SVNRepositoryFactory;
import org.tmatesoft.svn.core.wc.SVNClientManager;
import org.tmatesoft.svn.core.wc.SVNRevision;
import org.tmatesoft.svn.core.wc.SVNUpdateClient;
import org.tmatesoft.svn.core.wc.SVNWCUtil;
public class SVNUtil {
private static final Logger LOGGER=LoggerFactory.getLogger(SVNUtil.class);
private String svnUrl;
private String filePath;
private String userName;
private String password;
private File localFile;
private final int latest_revision=-1;
public SVNUtil(String svnUrl,String userName,String password,File file) {
this(userName,password,file);
this.svnUrl=svnUrl;
}
public SVNUtil(String userName,String password,File localFile) {
this.userName=userName;
this.password=password;
this.localFile=localFile;
}
public SVNUtil(String url, String filePath, String userName,
String password, File localFile) {
this(url, userName, password,localFile);
this.filePath=filePath;
}
public void checkOutFromSVN() throws SVNException {
System.setProperty("javax.net.debug", "all");
System.setProperty("svnkit.http.sslProtocols", "SSLv3");
setupLibrary();
SVNURL url = SVNURL.parseURIEncoded(this.svnUrl);
DefaultSVNOptions options = SVNWCUtil.createDefaultOptions(true);
SVNClientManager clientManager = SVNClientManager.newInstance(options,
userName, password);
SVNUpdateClient updateClient = clientManager.getUpdateClient();
updateClient.setIgnoreExternals(false);
long workVersion = updateClient.doCheckout(url, this.localFile,
SVNRevision.HEAD, SVNRevision.HEAD, SVNDepth.FILES, false);
LOGGER.info("Current version:{}", workVersion);
}
public void updateFromSVN() throws SVNException {
System.setProperty("svnkit.http.sslProtocols", "SSLv3");
setupLibrary();
DefaultSVNOptions options=SVNWCUtil.createDefaultOptions(true);
SVNClientManager clientManager=SVNClientManager.newInstance(options, userName, password);
SVNUpdateClient updateClient=clientManager.getUpdateClient();
updateClient.setIgnoreExternals(false);
long workVersion=updateClient.doUpdate(localFile, SVNRevision.HEAD,SVNDepth.INFINITY,false,false);
LOGGER.info("Current version:{}",workVersion);
}
public void getFileFromSVN() throws SVNException, FileNotFoundException {
System.setProperty("svnkit.http.sslProtocols", "SSLv3");
setupLibrary();
SVNRepository repository=SVNRepositoryFactory.create(SVNURL.parseURIEncoded(this.svnUrl));
ISVNAuthenticationManager authManager=SVNWCUtil.createDefaultAuthenticationManager(userName, password);
repository.setAuthenticationManager(authManager);
SVNNodeKind nodeKind=repository.checkPath(this.filePath,latest_revision);
if (nodeKind==SVNNodeKind.FILE) {
SVNProperties properties=new SVNProperties();
OutputStream contents=new FileOutputStream(this.localFile);
long workVersion=repository.getFile(this.filePath,latest_revision, properties, contents);
LOGGER.info("Current version:{}",workVersion);
}else {
LOGGER.error("Must be a file!current:{},url:{}",nodeKind,this.svnUrl);
}
}
/*
* Initializes the library to work with a repository via
* different protocols.
*/
private void setupLibrary() {
/*
* For using over http:// and https://
*/
DAVRepositoryFactory.setup();
/*
* For using over svn:// and svn+xxx://
*/
SVNRepositoryFactoryImpl.setup();
/*
* For using over file:///
*/
FSRepositoryFactory.setup();
}
}
Supported Protocols | Factory to setup |
svn://, svn+xxx:// | SVNRepositoryFactoryImpl (org.tmatesoft.svn.core.internal.io.svn) |
http://, https:// | DAVRepositoryFactory (org.tmatesoft.svn.core.internal.io.dav) |
file:/// (FSFS only) | FSRepositoryFactory (org.tmatesoft.svn.core.internal.io.fs) |
Also SVNRepositoryFactory may be used to create local FSFS-type repositories.
http://www.svnkit.com/kb/javadoc/org/tmatesoft/svn/core/io/SVNRepositoryFactory.html
package svnkit;
import java.io.File;
import org.tmatesoft.svn.core.SVNDepth;
import org.tmatesoft.svn.core.SVNException;
import org.tmatesoft.svn.core.SVNURL;
import org.tmatesoft.svn.core.internal.io.dav.DAVRepositoryFactory;
import org.tmatesoft.svn.core.internal.wc.DefaultSVNOptions;
import org.tmatesoft.svn.core.wc.ISVNOptions;
import org.tmatesoft.svn.core.wc.SVNClientManager;
import org.tmatesoft.svn.core.wc.SVNRevision;
import org.tmatesoft.svn.core.wc.SVNUpdateClient;
import org.tmatesoft.svn.core.wc.SVNWCUtil;
public class CheckOut {
// 声明SVN客户端管理类
private static SVNClientManager ourClientManager;
public static void main(String[] args) throws Exception {
// 初始化支持svn://协议的库。 必须先执行此操作。
DAVRepositoryFactory.setup();// 对于使用http://和https://
// SVNRepositoryFactoryImpl.setup();//对于使用svn:/ /和svn+xxx:/ /
// FSRepositoryFactory.setup();//对于使用file://
// 相关变量赋值
SVNURL repositoryURL = null;
try {
String url = "svn://localhost/project";
url = "https://127.0.0.1/svn/test/branch_fortest";
repositoryURL = SVNURL.parseURIEncoded(url);
} catch (SVNException e) {
//
System.out.println("无法连接");
}
String name = "admin";
String password = "admin";
String workPath = "svnkit";
ISVNOptions options = SVNWCUtil.createDefaultOptions(true);
// 实例化客户端管理类
ourClientManager = SVNClientManager.newInstance(
(DefaultSVNOptions) options, name, password);
// 要把版本库的内容check out到的目录
// FIle wcDir = new File("d:/test")
File wcDir = new File(workPath);
// 通过客户端管理类获得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.FILES, false);
System.out.println("把版本:" + workingVersion + " check out 到目录:" + wcDir+ "中。");
}
}
http://blog.csdn.net/luochen_50/article/details/7556629
报错:
org.tmatesoft.svn.core.SVNException: svn: E175002: Connection has been shutdown: javax.net.ssl.SSLException: Received fatal alert: bad_record_mac svn: E175002: OPTIONS request failed on ‘/svn/test/test‘ at org.tmatesoft.svn.core.internal.wc.SVNErrorManager.error(SVNErrorManager.java:106) at org.tmatesoft.svn.core.internal.wc.SVNErrorManager.error(SVNErrorManager.java:90) at org.tmatesoft.svn.core.internal.io.dav.http.HTTPConnection.request(HTTPConnection.java:775) at org.tmatesoft.svn.core.internal.io.dav.http.HTTPConnection.request(HTTPConnection.java:375) at org.tmatesoft.svn.core.internal.io.dav.http.HTTPConnection.request(HTTPConnection.java:363) at org.tmatesoft.svn.core.internal.io.dav.DAVConnection.performHttpRequest(DAVConnection.java:710) at org.tmatesoft.svn.core.internal.io.dav.DAVConnection.exchangeCapabilities(DAVConnection.java:627) at org.tmatesoft.svn.core.internal.io.dav.DAVConnection.open(DAVConnection.java:102) at org.tmatesoft.svn.core.internal.io.dav.DAVRepository.openConnection(DAVRepository.java:1032) at org.tmatesoft.svn.core.internal.io.dav.DAVRepository.getLatestRevision(DAVRepository.java:175) at org.tmatesoft.svn.core.internal.wc2.ng.SvnNgRepositoryAccess.getRevisionNumber(SvnNgRepositoryAccess.java:118) at org.tmatesoft.svn.core.internal.wc2.SvnRepositoryAccess.getLocations(SvnRepositoryAccess.java:184) at org.tmatesoft.svn.core.internal.wc2.ng.SvnNgRepositoryAccess.createRepositoryFor(SvnNgRepositoryAccess.java:45) at org.tmatesoft.svn.core.internal.wc2.ng.SvnNgAbstractUpdate.checkout(SvnNgAbstractUpdate.java:809) at org.tmatesoft.svn.core.internal.wc2.ng.SvnNgCheckout.run(SvnNgCheckout.java:26) at org.tmatesoft.svn.core.internal.wc2.ng.SvnNgCheckout.run(SvnNgCheckout.java:11) at org.tmatesoft.svn.core.internal.wc2.ng.SvnNgOperationRunner.run(SvnNgOperationRunner.java:20) at org.tmatesoft.svn.core.internal.wc2.SvnOperationRunner.run(SvnOperationRunner.java:21) at org.tmatesoft.svn.core.wc2.SvnOperationFactory.run(SvnOperationFactory.java:1235) at org.tmatesoft.svn.core.wc2.SvnOperation.run(SvnOperation.java:294) at org.tmatesoft.svn.core.wc.SVNUpdateClient.doCheckout(SVNUpdateClient.java:) at com.zte.ums.switchplat.tools.SVNUtil.process(SVNUtil.java:38) at com.zte.ums.switchplat.tools.SVNUtilTest.testProcess(SVNUtilTest.java:19) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) at java.lang.reflect.Method.invoke(Unknown Source) at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:47) at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12) at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:44) at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17) at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:271) at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:70) at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50) at org.junit.runners.ParentRunner$3.run(ParentRunner.java:238) at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:63) at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:236) at org.junit.runners.ParentRunner.access$(ParentRunner.java:53) at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:229) at org.junit.runners.ParentRunner.run(ParentRunner.java:309) at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50) at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197) Caused by: javax.net.ssl.SSLException: Connection has been shutdown: javax.net.ssl.SSLException: Received fatal alert: bad_record_mac at com.sun.net.ssl.internal.ssl.SSLSocketImpl.checkEOF(Unknown Source) at com.sun.net.ssl.internal.ssl.SSLSocketImpl.checkWrite(Unknown Source) at com.sun.net.ssl.internal.ssl.AppOutputStream.write(Unknown Source) at java.io.BufferedOutputStream.flushBuffer(Unknown Source) at java.io.BufferedOutputStream.flush(Unknown Source) at org.tmatesoft.svn.core.internal.io.dav.http.HTTPConnection.sendData(HTTPConnection.java:325) at org.tmatesoft.svn.core.internal.io.dav.http.HTTPRequest.dispatch(HTTPRequest.java:170) at org.tmatesoft.svn.core.internal.io.dav.http.HTTPConnection.request(HTTPConnection.java:474) ... 43 more Caused by: javax.net.ssl.SSLException: Received fatal alert: bad_record_mac at com.sun.net.ssl.internal.ssl.Alerts.getSSLException(Unknown Source) at com.sun.net.ssl.internal.ssl.Alerts.getSSLException(Unknown Source) at com.sun.net.ssl.internal.ssl.SSLSocketImpl.recvAlert(Unknown Source) at com.sun.net.ssl.internal.ssl.SSLSocketImpl.readRecord(Unknown Source) at com.sun.net.ssl.internal.ssl.SSLSocketImpl.performInitialHandshake(Unknown Source) at com.sun.net.ssl.internal.ssl.SSLSocketImpl.startHandshake(Unknown Source) at com.sun.net.ssl.internal.ssl.SSLSocketImpl.getSession(Unknown Source) at org.tmatesoft.svn.core.internal.io.dav.http.HTTPConnection.request(HTTPConnection.java:467) ... 43 more
解决办法: I would like to add that -Dsvnkit.http.sslProtocols="SSLv3" worked for me. However I don‘t understand why it works fine without using -Dsvnkit.http.sslProtocols="SSLv3" in 1.3.5 but I doesn‘t in 1.3.6/7. This suggests that this is rather SVNKIT issue than Java 5.
-Dsvnkit.http.sslProtocols="SSLv3" ... How and where to write this command? Can anybody help.
It is a system property. Usually one sets it when starts JVM (java), i.e in the command script: java -Dsvnkit.http.sslProtocols=SSLv3 -classpath a.jar:svnkit.jar:... mainClassName Or one may set it programatically at runtime: System.setProperty("svnkit.http.sslProtocols", "SSLv3");
http://issues.tmatesoft.com/issue/SVNKIT-176 http://stackoverflow.com/questions/8893871/eclipse-indigo-subversive-0-7-9-bad-record-mac
It is a hard to say what causing this. You need to find out by analyzing the logs, set the
System.setProperty("javax.net.debug", "all"); and check what is wrong.
A problem may be that server is not supporting TLS, which may be picked by implementation. To make sure that you always use the plain SSLv3 by setting the property:
System.setProperty("https.protocols", "SSLv3");//This doesn‘t work when suing svnkit.need use System.setProperty("svnkit.http.sslProtocols", "SSLv3"); Another cause may be the poor network, causing that occasionally some packets are broken but still have the correct checksum. In that case you may only retry the request.
http://stackoverflow.com/questions/22318729/javax-net-ssl-sslexception-received-fatal-alert-bad-record-mac
It might help if you include more of the debug output for the ssl connection leading up to the error which you included. I was seeing the same error and just solved it by including -Dhttps.protocols=SSLv3 -Dforce.http.jre.executor=true in my VM arguements ... so if you‘re lucky, that might work for you too.
http://stackoverflow.com/questions/9399810/javax-net-ssl-sslexception-received-fatal-alert-bad-record-mac-with-java-and-h
httpclient with certificate: http://stackoverflow.com/questions/995514/https-connection-android
“Received fatal alert: bad_record_mac” when deploying to sonatype:
As suggested here, I set this: MAVEN_OPTS="-Dhttps.protocols=SSLv3 -Dforce.http.jre.executor=true" http://stackoverflow.com/questions/12787657/received-fatal-alert-bad-record-mac-when-deploying-to-sonatype
added one properties line.
System.setProperty("https.protocols", "SSLv3,SSLv2Hello"); And now jsoup connection is able to connect properly using the correct HTTPS protocol. Note, don’t forget to include your SSL certificate as well when making connection. System.setProperty("javax.net.ssl.trustStore", certPath);
http://kennykee.com/350/javax-net-ssl-sslexception-received-fatal-alert-bad_record_mac-simple-solution/
import java.io.File;
import org.apache.log4j.Logger;
import org.tmatesoft.svn.core.SVNCommitInfo;
import org.tmatesoft.svn.core.SVNDepth;
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.internal.io.fs.FSRepositoryFactory;
import org.tmatesoft.svn.core.internal.io.svn.SVNRepositoryFactoryImpl;
import org.tmatesoft.svn.core.internal.wc.DefaultSVNOptions;
import org.tmatesoft.svn.core.io.SVNRepository;
import org.tmatesoft.svn.core.io.SVNRepositoryFactory;
import org.tmatesoft.svn.core.wc.SVNClientManager;
import org.tmatesoft.svn.core.wc.SVNRevision;
import org.tmatesoft.svn.core.wc.SVNStatus;
import org.tmatesoft.svn.core.wc.SVNUpdateClient;
import org.tmatesoft.svn.core.wc.SVNWCUtil;
/**
* SVNKit Utility
* @author lena yang
*
*/
public class SVNUtil {
private static Logger logger = Logger.getLogger(SVNUtil.class);
/**
* 通过不同的协议初始化版本库
*/
public static void setupLibrary() {
DAVRepositoryFactory.setup();// 对于使用http://和https://
SVNRepositoryFactoryImpl.setup();//对于使用svn:/ /和svn+xxx:/ /
FSRepositoryFactory.setup();//对于使用file://
}
/**
* 验证登录svn
*/
public static SVNClientManager authSvn(String svnRoot, String username,
String password) {
// 初始化版本库
setupLibrary();
// 创建库连接
SVNRepository repository = null;
try {
repository = SVNRepositoryFactory.create(SVNURL
.parseURIEncoded(svnRoot));
} catch (SVNException e) {
logger.error(e.getErrorMessage(), e);
return null;
}
// 身份验证
ISVNAuthenticationManager authManager = SVNWCUtil
.createDefaultAuthenticationManager(username, password);
// 创建身份验证管理器
repository.setAuthenticationManager(authManager);
DefaultSVNOptions options = SVNWCUtil.createDefaultOptions(true);
SVNClientManager clientManager = SVNClientManager.newInstance(options,
authManager);
return clientManager;
}
/**
* Make directory in svn repository
* @param clientManager
* @param url
* eg: http://svn.ambow.com/wlpt/bsp/trunk
* @param commitMessage
* @return
* @throws SVNException
*/
public static SVNCommitInfo makeDirectory(SVNClientManager clientManager,
SVNURL url, String commitMessage) {
try {
return clientManager.getCommitClient().doMkDir(
new SVNURL[] { url }, commitMessage);
} catch (SVNException e) {
logger.error(e.getErrorMessage(), e);
}
return null;
}
/**
* Imports an unversioned directory into a repository location denoted by a
* destination URL
* @param clientManager
* @param localPath
* a local unversioned directory or singal file that will be imported into a
* repository;
* @param dstURL
* a repository location where the local unversioned directory/file will be
* imported into
* @param commitMessage
* @param isRecursive 递归
* @return
*/
public static SVNCommitInfo importDirectory(SVNClientManager clientManager,
File localPath, SVNURL dstURL, String commitMessage,
boolean isRecursive) {
try {
return clientManager.getCommitClient().doImport(localPath, dstURL,
commitMessage, null, true, true,
SVNDepth.fromRecurse(isRecursive));
} catch (SVNException e) {
logger.error(e.getErrorMessage(), e);
}
return null;
}
/**
* Puts directories and files under version control
* @param clientManager
* SVNClientManager
* @param wcPath
* work copy path
*/
public static void addEntry(SVNClientManager clientManager, File wcPath) {
try {
clientManager.getWCClient().doAdd(new File[] { wcPath }, true,
false, false, SVNDepth.INFINITY, false, false,
true);
} catch (SVNException e) {
logger.error(e.getErrorMessage(), e);
}
}
/**
* Collects status information on a single Working Copy item
* @param clientManager
* @param wcPath
* local item‘s path
* @param remote
* true to check up the status of the item in the repository,
* that will tell if the local item is out-of-date (like ‘-u‘ option in the SVN client‘s
* ‘svn status‘ command), otherwise false
* @return
* @throws SVNException
*/
public static SVNStatus showStatus(SVNClientManager clientManager,
File wcPath, boolean remote) {
SVNStatus status = null;
try {
status = clientManager.getStatusClient().doStatus(wcPath, remote);
} catch (SVNException e) {
logger.error(e.getErrorMessage(), e);
}
return status;
}
/**
* Commit work copy‘s change to svn
* @param clientManager
* @param wcPath
* working copy paths which changes are to be committed
* @param keepLocks
* whether to unlock or not files in the repository
* @param commitMessage
* commit log message
* @return
* @throws SVNException
*/
public static SVNCommitInfo commit(SVNClientManager clientManager,
File wcPath, boolean keepLocks, String commitMessage) {
try {
return clientManager.getCommitClient().doCommit(
new File[] { wcPath }, keepLocks, commitMessage, null,
null, false, false, SVNDepth.INFINITY);
} catch (SVNException e) {
logger.error(e.getErrorMessage(), e);
}
return null;
}
/**
* Updates a working copy (brings changes from the repository into the working copy).
* @param clientManager
* @param wcPath
* working copy path
* @param updateToRevision
* revision to update to
* @param depth
* update的深度:目录、子目录、文件
* @return
* @throws SVNException
*/
public static long update(SVNClientManager clientManager, File wcPath,
SVNRevision updateToRevision, SVNDepth depth) {
SVNUpdateClient updateClient = clientManager.getUpdateClient();
/*
* sets externals not to be ignored during the update
*/
updateClient.setIgnoreExternals(false);
/*
* returns the number of the revision wcPath was updated to
*/
try {
return updateClient.doUpdate(wcPath, updateToRevision,depth, false, false);
} catch (SVNException e) {
logger.error(e.getErrorMessage(), e);
}
return 0;
}
/**
* recursively checks out a working copy from url into wcDir
* @param clientManager
* @param url
* a repository location from where a Working Copy will be checked out
* @param revision
* the desired revision of the Working Copy to be checked out
* @param destPath
* the local path where the Working Copy will be placed
* @param depth
* checkout的深度,目录、子目录、文件
* @return
* @throws SVNException
*/
public static long checkout(SVNClientManager clientManager, SVNURL url,
SVNRevision revision, File destPath, SVNDepth depth) {
SVNUpdateClient updateClient = clientManager.getUpdateClient();
/*
* sets externals not to be ignored during the checkout
*/
updateClient.setIgnoreExternals(false);
/*
* returns the number of the revision at which the working copy is
*/
try {
return updateClient.doCheckout(url, destPath, revision, revision,depth, false);
} catch (SVNException e) {
logger.error(e.getErrorMessage(), e);
}
return 0;
}
/**
* 确定path是否是一个工作空间
* @param path
* @return
*/
public static boolean isWorkingCopy(File path){
if(!path.exists()){
logger.warn("‘" + path + "‘ not exist!");
return false;
}