java 获取svn_java获取svn中的数据

本文展示了如何使用Java结合SVNKit库,实现获取SVN仓库一段时间内的版本号、作者更新记录以及特定用户提交的路径信息。通过构造SVNUtil类并初始化认证、选项和仓库,调用listLogByTime方法获取指定日期范围的提交记录,并过滤出特定作者的记录。
摘要由CSDN通过智能技术生成

实现的功能:

获取一段时间内的仓库版本号

获取相应版本号的数据信息

根据作者的账户信息,获取更新记录

maven信息:

org.tmatesoft.svnkit

svnkit

1.9.3

org.assertj

assertj-core

java代码:

public class SVNUtil {

private Random random = new Random();

private static final Logger logger = LoggerFactory.getLogger(SVNUtil.class);

private String userName = "";

private String password = "";

private String url = "";

private ISVNAuthenticationManager authManager;

private DefaultSVNOptions options; // svn的参数

private SVNRepository repository; // 仓库

public static void main(String[] args) throws SVNException {

SVNUtil svnUtil = new SVNUtil("season", "123456", "svn://10.10.11.100/project7");

String author = "season";

ZonedDateTime zonedDateTime = LocalDate.of(2020, 3, 1).atStartOfDay(ZoneId.systemDefault());

Date oneMonthAgo = Date.from(zonedDateTime.toInstant());

SVNLogEntry[] logEntries = svnUtil.listLogByTime(oneMonthAgo, Calendar.getInstance().getTime());

// 获取某一用户提交的记录

List authorLogEntryList = Lists.newArrayList();

for (SVNLogEntry entry: logEntries) {

if (author.equals(entry.getAuthor())){

authorLogEntryList.add(entry);

}

}

// 将提交路径放入set中

Set pathSet = Sets.newHashSet();

for (SVNLogEntry entry: authorLogEntryList) {

Map changedPaths = entry.getChangedPaths();

Set keySet = changedPaths.keySet();

pathSet.addAll(keySet);

}

}

/**

* 构造方法

*/

public SVNUtil(String user, String password, String url) {

try {

this.userName = user;

this.password = password;

this.url = url;

init();

} catch (SVNException e) {

e.printStackTrace();

}

}

/**

* 初始化

*/

public void init() throws SVNException {

logger.info("开始加载");

authManager = SVNWCUtil.createDefaultAuthenticationManager(userName, password.toCharArray());

options = SVNWCUtil.createDefaultOptions(true);

options.setDiffCommand("-x -w");

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

repository.setAuthenticationManager(authManager);

logger.info("init completed");

}

/**

* 获取一段时间内,所有的commit记录

*/

public SVNLogEntry[] listLogByTime(Date start, Date end) throws SVNException {

long startRevision = repository.getDatedRevision(start); // 获取某一个时间点的版本号,如果用作开始时间,应该版本号+1,因为我们想要获取的是后一个版本

long endRevision = repository.getDatedRevision(end);

Collection logEntries = repository.log(new String[]{""}, null, startRevision+1, endRevision, true, true);

SVNLogEntry[] svnLogEntries = logEntries.toArray(new SVNLogEntry[0]);

return svnLogEntries;

}

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值