Java svnkit check update commit
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.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;
public class SVNKit {
private static Logger logger = Logger.getLogger(SVNKit.class);
/**
* 通过不同的协议初始化版本库
*/
public static void setupLibrary() {
DAVRepositoryFactory.setup();
SVNRepositoryFactoryImpl.setup();
FSRepositoryFactory.setup();
}
/**
* 验证登录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 }, false, false, false, SVNDepth.fromRecurse(true),
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.fromRecurse(true));
} 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;
}
try {
if (null == SVNWCUtil.getWorkingCopyRoot(path, false)) {
return false;
}
} catch (SVNException e) {
logger.error(e.getErrorMessage(), e);
}
return true;
}
}
Java svnkit check update commit的更多相关文章
- 【JAVA】FOR UPDATE 和 FOR UPDATE NOWAIT 区别 (转)
1.for update 和 for update nowait 的区别:首先一点,如果只是select 的话,Oracle是不会加任何锁的,也就是Oracle对 select 读到的数据不会有任何限 ...
- Effective Java 38 Check parameters for validity
For public methods, use the Javadoc @throws tag to document the exception that will be thrown if a r ...
- JAVA开发CHECK STYLE
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE module PUBLIC "-/ ...
- eclipse Java类 红色感叹号 commit失败
解决方法: 1.进入java类文件所在物理目录 (e:\workspace\myproject\...) 2. 删除多余的版本管理工具的文件或文件夹(如 .svn) 3. 刷新eclipse工程 4 ...
- mysql java jdbc 如何 update select
2019年8月6日17:28:07 sql 不知道怎么写,也没去查,因为需求可能中途需要修改值,有点麻烦 直接用jdbc实现. 查询出来的值,直接根据update条件更新,写在一个方法里 public ...
- java simple check whether a file or directory.
Ref: check whether a file or directory First, make sure the path exists by using: new File(path).ex ...
- java svnkit实现svn提交,更新等操作
官网:https://svnkit.com/ api:https://svnkit.com/javadoc/org/tmatesoft/svn/core/io/SVNRepository.html w ...
- java遇到 Check $M2_HOME 问题 解决-Dmaven.multiModuleProjectDirectory system property is not set. Check $M2_HOME environment variable and mvn script match.
步骤: 1.添加M2_HOME的环境变量 2.Preference->Java->Installed JREs->Edit 选择一个jdk 3.添加 -Dmaven.multiMod ...
- java maven项目update project默认编译器1.5问题解决
解决办法一:在项目中的pom.xml指定jdk版本,如下 <build> <plugins> <plugin> <groupId>org.apache. ...
随机推荐
- Oracle 同步
原文出处:http://www.cnblogs.com/zeromyth/archive/2009/08/19/1549661.html Oracle备份功能包括: 高级复制(Advanced Rep ...
- listener failed: zbx_tcp_listen() fatal error: unable to serve on any address [[-]:20050]
故障现象: 客户端报错:service zabbix-agent 启动后,端口没有被正常监听,服务端也无法正常连接 将客户端改为二进制文件安装也不能正常启动/usr/local/zabbix/sbin ...
- 错误代码 1045 Access denied for user 'root'@'localhost' (using password:YES)
1 前言 现象是用MySQL 5.7 Command Line Client可以使用root账号进入,但是其它navicat,phpsqladmin,mysql workbench,heidisql用 ...
- PYTHON-流程控制之if/while/for-练习
# 1 练习题## 简述编译型与解释型语言的区别,且分别列出你知道的哪些语言属于编译型,哪些属于解释型# 编译型:C, 谷歌翻译,一次翻译后结果后重复使用# 解释型:Python, 同声传译,边执行边 ...
- Slave SQL_THREAD如何重放Relay log
复制的介绍: 根据日志定义的模式不一样,可以分为:Statement(SBR)模式,Row(RBR)格式或者是MIXED格式,记录最小的单位是一个Event,binlog日志前4个字节是一个magic ...
- VS-常用的快捷键-总结
1: 快速添加引用 === Shift+Alt+F10; 也可用于实现抽象类 2: 直接添加属性 ===prop+Tab+Tab; 3: 根据字段添加属性 === Ctrl +r+e; 4: 格式化代 ...
- Java入门第一章知识点总结
-d是directory 目录的意思 cls:清楚doc里面的内容 ipconfig:显示网络配置信息 java -version:检查安装的jdk版本信息 是类型自动向上转换. 在输出时,根据当前 ...
- jdk提供的数组扩容方法:System.arraycopy
package chapter7; /* * jdk提供的扩容方法 * System.arraycopy */public class TestArrayjdk { public static voi ...
- 【转】角落的开发工具集之Vs(Visual Studio)2017插件推荐
因为最近录制视频的缘故,很多朋友都在QQ群留言,或者微信公众号私信我,问我一些工具和一些插件啊,怎么使用的啊?那么今天我忙里偷闲整理一下清单,然后在这里面公布出来. Visual Studio 201 ...
- python全栈开发day50-jquery之ajax、XmlHttpRquest
一.昨日内容回顾 1.jquery位置信息 width() ..,innetWidth() .outWidth() offset().top left scrollTop 2.事件流 DOM2级 (1 ...