Search in sources :

Example 6 with SVNClientManager

use of org.tmatesoft.svn.core.wc.SVNClientManager 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 7 with SVNClientManager

use of org.tmatesoft.svn.core.wc.SVNClientManager 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)

Example 8 with SVNClientManager

use of org.tmatesoft.svn.core.wc.SVNClientManager in project sling by apache.

the class SvnChangeLogFinder method getChanges.

public List<String> getChanges(String first, String second) throws SVNException {
    SVNURL svnUrl = SVNURL.parseURIEncoded(SLING_SVN_REPO_BASE);
    List<String> changes = new ArrayList<>();
    SVNClientManager manager = SVNClientManager.newInstance();
    SVNRepository repo = manager.getRepositoryPool().createRepository(svnUrl, true);
    SVNRevision from = SVNRevision.create(getRevision(first, repo));
    SVNRevision to = SVNRevision.create(getRevision(second, repo));
    repo.log(new String[] { "tags/" + second }, from.getNumber(), to.getNumber(), false, false, (e) -> changes.add(e.getMessage()));
    return changes;
}
Also used : SVNURL(org.tmatesoft.svn.core.SVNURL) ArrayList(java.util.ArrayList) SVNRepository(org.tmatesoft.svn.core.io.SVNRepository) SVNRevision(org.tmatesoft.svn.core.wc.SVNRevision) SVNClientManager(org.tmatesoft.svn.core.wc.SVNClientManager)

Example 9 with SVNClientManager

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

the class SvnBlameCommandTest method checkout.

private File checkout(String scmUrl) throws Exception {
    ISVNOptions options = SVNWCUtil.createDefaultOptions(true);
    ISVNAuthenticationManager isvnAuthenticationManager = SVNWCUtil.createDefaultAuthenticationManager(null, null, (char[]) null, false);
    SVNClientManager svnClientManager = SVNClientManager.newInstance(options, isvnAuthenticationManager);
    File out = temp.newFolder();
    SVNUpdateClient updateClient = svnClientManager.getUpdateClient();
    SvnCheckout co = updateClient.getOperationsFactory().createCheckout();
    co.setUpdateLocksOnDemand(updateClient.isUpdateLocksOnDemand());
    co.setSource(SvnTarget.fromURL(SVNURL.parseURIEncoded(scmUrl), SVNRevision.HEAD));
    co.setSingleTarget(SvnTarget.fromFile(out));
    co.setRevision(SVNRevision.HEAD);
    co.setDepth(SVNDepth.INFINITY);
    co.setAllowUnversionedObstructions(false);
    co.setIgnoreExternals(updateClient.isIgnoreExternals());
    co.setExternalsHandler(SvnCodec.externalsHandler(updateClient.getExternalsHandler()));
    co.setTargetWorkingCopyFormat(wcVersion);
    co.run();
    return out;
}
Also used : SVNUpdateClient(org.tmatesoft.svn.core.wc.SVNUpdateClient) ISVNOptions(org.tmatesoft.svn.core.wc.ISVNOptions) ISVNAuthenticationManager(org.tmatesoft.svn.core.auth.ISVNAuthenticationManager) SvnCheckout(org.tmatesoft.svn.core.wc2.SvnCheckout) 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)

Example 10 with SVNClientManager

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

the class SvnScmProviderTest method computeChangedPaths_should_not_crash_when_getRepositoryRootURL_getPath_is_empty.

@Test
public void computeChangedPaths_should_not_crash_when_getRepositoryRootURL_getPath_is_empty() throws SVNException {
    // verify assumptions about what SVNKit returns as svn root path for urls like http://svnserver/
    assertThat(SVNURL.parseURIEncoded("http://svnserver/").getPath()).isEmpty();
    assertThat(SVNURL.parseURIEncoded("http://svnserver").getPath()).isEmpty();
    SVNClientManager svnClientManagerMock = mock(SVNClientManager.class);
    SVNWCClient svnwcClientMock = mock(SVNWCClient.class);
    when(svnClientManagerMock.getWCClient()).thenReturn(svnwcClientMock);
    SVNLogClient svnLogClient = mock(SVNLogClient.class);
    when(svnClientManagerMock.getLogClient()).thenReturn(svnLogClient);
    SVNInfo svnInfoMock = mock(SVNInfo.class);
    when(svnwcClientMock.doInfo(any(), any())).thenReturn(svnInfoMock);
    // Simulate repository root on /, SVNKIT then returns an repository root url WITHOUT / at the end.
    when(svnInfoMock.getRepositoryRootURL()).thenReturn(SVNURL.parseURIEncoded("http://svnserver"));
    when(svnInfoMock.getURL()).thenReturn(SVNURL.parseURIEncoded("http://svnserver/myproject/trunk/"));
    assertThat(SvnScmProvider.computeChangedPaths(Paths.get("/"), svnClientManagerMock)).isEmpty();
}
Also used : SVNWCClient(org.tmatesoft.svn.core.wc.SVNWCClient) SVNInfo(org.tmatesoft.svn.core.wc.SVNInfo) SVNClientManager(org.tmatesoft.svn.core.wc.SVNClientManager) SVNLogClient(org.tmatesoft.svn.core.wc.SVNLogClient) Test(org.junit.Test)

Aggregations

SVNClientManager (org.tmatesoft.svn.core.wc.SVNClientManager)13 File (java.io.File)7 SVNLogClient (org.tmatesoft.svn.core.wc.SVNLogClient)5 SVNRevision (org.tmatesoft.svn.core.wc.SVNRevision)4 ZipFile (java.util.zip.ZipFile)3 Test (org.junit.Test)3 InputFile (org.sonar.api.batch.fs.InputFile)3 SVNException (org.tmatesoft.svn.core.SVNException)3 SVNURL (org.tmatesoft.svn.core.SVNURL)3 SVNInfo (org.tmatesoft.svn.core.wc.SVNInfo)3 IOException (java.io.IOException)2 MalformedURLException (java.net.MalformedURLException)2 URISyntaxException (java.net.URISyntaxException)2 CheckForNull (javax.annotation.CheckForNull)2 DefaultInputFile (org.sonar.api.batch.fs.internal.DefaultInputFile)2 BlameOutput (org.sonar.api.batch.scm.BlameCommand.BlameOutput)2 SVNDepth (org.tmatesoft.svn.core.SVNDepth)2 ISVNOptions (org.tmatesoft.svn.core.wc.ISVNOptions)2 SVNStatus (org.tmatesoft.svn.core.wc.SVNStatus)2 SVNStatusClient (org.tmatesoft.svn.core.wc.SVNStatusClient)2