Question

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.

Était-ce utile?

La solution

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()));
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top