svnkit java_java操作svn的类svnkit简单使用

private static void checkOut(String desPath) {

SVNClientManager ourClientManager;

//初始化支持svn://协议的库。 必须先执行此操作。

SVNRepositoryFactoryImpl.setup();

//相关变量赋值

SVNURL repositoryURL = null;

try {

repositoryURL = SVNURL.parseURIEncoded(“http://xxxxx/svn/finance/项目文档/8_算法实验室/测试文档/兴业数金使用手册V0.1.docx”);

} catch (SVNException e) {

System.out.println(“初始化svn地址失败” + “http://xxxxx/svn/finance/项目文档/8_算法实验室/测试文档/兴业数金使用手册V0.1.docx”);

System.out.println(e.getMessage());

System.exit(1);

}

ISVNOptions options = SVNWCUtil.createDefaultOptions(true);

//实例化客户端管理类

ourClientManager = SVNClientManager.newInstance((DefaultSVNOptions) options, “svn账号”, “密码”);

//要把版本库的内容check out到的目录

File desFile = new File(desPath);

//通过客户端管理类获得updateClient类的实例。

SVNUpdateClient updateClient = ourClientManager.getUpdateClient();

updateClient.setIgnoreExternals(false);

try {

//返回工作版本号

long workingVersion = updateClient.doCheckout(repositoryURL, desFile, SVNRevision.HEAD, SVNRevision.HEAD, SVNDepth.INFINITY, true);

System.out.println(“把版本:” + workingVersion + " check out 到目录:" + desPath + “中”);

} catch (SVNException e) {

System.out.println(“检出代码出错” + e);

System.exit(1);

}

public static void checkOutByRevsion(String version, String url, String path, String name, String pwd) throws Exception {

SVNClientManager ourClientManager;

//初始化支持svn://协议的库。 必须先执行此操作。

DAVRepositoryFactory.setup();

//相关变量赋值

SVNURL repositoryURL;

//"http://112.124.45.101/svn/finance/产品/产品设计/测试/ceshi.doc"

repositoryURL = SVNURL.parseURIEncoded(url);

// String name = “xuanxuan.zhang”;

// String password = “zxx2017”;

ISVNOptions options = SVNWCUtil.createDefaultOptions(true);

//实例化客户端管理类

ourClientManager = SVNClientManager.newInstance((DefaultSVNOptions) options, name, pwd);

//要把版本库的内容check out到的目录"d:/test/"

String substring = url.substring(url.lastIndexOf("/"));

substring.replace("/", File.separator);

File delteDir = new File(path + substring);

if (delteDir.exists()) {

delteDir.delete();

}

path.replace("/", File.separator);

// path.replace("\", File.separator);

File wcDir = new File(path);

//通过客户端管理类获得updateClient类的实例。

SVNUpdateClient updateClient = ourClientManager.getUpdateClient();

/*

* sets externals not to be ignored during the checkout

*/

updateClient.setIgnoreExternals(false);

//执行check out 操作,返回工作副本的版本号。

long workingVersion = updateClient.doExport(repositoryURL, wcDir, SVNRevision.HEAD, SVNRevision.parse(version), “”, true, false);

System.out.println(“把版本:” + workingVersion + " check out 到目录:" + wcDir + “中。”);

}

/**

从svn 上获取提交文件记录

@param scriptDefine 此参数可以不用(这里用来取地址的)

@param userName svn 账号

@param pwd svn 密码

@return

@throws Exception

*/

public static List filterCommitHistoryTest(ScriptDefine scriptDefine, String userName, String pwd) throws Exception {

SVNRepository repository = null;

DAVRepositoryFactory.setup();

SVNRepositoryFactoryImpl.setup();

FSRepositoryFactory.setup();

String url = scriptDefine.getUrl() + “/” + scriptDefine.getName();//svn 上存放文件的地址 例如:http://112.124.45.101/svn/finance/产品/产品设计/测试

repository = SVNRepositoryFactory.create(SVNURL.parseURIEncoded(url));

// 身份验证

ISVNAuthenticationManager authManager = SVNWCUtil.createDefaultAuthenticationManager(userName, pwd);

repository.setAuthenticationManager(authManager);

// 过滤条件

final SimpleDateFormat format = new SimpleDateFormat(“yyyy-MM-dd hh:mm”);

long startRevision = 0;

long endRevision = -1;//表示最后一个版本

final List history = new ArrayList();

List list = new ArrayList<>();

//String[] 为过滤的文件路径前缀,为空表示不进行过滤

repository.log(new String[]{""},

startRevision,

endRevision,

true,

true,

new ISVNLogEntryHandler() {

@Override

public void handleLogEntry(SVNLogEntry svnlogentry) throws SVNException {

fillResult(svnlogentry);

}

void fillResult(SVNLogEntry svnlogentry) {

//getChangedPaths为提交的历史记录MAP key为文件名,value为文件详情

history.addAll(svnlogentry.getChangedPaths().keySet());

list.add(svnlogentry);

}

});

List versionlist = new ArrayList<>();

for (SVNLogEntry svnLogEntry : list) {

Map changedPaths = svnLogEntry.getChangedPaths();

/* + svnLogEntry.getAuthor() + “—时间:” + svnLogEntry.getDate() +"—消息:" + svnLogEntry.getMessage()+"–版本号:"+svnLogEntry.getRevision()*/

log.info(“文件:” + changedPaths.keySet() + " & 提交者" + svnLogEntry.getAuthor() + " & 提交时间:" + svnLogEntry.getDate() + " & 提交消息:" + svnLogEntry.getMessage() + " & 版本号:" + svnLogEntry.getRevision());

ScriptVersion scriptVersion = new ScriptVersion();

scriptVersion.setUpdateTime(svnLogEntry.getDate());

scriptVersion.setVersionNum(String.valueOf(svnLogEntry.getRevision()));

scriptVersion.setMsg(svnLogEntry.getMessage());

scriptVersion.setAuthor(svnLogEntry.getAuthor());

versionlist.add(scriptVersion);

}

Collections.sort(versionlist);

return versionlist;

}

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值