[英]svnkit: How to get exact result of 'svn status' programmatically as String?
I only found How to list locally-modified/unversioned files using svnkit? 我只找到了如何使用svnkit列出本地修改/未版本控制的文件? which would need complex logic to be implemented to get the exact output of
svn status
on a root directory of a repository. 这需要实现复杂的逻辑,以便在存储库的根目录中获得
svn status
的确切输出。
As svnkit also delivers a command line tool jsvn
which is implemented in svnkit-cli
I found the code I want to use in org.tmatesoft.svn.cli.svn.SVNStatusCommand.run()
. 由于svnkit还提供了一个命令行工具
jsvn
,它在jsvn
svnkit-cli
实现,我找到了我想在org.tmatesoft.svn.cli.svn.SVNStatusCommand.run()
使用的代码。
But I can't get it to work and don't find the exact way jsvn is doing it. 但我无法让它工作,并没有找到jsvn正在做的确切方式。 I would debug jsvn, but cannot get gradle build set up, most probably because of our windows ntlm http proxy here...
我会调试jsvn,但无法获得gradle构建,很可能是因为我们的windows ntlm http代理在这里...
What I have tried so far: 到目前为止我尝试过的:
StringBuffer result = new StringBuffer();
SVNStatusCommand svnStatusCall = new SVNStatusCommand();
File statusResult = new File(System.getProperty("java.io.tmpdir") + File.separator + System.currentTimeMillis() + "svnStatusCalls");
PrintStream stream = new PrintStream(statusResult);
SVNCommandEnvironment env = new SVNCommandEnvironment("mySvn", stream, stream, null);
env.getTargets().add("/home/user/svnroot");
svnStatusCall.init(env);
svnStatusCall.run();
stream.flush();
Scanner scanner = new Scanner(statusResult);
while (scanner.hasNextLine()) {
result.append(scanner.nextLine());
}
scanner.close();
This fails due to myTargets of the SVNCommandEnvironment beeing not initialized yet, ie being null. 这由于SVNCommandEnvironment的myTargets尚未初始化而失败,即为空。 The aim is to get the output in a String.
目的是在String中获取输出。 I don't like the PrintStream and the extra file in the filesystem, but don't see a different way.
我不喜欢PrintStream和文件系统中的额外文件,但没有看到不同的方式。
AbstractSVNCommand.registerCommand(new SVNStatusCommand());
final ByteArrayOutputStream bos = new ByteArrayOutputStream();
final PrintStream stream = new PrintStream(bos);
final SVNCommandLine commandLine = new SVNCommandLine();
commandLine.init(new String[] {"status", "d:/svntest/small.svn17"});
final SVNCommandEnvironment env = new SVNCommandEnvironment("mySvn", stream, stream, System.in);
env.init(commandLine);
env.initClientManager();
final SVNStatusCommand svnStatusCall = new SVNStatusCommand();
svnStatusCall.init(env);
svnStatusCall.run();
stream.flush();
System.out.println(new String(bos.toByteArray()));
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.