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.

Community
  • 1
  • 1
jan
  • 2,741
  • 4
  • 35
  • 56

1 Answers1

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()));
mstrap
  • 16,808
  • 10
  • 56
  • 86
  • 1
    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)? – jan Oct 19 '12 at 09:37
  • 1
    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. – mstrap Oct 19 '12 at 14:37
  • 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. – David Moles Sep 03 '14 at 22:22