use of org.tmatesoft.svn.core.wc.SVNInfo in project MassBank-web by MassBank.
the class SVNOperation method getWcRevision.
/*
* Gets the revision number of working copy
*/
public long getWcRevision() {
long revison = 0;
try {
SVNInfo info = this.svnClient.getInfo();
revison = info.getRevision().getNumber();
} catch (SVNException e) {
e.printStackTrace();
}
return revison;
}
use of org.tmatesoft.svn.core.wc.SVNInfo in project omegat by omegat-org.
the class SVNRemoteRepository2 method getFileVersion.
@Override
public String getFileVersion(String file) throws Exception {
File f = new File(baseDirectory, file);
if (!f.exists()) {
return null;
}
SVNInfo info = ourClientManager.getWCClient().doInfo(f, SVNRevision.BASE);
Log.logDebug(LOGGER, "SVN committed revision for file {0} is {1}", file, info.getCommittedRevision().getNumber());
return Long.toString(info.getCommittedRevision().getNumber());
}
use of org.tmatesoft.svn.core.wc.SVNInfo 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.SVNInfo 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;
}
use of org.tmatesoft.svn.core.wc.SVNInfo in project omegat by omegat-org.
the class SVNRemoteRepository2 method getRecentlyDeletedFiles.
@Override
public String[] getRecentlyDeletedFiles() throws Exception {
final ArrayList<String> deleted = new ArrayList<>();
final SVNInfo info = ourClientManager.getWCClient().doInfo(baseDirectory, SVNRevision.HEAD);
SVNRevision currentRevision = info.getRevision();
String settingKey = "lastDeleteCheckForName" + baseDirectory.getName();
String sinceRevisionString = projectTeamSettings.get(settingKey);
SVNRevision sinceRevision;
if (sinceRevisionString == null) {
sinceRevision = currentRevision;
} else {
sinceRevision = SVNRevision.parse(sinceRevisionString);
}
final String repoPath = info.getPath();
try {
ourClientManager.getLogClient().doLog(new File[] { baseDirectory }, sinceRevision, currentRevision, false, // to get the list of files changed/deleted
true, 1000000, new ISVNLogEntryHandler() {
public void handleLogEntry(SVNLogEntry en) throws SVNException {
if (en.getRevision() == sinceRevision.getNumber()) {
return;
}
Map<String, SVNLogEntryPath> changedPaths = en.getChangedPaths();
for (Map.Entry<String, SVNLogEntryPath> entry : changedPaths.entrySet()) {
SVNLogEntryPath path = entry.getValue();
// eg /remotedir/my/file; repoPath = remotedir. To strip /remotedir/, add 2 for the slashes. But if remoteDir is empty, then only 1 slash to be removed.
String filePath = path.getPath();
if ("".equals(repoPath)) {
filePath = filePath.substring(1);
} else {
filePath = filePath.substring(repoPath.length() + 2);
}
// filepath is always using '/', but on windows we want to return path with backslashes
filePath = filePath.replace('/', File.separatorChar);
if (path.getType() == 'D') {
deleted.add(filePath);
} else if (path.getType() == 'A') {
// added after it has been deleted. Don't delete any more!
deleted.remove(filePath);
}
}
}
});
} catch (SVNException e) {
e.printStackTrace();
}
projectTeamSettings.set(settingKey, Long.toString(currentRevision.getNumber()));
String[] result = new String[deleted.size()];
return deleted.toArray(result);
}
Aggregations