Search in sources :

Example 1 with SVNLogClient

use of org.tmatesoft.svn.core.wc.SVNLogClient in project Gargoyle by callakrsos.

the class SVNLog method logFileSystem.

/********************************
	 * 작성일 : 2016. 7. 13. 작성자 : KYJ
	 *
	 *
	 * @param path
	 * @param startRevision
	 * @param endDate
	 * @param exceptionHandler
	 * @return
	 ********************************/
public List<SVNLogEntry> logFileSystem(File[] path, long startRevision, Date endDate, Consumer<Exception> exceptionHandler) {
    SVNLogClient logClient = getSvnManager().getLogClient();
    List<SVNLogEntry> result = new ArrayList<>();
    try {
        ISVNLogEntryHandler handler = logEntry -> {
            LOGGER.debug("path :: {}  rivision :: {} date :: {} author :: {} message :: {} ", path, logEntry.getRevision(), logEntry.getDate(), logEntry.getAuthor(), logEntry.getMessage());
            result.add(logEntry);
        };
        doLog(path, startRevision, endDate, logClient, handler);
    } catch (SVNException e) {
        LOGGER.error(ValueUtil.toString(e));
        if (exceptionHandler != null)
            exceptionHandler.accept(e);
    }
    return result;
}
Also used : ILogCommand(com.kyj.scm.manager.core.commons.ILogCommand) Properties(java.util.Properties) Logger(org.slf4j.Logger) URLDecoder(java.net.URLDecoder) SVNException(org.tmatesoft.svn.core.SVNException) Date(java.util.Date) Collection(java.util.Collection) LoggerFactory(org.slf4j.LoggerFactory) ValueUtil(com.kyj.fx.voeditor.visual.util.ValueUtil) File(java.io.File) ArrayList(java.util.ArrayList) Consumer(java.util.function.Consumer) SVNLogClient(org.tmatesoft.svn.core.wc.SVNLogClient) List(java.util.List) SVNRepository(org.tmatesoft.svn.core.io.SVNRepository) SVNLogEntry(org.tmatesoft.svn.core.SVNLogEntry) SVNRevision(org.tmatesoft.svn.core.wc.SVNRevision) ISVNLogEntryHandler(org.tmatesoft.svn.core.ISVNLogEntryHandler) SVNLogEntry(org.tmatesoft.svn.core.SVNLogEntry) ArrayList(java.util.ArrayList) ISVNLogEntryHandler(org.tmatesoft.svn.core.ISVNLogEntryHandler) SVNException(org.tmatesoft.svn.core.SVNException) SVNLogClient(org.tmatesoft.svn.core.wc.SVNLogClient)

Example 2 with SVNLogClient

use of org.tmatesoft.svn.core.wc.SVNLogClient in project Gargoyle by callakrsos.

the class SVNLog method log.

/********************************
	 * 작성일 : 2016. 5. 5. 작성자 : KYJ
	 *
	 * 이력정보 조회
	 *
	 * @param path
	 *            상대경로
	 * @param revision
	 *            리비젼번호
	 * @param exceptionHandler
	 *            에러발생시 처리할 핸들 정의
	 * @return
	 ********************************/
public List<SVNLogEntry> log(String path, String revision, Consumer<Exception> exceptionHandler) {
    SVNLogClient logClient = getSvnManager().getLogClient();
    List<SVNLogEntry> result = new ArrayList<>();
    try {
        ISVNLogEntryHandler handler = logEntry -> {
            LOGGER.debug("rivision :: {} date :: {} author :: {} message :: {} ", logEntry.getRevision(), logEntry.getDate(), logEntry.getAuthor(), logEntry.getMessage());
            result.add(logEntry);
        };
        String _path = path;
        try {
            _path = URLDecoder.decode(_path, "UTF-8");
        } catch (Exception e) {
            e.printStackTrace();
        }
        logClient.doLog(getSvnURL(), new String[] { _path }, SVNRevision.create(Long.parseLong(revision)), SVNRevision.create(Long.parseLong(revision) == -1 ? 0 : Long.parseLong(revision)), SVNRevision.HEAD, true, false, 100L, handler);
    } catch (SVNException e) {
        if (exceptionHandler != null)
            exceptionHandler.accept(e);
        else
            LOGGER.error(ValueUtil.toString(e));
    }
    return result;
}
Also used : ILogCommand(com.kyj.scm.manager.core.commons.ILogCommand) Properties(java.util.Properties) Logger(org.slf4j.Logger) URLDecoder(java.net.URLDecoder) SVNException(org.tmatesoft.svn.core.SVNException) Date(java.util.Date) Collection(java.util.Collection) LoggerFactory(org.slf4j.LoggerFactory) ValueUtil(com.kyj.fx.voeditor.visual.util.ValueUtil) File(java.io.File) ArrayList(java.util.ArrayList) Consumer(java.util.function.Consumer) SVNLogClient(org.tmatesoft.svn.core.wc.SVNLogClient) List(java.util.List) SVNRepository(org.tmatesoft.svn.core.io.SVNRepository) SVNLogEntry(org.tmatesoft.svn.core.SVNLogEntry) SVNRevision(org.tmatesoft.svn.core.wc.SVNRevision) ISVNLogEntryHandler(org.tmatesoft.svn.core.ISVNLogEntryHandler) SVNLogEntry(org.tmatesoft.svn.core.SVNLogEntry) ArrayList(java.util.ArrayList) ISVNLogEntryHandler(org.tmatesoft.svn.core.ISVNLogEntryHandler) SVNException(org.tmatesoft.svn.core.SVNException) SVNLogClient(org.tmatesoft.svn.core.wc.SVNLogClient) SVNException(org.tmatesoft.svn.core.SVNException)

Example 3 with SVNLogClient

use of org.tmatesoft.svn.core.wc.SVNLogClient in project sonarqube by SonarSource.

the class SvnScmProvider method branchChangedLines.

@CheckForNull
@Override
public Map<Path, Set<Integer>> branchChangedLines(String targetBranchName, Path rootBaseDir, Set<Path> changedFiles) {
    SVNClientManager clientManager = null;
    try {
        clientManager = newSvnClientManager(configuration);
        // find reference revision number: the copy point
        SVNLogClient svnLogClient = clientManager.getLogClient();
        long[] revisionCounter = { 0 };
        svnLogClient.doLog(new File[] { rootBaseDir.toFile() }, null, null, null, true, true, 0, svnLogEntry -> revisionCounter[0] = svnLogEntry.getRevision());
        long startRev = revisionCounter[0];
        SVNDiffClient svnDiffClient = clientManager.getDiffClient();
        File path = rootBaseDir.toFile();
        ChangedLinesComputer computer = newChangedLinesComputer(rootBaseDir, changedFiles);
        svnDiffClient.doDiff(path, SVNRevision.create(startRev), path, SVNRevision.WORKING, SVNDepth.INFINITY, false, computer.receiver(), null);
        return computer.changedLines();
    } catch (Exception e) {
        LOG.warn("Failed to get changed lines from Subversion", e);
    } finally {
        if (clientManager != null) {
            try {
                clientManager.dispose();
            } catch (Exception e) {
                LOG.warn("Unable to dispose SVN ClientManager", e);
            }
        }
    }
    return null;
}
Also used : SVNDiffClient(org.tmatesoft.svn.core.wc.SVNDiffClient) File(java.io.File) SVNClientManager(org.tmatesoft.svn.core.wc.SVNClientManager) SVNLogClient(org.tmatesoft.svn.core.wc.SVNLogClient) URISyntaxException(java.net.URISyntaxException) MalformedURLException(java.net.MalformedURLException) SVNException(org.tmatesoft.svn.core.SVNException) CheckForNull(javax.annotation.CheckForNull)

Example 4 with SVNLogClient

use of org.tmatesoft.svn.core.wc.SVNLogClient in project sonarqube by SonarSource.

the class SvnBlameCommandTest method blame_givenCredentialsSupplied_doNotlogWarning.

@Test
public void blame_givenCredentialsSupplied_doNotlogWarning() throws Exception {
    BlameOutput output = mock(BlameOutput.class);
    InputFile inputFile = mock(InputFile.class);
    SvnConfiguration properties = mock(SvnConfiguration.class);
    SvnBlameCommand svnBlameCommand = new SvnBlameCommand(properties);
    SVNClientManager clientManager = mock(SVNClientManager.class);
    SVNLogClient logClient = mock(SVNLogClient.class);
    SVNStatusClient statusClient = mock(SVNStatusClient.class);
    SVNStatus status = mock(SVNStatus.class);
    when(properties.isEmpty()).thenReturn(true);
    when(clientManager.getLogClient()).thenReturn(logClient);
    when(clientManager.getStatusClient()).thenReturn(statusClient);
    when(status.getContentsStatus()).thenReturn(SVNStatusType.STATUS_NORMAL);
    when(inputFile.file()).thenReturn(mock(File.class));
    when(statusClient.doStatus(any(File.class), anyBoolean())).thenReturn(status);
    doThrow(SVNAuthenticationException.class).when(logClient).doAnnotate(any(File.class), any(SVNRevision.class), any(SVNRevision.class), any(SVNRevision.class), anyBoolean(), anyBoolean(), any(AnnotationHandler.class), eq(null));
    assertThrows(IllegalStateException.class, () -> {
        svnBlameCommand.blame(clientManager, inputFile, output);
        assertThat(logTester.logs(LoggerLevel.WARN)).isEmpty();
    });
}
Also used : SVNStatus(org.tmatesoft.svn.core.wc.SVNStatus) SVNStatusClient(org.tmatesoft.svn.core.wc.SVNStatusClient) BlameOutput(org.sonar.api.batch.scm.BlameCommand.BlameOutput) SVNRevision(org.tmatesoft.svn.core.wc.SVNRevision) ZipFile(java.util.zip.ZipFile) InputFile(org.sonar.api.batch.fs.InputFile) DefaultInputFile(org.sonar.api.batch.fs.internal.DefaultInputFile) File(java.io.File) SVNClientManager(org.tmatesoft.svn.core.wc.SVNClientManager) SVNLogClient(org.tmatesoft.svn.core.wc.SVNLogClient) InputFile(org.sonar.api.batch.fs.InputFile) DefaultInputFile(org.sonar.api.batch.fs.internal.DefaultInputFile) Test(org.junit.Test)

Example 5 with SVNLogClient

use of org.tmatesoft.svn.core.wc.SVNLogClient in project sonarqube by SonarSource.

the class SvnBlameCommandTest method blame_givenNoCredentials_logWarning.

@Test
public void blame_givenNoCredentials_logWarning() throws Exception {
    BlameOutput output = mock(BlameOutput.class);
    InputFile inputFile = mock(InputFile.class);
    SvnBlameCommand svnBlameCommand = newSvnBlameCommand();
    SVNClientManager clientManager = mock(SVNClientManager.class);
    SVNLogClient logClient = mock(SVNLogClient.class);
    SVNStatusClient statusClient = mock(SVNStatusClient.class);
    SVNStatus status = mock(SVNStatus.class);
    when(clientManager.getLogClient()).thenReturn(logClient);
    when(clientManager.getStatusClient()).thenReturn(statusClient);
    when(status.getContentsStatus()).thenReturn(SVNStatusType.STATUS_NORMAL);
    when(inputFile.file()).thenReturn(mock(File.class));
    when(statusClient.doStatus(any(File.class), anyBoolean())).thenReturn(status);
    doThrow(SVNAuthenticationException.class).when(logClient).doAnnotate(any(File.class), any(SVNRevision.class), any(SVNRevision.class), any(SVNRevision.class), anyBoolean(), anyBoolean(), any(AnnotationHandler.class), eq(null));
    assertThrows(IllegalStateException.class, () -> {
        svnBlameCommand.blame(clientManager, inputFile, output);
        assertThat(logTester.logs(LoggerLevel.WARN)).contains("Authentication to SVN server is required but no " + "authentication data was passed to the scanner");
    });
}
Also used : SVNStatus(org.tmatesoft.svn.core.wc.SVNStatus) SVNStatusClient(org.tmatesoft.svn.core.wc.SVNStatusClient) BlameOutput(org.sonar.api.batch.scm.BlameCommand.BlameOutput) SVNRevision(org.tmatesoft.svn.core.wc.SVNRevision) ZipFile(java.util.zip.ZipFile) InputFile(org.sonar.api.batch.fs.InputFile) DefaultInputFile(org.sonar.api.batch.fs.internal.DefaultInputFile) File(java.io.File) SVNClientManager(org.tmatesoft.svn.core.wc.SVNClientManager) SVNLogClient(org.tmatesoft.svn.core.wc.SVNLogClient) InputFile(org.sonar.api.batch.fs.InputFile) DefaultInputFile(org.sonar.api.batch.fs.internal.DefaultInputFile) Test(org.junit.Test)

Aggregations

SVNLogClient (org.tmatesoft.svn.core.wc.SVNLogClient)11 File (java.io.File)7 SVNException (org.tmatesoft.svn.core.SVNException)7 SVNRevision (org.tmatesoft.svn.core.wc.SVNRevision)6 SVNClientManager (org.tmatesoft.svn.core.wc.SVNClientManager)5 ValueUtil (com.kyj.fx.voeditor.visual.util.ValueUtil)3 ILogCommand (com.kyj.scm.manager.core.commons.ILogCommand)3 URLDecoder (java.net.URLDecoder)3 ArrayList (java.util.ArrayList)3 Collection (java.util.Collection)3 Date (java.util.Date)3 List (java.util.List)3 Properties (java.util.Properties)3 Consumer (java.util.function.Consumer)3 Test (org.junit.Test)3 Logger (org.slf4j.Logger)3 LoggerFactory (org.slf4j.LoggerFactory)3 ISVNLogEntryHandler (org.tmatesoft.svn.core.ISVNLogEntryHandler)3 MalformedURLException (java.net.MalformedURLException)2 URISyntaxException (java.net.URISyntaxException)2