svnkit:通过java操作svn

来源:互联网 发布:网络教育当兵可以吗? 编辑:程序博客网 时间:2024/06/07 01:06

官方文档:http://wiki.svnkit.com/Getting_Started_With_SVNKit

demo: 获取提交历史

public static List<String> getLogs() throws SVNException{        /*         * 对版本库进行初始化操作,使用https或http访问svn时,执行DAVRepositoryFactory.setup(); 对于通过使用svn:// 和 svn+xxx://         * 访问svn时,执行SVNRepositoryFactoryImpl.setup(); 对于通过file:/// 访问svn的情况,执行 FSRepositoryFactory.setup();         */        String url = "http://10.27.164.97/svn/imp/branches/imp_V1.0.5";        String name = "15050886";        String password = "sn9988&";        long startRevision = 0;        long endRevision = -1; // HEAD (the latest) revision        SVNURL svnurl = SVNURL.parseURIEncoded(url); // 某目录在svn的位置,获取目录对应的URL。即版本库对应的URL地址        DAVRepositoryFactory.setup(); // 初始化        ISVNOptions options = SVNWCUtil.createDefaultOptions(true); // 驱动选项        ISVNAuthenticationManager authManager = SVNWCUtil.createDefaultAuthenticationManager(name, password); // 提供认证        SVNRepository repos = SVNRepositoryFactory.create(svnurl);        repos.setAuthenticationManager(authManager); // 设置认证        Collection logEntries = null;        List<String> result = new ArrayList<String>();        logEntries = repos.log(new String[] { "" }, null, startRevision, endRevision, true, true);                for (Iterator entries = logEntries.iterator(); entries.hasNext();) {            SVNLogEntry logEntry = (SVNLogEntry) entries.next();            System.out.println("---------------------------------------------");            System.out.println("revision: " + logEntry.getRevision());            System.out.println("author: " + logEntry.getAuthor());            System.out.println("date: " + logEntry.getDate());            System.out.println("log message: " + logEntry.getMessage());            if (logEntry.getChangedPaths().size() > 0) {                System.out.println();                System.out.println("changed paths:");                Set changedPathsSet = logEntry.getChangedPaths().keySet();                for (Iterator changedPaths = changedPathsSet.iterator(); changedPaths.hasNext();) {                    SVNLogEntryPath entryPath = (SVNLogEntryPath) logEntry.getChangedPaths().get(changedPaths.next());                    System.out.println(" "                            + entryPath.getType()                            + " "                            + entryPath.getPath()                            + ((entryPath.getCopyPath() != null) ? " (from " + entryPath.getCopyPath() + " revision "                                    + entryPath.getCopyRevision() + ")" : ""));                    result.add(entryPath.getPath());                }            }        }        // 倒序        Collections.reverse(result);        return result;    }


0 0
原创粉丝点击