Search in sources :

Example 16 with SVNWCClient

use of org.tmatesoft.svn.core.wc.SVNWCClient in project MassBank-web by MassBank.

the class SVNClientWrapper method delete.

/*
	 * Schedules a Working Copy item for deletion.
	 */
public boolean delete(String filePath) throws SVNException {
    SVNWCClient client = this.manager.getWCClient();
    int cnt = 0;
    while (true) {
        try {
            client.doDelete(new File(filePath), true, false);
            return true;
        } catch (SVNException e) {
            SVNErrorCode errCode = e.getErrorMessage().getErrorCode();
            // E195006
            if (errCode == SVNErrorCode.CLIENT_MODIFIED) {
                String errMessage = errCode.toString();
                logger.warning("[SVNService] delete --> " + errMessage);
                return false;
            }
            int ret = handleError("delete", e, ++cnt);
            switch(ret) {
                case ERROR_NEXT_THROW:
                    throw e;
                case ERROR_NEXT_BREAK:
                    return true;
                case ERROR_NEXT_RETRY:
                    continue;
            }
        }
    }
}
Also used : SVNErrorCode(org.tmatesoft.svn.core.SVNErrorCode) SVNWCClient(org.tmatesoft.svn.core.wc.SVNWCClient) SVNException(org.tmatesoft.svn.core.SVNException) File(java.io.File)

Example 17 with SVNWCClient

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

Example 18 with SVNWCClient

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

the class SvnScmProvider method computeChangedPaths.

static Set<Path> computeChangedPaths(Path projectBasedir, SVNClientManager clientManager) throws SVNException {
    SVNWCClient wcClient = clientManager.getWCClient();
    SVNInfo svnInfo = wcClient.doInfo(projectBasedir.toFile(), null);
    // SVN path of the repo root, for example: /C:/Users/JANOSG~1/AppData/Local/Temp/x/y
    Path svnRootPath = toPath(svnInfo.getRepositoryRootURL());
    // -> set it to "/" to avoid crashing when using Path.relativize later
    if (svnRootPath.equals(Paths.get(""))) {
        svnRootPath = Paths.get("/");
    }
    // SVN path of projectBasedir, for example: /C:/Users/JANOSG~1/AppData/Local/Temp/x/y/branches/b1
    Path svnProjectPath = toPath(svnInfo.getURL());
    // path of projectBasedir, as "absolute path within the SVN repo", for example: /branches/b1
    Path inRepoProjectPath = Paths.get("/").resolve(svnRootPath.relativize(svnProjectPath));
    // We inspect "svn log" from latest revision until copy-point.
    // The same path may appear in multiple commits, the ordering of changes and removals is important.
    Set<Path> paths = new HashSet<>();
    Set<Path> removed = new HashSet<>();
    SVNLogClient svnLogClient = clientManager.getLogClient();
    svnLogClient.doLog(new File[] { projectBasedir.toFile() }, null, null, null, true, true, 0, svnLogEntry -> svnLogEntry.getChangedPaths().values().forEach(entry -> {
        if (entry.getKind().equals(SVNNodeKind.FILE)) {
            Path path = projectBasedir.resolve(inRepoProjectPath.relativize(Paths.get(entry.getPath())));
            if (isModified(entry)) {
                // Skip if the path is removed in a more recent commit
                if (!removed.contains(path)) {
                    paths.add(path);
                }
            } else if (entry.getType() == SVNLogEntryPath.TYPE_DELETED) {
                removed.add(path);
            }
        }
    }));
    return paths;
}
Also used : Path(java.nio.file.Path) SVNLogEntryPath(org.tmatesoft.svn.core.SVNLogEntryPath) ScmProvider(org.sonar.api.batch.scm.ScmProvider) URL(java.net.URL) URISyntaxException(java.net.URISyntaxException) SVNDepth(org.tmatesoft.svn.core.SVNDepth) SvnScmSupport.newSvnClientManager(org.sonar.scm.svn.SvnScmSupport.newSvnClientManager) SVNClientManager(org.tmatesoft.svn.core.wc.SVNClientManager) HashSet(java.util.HashSet) SVNLogClient(org.tmatesoft.svn.core.wc.SVNLogClient) Loggers(org.sonar.api.utils.log.Loggers) Map(java.util.Map) Path(java.nio.file.Path) Logger(org.sonar.api.utils.log.Logger) SVNLogEntryPath(org.tmatesoft.svn.core.SVNLogEntryPath) MalformedURLException(java.net.MalformedURLException) SVNException(org.tmatesoft.svn.core.SVNException) SVNNodeKind(org.tmatesoft.svn.core.SVNNodeKind) Set(java.util.Set) Instant(java.time.Instant) File(java.io.File) SVNRevision(org.tmatesoft.svn.core.wc.SVNRevision) Paths(java.nio.file.Paths) SVNURL(org.tmatesoft.svn.core.SVNURL) SVNWCClient(org.tmatesoft.svn.core.wc.SVNWCClient) BlameCommand(org.sonar.api.batch.scm.BlameCommand) SVNInfo(org.tmatesoft.svn.core.wc.SVNInfo) CheckForNull(javax.annotation.CheckForNull) SVNDiffClient(org.tmatesoft.svn.core.wc.SVNDiffClient) SVNWCClient(org.tmatesoft.svn.core.wc.SVNWCClient) SVNInfo(org.tmatesoft.svn.core.wc.SVNInfo) SVNLogClient(org.tmatesoft.svn.core.wc.SVNLogClient) HashSet(java.util.HashSet)

Aggregations

SVNWCClient (org.tmatesoft.svn.core.wc.SVNWCClient)18 SVNException (org.tmatesoft.svn.core.SVNException)10 VcsException (com.intellij.openapi.vcs.VcsException)4 File (java.io.File)4 SVNPropertyData (org.tmatesoft.svn.core.wc.SVNPropertyData)4 SvnBindException (org.jetbrains.idea.svn.commandLine.SvnBindException)2 SVNProperties (org.tmatesoft.svn.core.SVNProperties)2 SVNClientManager (org.tmatesoft.svn.core.wc.SVNClientManager)2 SVNInfo (org.tmatesoft.svn.core.wc.SVNInfo)2 SVNLogClient (org.tmatesoft.svn.core.wc.SVNLogClient)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 OutputStream (java.io.OutputStream)1 MalformedURLException (java.net.MalformedURLException)1 URISyntaxException (java.net.URISyntaxException)1 URL (java.net.URL)1 Path (java.nio.file.Path)1 Paths (java.nio.file.Paths)1 Instant (java.time.Instant)1 HashSet (java.util.HashSet)1 Map (java.util.Map)1