学习笔记—SVNKit 开发

版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接: https://blog.csdn.net/huxiutao/article/details/90480662

最基本的介绍和用法可以参考以下几个链接:
SVNKit开发指南
https://blog.csdn.net/bfhx1314/article/details/17072517
http://www.cnblogs.com/powerwu/articles/9718325.html
https://www.open-open.com/doc/275db77be45c49ac85cc0e7602d0cb4d.html#_Toc229817613

在网上要下载该文档时,可能需要积分,这里我已经共享出来了(永久有效):
链接:https://pan.baidu.com/s/11BO_idkASYuqC450jPKrIA
提取码:sdve

该文档中有基本的用法和几个常用操作的示例。

当然最权威的学习资料:(官网)
https://svnkit.com/javadoc/index.html

SVNKit_FAQ:
https://wiki.svnkit.com/SVNKit_FAQ?highlight=%28Create%29%7C%28new%29%7C%28branch%29

我这里要补充说明的一点是,在我们实际项目中的需求是要求上传指定文件,就用到了:

SVNCommitClient:

此类提供了把改变提交到存储库上的一些操作。

  • doCommit(…)将修改从工作副本提交到存储库。
  • doImport(…)递归提交一个路径(本地目录)到存储库。
  • doDelete(…)从存储库中删除一个条目。
  • doMkDir(…)在存储库中创建一个目录。

SVNCommitClient的方法和SVN命令行客户端的命令的对应关系。

  • doCommit() == ‘svn commit’
  • doImport( ) == ‘svn import’
  • doDelete() == ‘svn delete URL’
  • doMkDir() == ‘svn mkdir URL’

开发指南中给出了一个例子,是将某个目录中的文件利用doImport()上传到版本库中,并没有说如何针对某一个文件进行上传。然后,我在官网上查了一下doImport方法,其实也是可以指定某个文件进行上传的:

    public SVNCommitInfo doImport(File path, SVNURL dstURL, String commitMessage, SVNProperties revisionProperties, boolean useGlobalIgnores, boolean ignoreUnknownNodeTypes, SVNDepth depth) throws SVNException {
        return this.doImport(path, dstURL, commitMessage, revisionProperties, useGlobalIgnores, ignoreUnknownNodeTypes, depth, true);
    }

    public SVNCommitInfo doImport(File path, SVNURL dstURL, String commitMessage, SVNProperties revisionProperties, boolean useGlobalIgnores, boolean ignoreUnknownNodeTypes, SVNDepth depth, boolean applyAutoProperties) throws SVNException {
        SvnImport svnImport = this.getOperationsFactory().createImport();
        svnImport.setCommitHandler(SvnCodec.commitHandler(this.getCommitHandler()));
        svnImport.setCommitMessage(commitMessage);
        svnImport.setRevisionProperties(revisionProperties);
        svnImport.addTarget(SvnTarget.fromURL(dstURL));
        svnImport.setSource(path);
        svnImport.setDepth(depth);
        svnImport.setUseGlobalIgnores(useGlobalIgnores);
        svnImport.setApplyAutoProperties(applyAutoProperties);
        return (SVNCommitInfo)svnImport.run();
    }

doImport(java.io.File path, SVNURL dstURL, java.lang.String commitMessage, SVNProperties revisionProperties, boolean useGlobalIgnores, boolean ignoreUnknownNodeTypes, SVNDepth depth)
Imports file or directory path into repository directory dstURL at HEAD revision.

这是官网的解释,是支持文件和目录的。

当然我所要讲的重点不在于以上这些用法,而在于利用doImport中上传指定文件时如何使用参数:SVNURL dstURL的问题:
刚开始以为dstURL直接定义为SVN上的目录即可,但是怎么都上传不成功,最后通过不断的尝试,才发现必须要将dstURL定义为“SVN上的目标路径/文件名”才行,例如:

SVNURL dstURL = SVNURL.parseURIEncoded("svnL//127.0.0.1:36900/test/config/MyConfig.txt");
// doImport的基本使用
import java.io.File;
import org.tmatesoft.svn.core.SVNCommitInfo;
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.svn.SVNRepositoryFactoryImpl;
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.SVNWCUtil;
/*此类执行的操作是把本地目录下的内容上传到版本库中。*/
public class DoImport {
	//声明SVN客户端管理类
	private static SVNClientManager ourClientManager;
	public static void main(String[] args) throws Exception {
		//初始化支持svn://协议的库。 必须先执行此操作。
		SVNRepositoryFactoryImpl.setup();
		//相关变量赋值
		SVNURL repositoryURL = null;
		try {
			repositoryURL = SVNURL.parseURIEncoded("svn://localhost/");
		} catch (SVNException e) {
			//
		}
		String name = "test";
		String password = "test";
		ISVNOptions options = SVNWCUtil.createDefaultOptions(true);
		//实例化客户端管理类
		ourClientManager = SVNClientManager.newInstance(
				(DefaultSVNOptions) options, name, password);
		//要把此目录中的内容导入到版本库
		File impDir = new File("e:/svntest/impDir");
		//执行导入操作
		SVNCommitInfo commitInfo=ourClientManager.getCommitClient().doImport(impDir, repositoryURL,
				"import operation!",null, false,false,SVNDepth.INFINITY);
			System.out.println(commitInfo.toString());
	}
}

另外SVN中文版好的链接:

https://www.kancloud.cn/i281151/svn#/catalog

https://www.runoob.com/svn/svn-tutorial.html

SVN版本管理详解(电子版)
链接:https://pan.baidu.com/s/1iQHf6wIdm4q6CdBywCQI2g
提取码:dh7d

推荐:关于SVN的实践指南,DevOps实战:版本管理实践指南
https://blog.csdn.net/liumiaocn/article/details/82286778

SVN下载官网:
http://subversion.apache.org/packages.html#
目前有五个版本:

  • CollabNet (supported and certified by CollabNet; requires
    registration)
    CollabNet是功能最强大的,因为svn的创始者就是CollabNet,不过这个版本因为功能最多,所以整个软件包含也是最臃肿的,安装包就有100多M,而且因为是运行在JAVA平台上的,要占用很大的内存资源;

  • SlikSVN (32- and 64-bit client MSI; maintained by Bert Huijben,
    SharpSvn project)
    SlikSVN和Win32Svn这两个基本一样,都只有svn的内核,没有界面,也就是使用的时候只能用命令行操作。这两者稍微有些区别,比如win32Svn了和apache的库文件,而slikSVN没有;

  • TortoiseSVN (optionally installs 32- and 64-bit command line tools
    and svnserve; supported and maintained by the TortoiseSVN project)
    客户端界面化的工具,俗称“小乌龟”。

  • VisualSVN (32- and 64-bit client and server; supported and maintained
    by VisualSVN)
    VisualSVN是最傻瓜似的svn,安装和配置都有图形界面,操作起来很方便,VisualSVN = Subversion + GUI管理界面;

  • WANdisco (32- and 64-bit client and server; supported and certified
    by WANdisco; requires registration)
    WANdisco用的很少。

猜你喜欢

转载自blog.csdn.net/huxiutao/article/details/90480662