Ok, so the first thing to note is that this phenomena does not happen on Windows. FitNesse automatically encloses classpath elements contained whitespace with double-quotes, as already noted in the question. The command which FitNesse generates is:
java -cp fitnesse.jar:"/home/stewart/white space test/example-1.0.0-SNAPSHOT/target/test-classes":"/home/stewart/white space test/example-1.0.0-SNAPSHOT/target/classes":/home/stewart/.m2/repository/org/fitnesse/fitnesse/20121220/fitnesse-20121220.jar fit.FitServer linux-desktop 9123 10
On Windows, this would be:
java -cp fitnesse.jar:"C:\white space test\example-1.0.0-SNAPSHOT\target\test-classes":"C:\white space test\example-1.0.0-SNAPSHOT\target\classes":C:\.m2\repository\org\fitnesse\fitnesse\20121220\fitnesse-20121220.jar fit.FitServer windows-desktop 9123 10
And it just works!
Given that Windows is the operating system where it's common to have whitespace in directory (folder) names, I could have stopped there; but I wanted to dig deeper, as you can occasionally get whitespace in directory names on Unix-like systems (MacOS springs to mind.)
Digging into FitNesse source code, the class we are interested in is fitnesse.testsystems.CommandRunner
. In the method asynchronousStart()
it uses Java's Runtime.exec()
method.
Runtime.exec()
has overloaded methods. In some, the command is a String
which gets parsed with a java.util.StringTokenizer
. In others, the command is already a String[]
and does not get further parsed.
In other words, this fails:
String cmd = "java -cp fitnesse.jar:\"/home/stewart/white space test/example-1.0.0-SNAPSHOT/target/test-classes\":\"/home/stewart/white space test/example-1.0.0-SNAPSHOT/target/classes\":/home/stewart/.m2/repository/org/fitnesse/fitnesse/20121220/fitnesse-20121220.jar fit.FitServer linux-desktop 9123 10";
String[] env = new String[]{};
Runtime.getRuntime().exec(cmd, env);
Whilst this works:
String[] cmd = new String[] {
"java",
"-cp",
"fitnesse.jar:\"/home/stewart/white space test/example-1.0.0-SNAPSHOT/target/test-classes\":\"/home/stewart/white space test/example-1.0.0-SNAPSHOT/target/classes\":/home/stewart/.m2/repository/org/fitnesse/fitnesse/20121220/fitnesse-20121220.jar",
"fit.FitServer",
"linux-desktop",
"9123",
"10";
};
String[] env = new String[]{};
Runtime.getRuntime().exec(cmd, env);
Conclusion: it's a bug in FitNesse.
Update: this is fixed FitNesse versions 20140623 onwards.