Search in sources :

Example 6 with SVNInfo

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;
}
Also used : SVNInfo(org.tmatesoft.svn.core.wc.SVNInfo) SVNException(org.tmatesoft.svn.core.SVNException)

Example 7 with SVNInfo

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());
}
Also used : SVNInfo(org.tmatesoft.svn.core.wc.SVNInfo) File(java.io.File)

Example 8 with SVNInfo

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();
}
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 9 with SVNInfo

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

Example 10 with SVNInfo

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);
}
Also used : ArrayList(java.util.ArrayList) SVNInfo(org.tmatesoft.svn.core.wc.SVNInfo) SVNRevision(org.tmatesoft.svn.core.wc.SVNRevision) Map(java.util.Map)

Aggregations

SVNInfo (org.tmatesoft.svn.core.wc.SVNInfo)10 Test (org.junit.Test)4 Change (com.intellij.openapi.vcs.changes.Change)3 SVNClientManager (org.tmatesoft.svn.core.wc.SVNClientManager)3 SVNPropertyData (org.tmatesoft.svn.core.wc.SVNPropertyData)3 SmartList (com.intellij.util.SmartList)2 File (java.io.File)2 Map (java.util.Map)2 AtomicReference (java.util.concurrent.atomic.AtomicReference)2 SVNException (org.tmatesoft.svn.core.SVNException)2 SVNURL (org.tmatesoft.svn.core.SVNURL)2 SVNLogClient (org.tmatesoft.svn.core.wc.SVNLogClient)2 SVNRevision (org.tmatesoft.svn.core.wc.SVNRevision)2 SVNWCClient (org.tmatesoft.svn.core.wc.SVNWCClient)2 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