实现的功能:
- 获取一段时间内的仓库版本号
- 获取相应版本号的数据信息
- 根据作者的账户信息,获取更新记录
maven信息:
<!-- https://mvnrepository.com/artifact/org.tmatesoft.svnkit/svnkit -->
<dependency>
<groupId>org.tmatesoft.svnkit</groupId>
<artifactId>svnkit</artifactId>
<version>1.9.3</version>
</dependency>
<dependency>
<groupId>org.assertj</groupId>
<artifactId>assertj-core</artifactId>
</dependency>
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<SVNLogEntry> authorLogEntryList = Lists.newArrayList();
for (SVNLogEntry entry: logEntries) {
if (author.equals(entry.getAuthor())){
authorLogEntryList.add(entry);
}
}
// 将提交路径放入set中
Set<String> pathSet = Sets.newHashSet();
for (SVNLogEntry entry: authorLogEntryList) {
Map<String, SVNLogEntryPath> changedPaths = entry.getChangedPaths();
Set<String> 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<SVNLogEntry> logEntries = repository.log(new String[]{""}, null, startRevision+1, endRevision, true, true);
SVNLogEntry[] svnLogEntries = logEntries.toArray(new SVNLogEntry[0]);
return svnLogEntries;
}
}
转载自:
https://blog.csdn.net/weixin_41793807/article/details/82699305