use of org.tmatesoft.svn.core.wc.SVNClientManager 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.SVNClientManager in project omegat by omegat-org.
the class TeamTool method initTeamProject.
/**
* Utility function to create a minimal project to serve as a base for a
* team project. Will add/stage everything if invoked on a path already
* containing a git working tree or svn checkout.
*
* @param dir
* Directory in which to create team project
* @param srcLang
* Source language
* @param trgLang
* Target language
* @throws Exception
* If specified dir is not a directory, is not writeable, etc.
*/
public static void initTeamProject(File dir, String srcLang, String trgLang) throws Exception {
if (!dir.isDirectory()) {
throw new IllegalArgumentException("Specified dir is not a directory: " + dir.getPath());
}
if (!dir.canWrite()) {
throw new IOException("Specified dir is not writeable: " + dir.getPath());
}
// Create project properties
ProjectProperties props = new ProjectProperties(dir);
props.setSourceLanguage(srcLang);
props.setTargetLanguage(trgLang);
// Set default tokenizers
props.setSourceTokenizer(PluginUtils.getTokenizerClassForLanguage(new Language(srcLang)));
props.setTargetTokenizer(PluginUtils.getTokenizerClassForLanguage(new Language(trgLang)));
// Create project internal directories
props.autocreateDirectories();
// Create version-controlled glossary file
GlossaryManager.createNewWritableGlossaryFile(props.getWritableGlossaryFile().getAsFile());
ProjectFileStorage.writeProjectFile(props);
// Create empty project TM
new ProjectTMX(props.getSourceLanguage(), props.getTargetLanguage(), props.isSentenceSegmentingEnabled(), null, null).save(props, new File(props.getProjectInternal(), OConsts.STATUS_EXTENSION).getPath(), false);
// and set EOL handling correctly for cross-platform work
if (new File(dir, ".svn").isDirectory()) {
SVNClientManager mgr = SVNClientManager.newInstance();
mgr.getWCClient().doSetProperty(dir, "svn:auto-props", SVNPropertyValue.create("*.txt = svn:eol-style=native\n*.tmx = svn:eol-style=native\n"), false, SVNDepth.EMPTY, null, null);
mgr.getWCClient().doAdd(dir.listFiles(f -> !f.getName().startsWith(".")), false, false, true, SVNDepth.fromRecurse(true), false, false, false, true);
} else if (new File(dir, ".git").isDirectory()) {
try (BufferedWriter writer = Files.newBufferedWriter(new File(dir, ".gitattributes").toPath())) {
writer.write("* text=auto\n");
writer.write("*.tmx text\n");
writer.write("*.txt text\n");
}
Git.open(dir).add().addFilepattern(".").call();
}
System.out.println(StringUtil.format(OStrings.getString("TEAM_TOOL_INIT_COMPLETE"), srcLang, trgLang));
}
use of org.tmatesoft.svn.core.wc.SVNClientManager in project omegat by omegat-org.
the class SVNRemoteRepository2 method isSVNRepository.
/**
* Determines whether or not the supplied URL represents a valid Subversion repository.
*
* <p>
* Does the equivalent of <code>svn info <i>url</i></code>.
*
* @param url
* URL of supposed remote repository
* @return true if repository appears to be valid, false otherwise
*/
public static boolean isSVNRepository(String url) {
// Heuristics to save some waiting time
try {
ISVNOptions options = SVNWCUtil.createDefaultOptions(true);
SVNClientManager ourClientManager = SVNClientManager.newInstance(options, (ISVNAuthenticationManager) null);
ourClientManager.getWCClient().doInfo(SVNURL.parseURIEncoded(SVNEncodingUtil.autoURIEncode(url)), SVNRevision.HEAD, SVNRevision.HEAD);
} catch (SVNAuthenticationException ex) {
// https://twitter.com/amadlonkay/status/699716236372889600
return true;
} catch (SVNException ex) {
return false;
}
return true;
}
Aggregations