SvnKit 로 제출 기록 획득

4290 단어 svnkit
작업 상 JAVA 를 통 해 SVN 의 제출 기록 을 받 아야 하기 때문에 SVNKit 를 봤 는데,
다음은 코드 입 니 다. 백업 을 저장 합 니 다.
 
SvnKit 프로젝트 주소:http://svnkit.com/index.html
 
package com.svnkit;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Date;
import java.util.Iterator;
import java.util.List;
import java.util.Set;

import org.apache.log4j.Logger;
import org.junit.BeforeClass;
import org.junit.Test;
import org.tmatesoft.svn.core.ISVNLogEntryHandler;
import org.tmatesoft.svn.core.SVNException;
import org.tmatesoft.svn.core.SVNLogEntry;
import org.tmatesoft.svn.core.SVNLogEntryPath;
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 SVNUtilTest {
    private static String url = "  SVN  ";
    private static SVNRepository repository = null;

    @BeforeClass
    public static void setupLibrary() {
        DAVRepositoryFactory.setup();
        SVNRepositoryFactoryImpl.setup();
        FSRepositoryFactory.setup();
        try {
            repository = SVNRepositoryFactory.create(SVNURL.parseURIEncoded(url));
        }
        catch (SVNException e) {
            logger.error(e.getErrorMessage(), e);
        }
        //     
        ISVNAuthenticationManager authManager = SVNWCUtil.createDefaultAuthenticationManager("SVN   ","SVN  ");
        repository.setAuthenticationManager(authManager);
    }

    @Test
    public void filterCommitHistoryTest() throws Exception {
        //     
        final SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
        final Date begin = format.parse("2014-02-13");
        final Date end = format.parse("2014-02-14");
        final String author = "";
        long startRevision = 0;
        long endRevision = -1;//        
        final List<String> history = new ArrayList<String>();
		//String[]           ,         
        repository.log(new String[]{""},
                       startRevision,
                       endRevision,
                       true,
                       true,
                       new ISVNLogEntryHandler() {
                           @Override
                           public void handleLogEntry(SVNLogEntry svnlogentry)
                                   throws SVNException {
				//          
                               if (svnlogentry.getDate().after(begin)
                                   && svnlogentry.getDate().before(end)) {
                                   //        
                                   if (!"".equals(author)) {
                                       if (author.equals(svnlogentry.getAuthor())) {
                                           fillResult(svnlogentry);
                                       }
                                   } else {
                                       fillResult(svnlogentry);
                                   }
                               }
                           }

                           public void fillResult(SVNLogEntry svnlogentry) {
                          //getChangedPaths        MAP key    ,value     
                               history.addAll(svnlogentry.getChangedPaths().keySet());
                           }
                       });
        for (String path : history) {
            System.out.println(path);
        }
    }
}

좋은 웹페이지 즐겨찾기