首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 软件管理 > CVS SVN >

获取Svn mergeInfo小结

2013-07-09 
获取Svn mergeInfo总结方法一:利用svnkit的api进行获取,代码如下:public String getMergeInfo1(String svn

获取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();    }

热点排行