1

I only found How to list locally-modified/unversioned files using svnkit? which would need complex logic to be implemented to get the exact output of svn status on a root directory of a repository.

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().

But I can't get it to work and don't find the exact way jsvn is doing it. I would debug jsvn, but cannot get gradle build set up, most probably because of our windows ntlm http proxy here...

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, i.e. being null. The aim is to get the output in a String. I don't like the PrintStream and the extra file in the filesystem, but don't see a different way.

1 Answer 1

4
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()));
Sign up to request clarification or add additional context in comments.

3 Comments

Could it become a problem to use System.in? What if I'm not sure the command would really try to get input? Could the program 'hang' if the calling code doesn't provide a console to the user (as I do)?
Theoretically, it could become a problem. But local "svn status" should never require input from the console. You might create some custom InputStream which throws IOException when trying to read from it.
Is there documentation on svnkit-cli anywhere? There doesn't seem to be any JavaDoc in the source code, at least at 1.7.11.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.