Get Svn mergeInfo summary

Method 1:
Use the api of svnkit to obtain, the code is as follows:
  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 "";
    }


Method 2:
Use the svn command to obtain, this method can run normally when tomcat is started with startup.bat, but the startup account needs to be set when starting tomcat in the form of a service, otherwise the content cannot be obtained, the code is as follows:
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();
    }

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326940937&siteId=291194637
svn