2012年10月13日土曜日

SVNKitでShowLogするサンプル

SVNKit(http://svnkit.com/)を利用してSVNのログ表示を実行してみた。 こんな感じで書けばいけるようである。
import java.io.File;

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.wc.SVNLogClient;
import org.tmatesoft.svn.core.wc.SVNRevision;
import org.tmatesoft.svn.core.wc.SVNWCUtil;


public class SVNLogSample {
 private static class LogEntryHandler implements ISVNLogEntryHandler{

  @Override
  public void handleLogEntry(SVNLogEntry arg0) throws SVNException {
   System.out.print(arg0.getDate());
//   System.out.print(arg0.getChangedPaths());
   System.out.print(arg0.getAuthor());
   System.out.println(arg0.getMessage());
  }
  
 }
 private static final String SVN_USER="svnuser";
 private static final String SVN_PASS="svnuserpass";
 public static void main(String[] args) throws SVNException {
  new SVNLogSample().execute();
 }

 private void execute() throws SVNException {
  System.out.println("start");
  init();
  ISVNAuthenticationManager auth = SVNWCUtil.createDefaultAuthenticationManager(new File("tmp"),SVN_USER,SVN_PASS,false);
  SVNLogClient lc = new SVNLogClient(auth,null);
  SVNURL targetUrl=SVNURL.parseURIEncoded("svn://xxxxxxx");
  ISVNLogEntryHandler handler = new LogEntryHandler();
  String[] path = new String[]{"/path1","/path1"};
  lc.doLog(targetUrl,path,SVNRevision.HEAD, SVNRevision.HEAD, SVNRevision.create(0), true, true, 50, handler);
 }

 private void init() {
  DAVRepositoryFactory.setup();
  SVNRepositoryFactoryImpl.setup();
  FSRepositoryFactory.setup(); 
 }
}

0 件のコメント: