2012年10月13日土曜日

SVNKitでSvnDiffのサンプルコード

SVNKit(http://svnkit.com/)を利用してSVNDiffを実行してみた。
こんな感じで書けば実行できるようである。
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.UnsupportedEncodingException;
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.ISVNDiffStatusHandler;
import org.tmatesoft.svn.core.wc.SVNDiffClient;
import org.tmatesoft.svn.core.wc.SVNDiffStatus;
import org.tmatesoft.svn.core.wc.SVNLogClient;
import org.tmatesoft.svn.core.wc.SVNRevision;
import org.tmatesoft.svn.core.wc.SVNWCUtil;
public class SVNDiffSample {
 private static class DiffStatusHandler implements ISVNDiffStatusHandler{
 @Override
 public void handleDiffStatus(SVNDiffStatus arg0) throws SVNException {
  System.out.print(arg0.getPath());
  System.out.print(":");
  System.out.println(arg0.getModificationType());
 }
}
 private static final String SVN_USER="svn_user";
 private static final String SVN_PASS="svn_pass";
 public static void main(String[] args) throws SVNException, UnsupportedEncodingException {
  new SVNDiffSample().execute();
 }
 private void execute() throws SVNException, UnsupportedEncodingException {
  System.out.println("start");
  init();
  ISVNAuthenticationManager auth = SVNWCUtil.createDefaultAuthenticationManager(new        File("tmp"),SVN_USER,SVN_PASS,false);
  SVNDiffClient lc = new SVNDiffClient(auth,null);
  SVNURL targetUrl=SVNURL.parseURIEncoded("svn://urlstring");
  ISVNDiffStatusHandler handler = new DiffStatusHandler();
  //lc.doDiffStatus(targetUrl, SVNRevision.create(revNo), targetUrl,SVNRevision.create(revNo),   true, true, handler);
  ByteArrayOutputStream bao = new ByteArrayOutputStream();
  lc.doDiff(targetUrl, SVNRevision.create(revNo), targetUrl,SVNRevision.create(revNo),       SVNDepth.INFINITY, true, bao);
  System.out.println("SIZE:"+bao.size());
  System.out.println(bao.toString("MS932"));
 }
 private void init() {
  DAVRepositoryFactory.setup();
  SVNRepositoryFactoryImpl.setup();
  FSRepositoryFactory.setup();
 }
}

0 件のコメント: