标签:
package org.mo.svn.util; import java.util.ArrayList; import java.util.HashSet; import java.util.Iterator; import java.util.List; import java.util.Map; import org.tmatesoft.svn.core.ISVNLogEntryHandler; import org.tmatesoft.svn.core.SVNException; import org.tmatesoft.svn.core.SVNLogEntry; import org.tmatesoft.svn.core.SVNURL; import org.tmatesoft.svn.core.auth.ISVNAuthenticationManager; import org.tmatesoft.svn.core.internal.io.dav.DAVRepositoryFactory; import org.tmatesoft.svn.core.internal.io.fs.FSRepositoryFactory; import org.tmatesoft.svn.core.internal.io.svn.SVNRepositoryFactoryImpl; import org.tmatesoft.svn.core.io.SVNRepository; import org.tmatesoft.svn.core.io.SVNRepositoryFactory; import org.tmatesoft.svn.core.wc.SVNWCUtil; public class SVNutil { private static SVNRepository repository = null; static { DAVRepositoryFactory.setup(); SVNRepositoryFactoryImpl.setup(); FSRepositoryFactory.setup(); } public SVNutil(String url, String username, String password) { if (!url.trim().isEmpty() && !username.trim().isEmpty() && !password.trim().isEmpty()) { try { // 身份验证 ISVNAuthenticationManager authManager = SVNWCUtil.createDefaultAuthenticationManager(username, password); repository = SVNRepositoryFactory.create(SVNURL.parseURIEncoded(url)); repository.setAuthenticationManager(authManager); } catch (SVNException e) { throw new RuntimeException("repository 对象为空!"); } } } /** * 根据注释的信息查找内容 * * @param message * @return * @throws SVNException */ public List<String> getLogByMessage(final String message) throws SVNException { long startRevision = 0; long endRevision = -1;// 表示最后一个版本 // String[] 为过滤的文件路径前缀,为空表示不进行过滤 final List<String> history = new ArrayList<String>(); repository.log(new String[] {}, startRevision, endRevision, true, true, new ISVNLogEntryHandler() { @Override public void handleLogEntry(SVNLogEntry svnlogentry) throws SVNException { if (message.equals(svnlogentry.getMessage())) { // getChangedPaths为提交的历史记录MAP key为文件名,value为文件详情 Map changedPaths = svnlogentry.getChangedPaths(); // 追加了所有的数据。 history.addAll(changedPaths.keySet()); } } }); // 去除重复 HashSet h = new HashSet(history); history.clear(); history.addAll(h); //去除文件夹,非文件类型 List<String> newLogByMessage = new ArrayList<String>(); for (String removeNoPoint : history) { if (removeNoPoint.contains(".")) { newLogByMessage.add(removeNoPoint); } } return newLogByMessage; } }
用的jar :svnkit-1.3.5.jar
标签:
原文地址:http://my.oschina.net/moziqi/blog/397666