Search in sources :

Example 11 with SVNLogClient

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

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