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;
}
}
}
}
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();
}
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;
}
Aggregations