获取Svn mergeInfo总结

方法一:
利用svnkit的api进行获取,代码如下:
  public String getMergeInfo1(String svnURL) {
        Properties properties = System.getProperties();
        properties.setProperty("svnkit.http.methods", "Basic,Digest,NTLM");
        SVNRepository repository = null;
        try {
            repository = SVNRepositoryFactory.create(SVNURL.parseURIEncoded(svnURL));
            ISVNAuthenticationManager authManager = SVNWCUtil.createDefaultAuthenticationManager("username", "password");
            repository.setAuthenticationManager(authManager);
            long latestRevision = repository.getLatestRevision();
            Map<String, SVNMergeInfo> mergeInfo = repository.getMergeInfo(new String[] { "" }, latestRevision, SVNMergeInfoInheritance.EXPLICIT, false);
            return mergeInfo.toString();
        } catch (SVNException e) {
            e.printStackTrace();
        }
        return "";
    }


方法二:
利用svn命令的方式进行获取,这种方式在以startup.bat启动tomcat能正常运行,但以服务的形式启动tomcat时需要设置启动账号,否则取不到内容,代码如下:
public String getMergeInfo2(String svnURL) {

        StringBuilder sb = new StringBuilder();
        Process exec = null;
        BufferedReader br = null;
        try {
            exec = Runtime.getRuntime().exec("svn pg svn:mergeinfo " + svnURL);
            InputStream inputStream = exec.getInputStream();
            br = new BufferedReader(new InputStreamReader(inputStream));
            String str = null;
            while ((str = br.readLine()) != null) {
                sb.append(str);
                sb.append("\r\n");
            }
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            if (br != null) {
                try {
                    br.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
        return sb.toString();
    }

你可能感兴趣的:(SVN,mergeinfo)