首页 > 编程语言 > 详细

java获取svn中的数据

时间:2020-03-23 11:43:23      阅读:106      评论:0      收藏:0      [点我收藏+]

实现的功能:

  1. 获取一段时间内的仓库版本号
  2. 获取相应版本号的数据信息
  3. 根据作者的账户信息,获取更新记录

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); // 获取某一个时间点的版本号
        long endRevision = repository.getDatedRevision(end);
        
        Collection<SVNLogEntry> logEntries = repository.log(new String[]{""}, null, startRevision, endRevision, true, true);
        SVNLogEntry[] svnLogEntries = logEntries.toArray(new SVNLogEntry[0]);
        return svnLogEntries;
    }
}

转载自:
https://blog.csdn.net/weixin_41793807/article/details/82699305

java获取svn中的数据

原文:https://www.cnblogs.com/season-qd/p/12550944.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!