提交 841e36e4 编写于 作者: K kohsuke

fixed whitespace handling on Windows. (#1007)


git-svn-id: https://hudson.dev.java.net/svn/hudson/trunk/hudson/main@5932 71c3de6d-444a-0410-be80-ed276b4c234a
上级 67f73f22
......@@ -155,8 +155,16 @@ public class Ant extends Builder {
// so we need to wrap it into cmd.exe.
// double %% is needed because we want ERRORLEVEL to be expanded after
// batch file executed, not before. This alone shows how broken Windows is...
args.prepend("cmd.exe","/C");
args.add("&&","exit","%%ERRORLEVEL%%");
// on Windows, proper double quote handling requires extra surrounding quote.
// so we need to convert the entire argument list once into a string,
// then build the new list so that by the time JVM invokes CreateProcess win32 API,
// it puts additional double-quote. See issue #1007
// the 'addQuoted' is necessary because Process implementation for Windows (at least in Sun JVM)
// is too clever to avoid putting a quote around it if the argument begins with "
// see "cmd /?" for more about how cmd.exe handles quotation.
args = new ArgumentListBuilder().add("cmd.exe","/C").addQuoted(args.toStringWithQuote());
}
try {
......
......@@ -81,4 +81,17 @@ public class ArgumentListBuilder {
public List<String> toList() {
return args;
}
public String toStringWithQuote() {
StringBuilder buf = new StringBuilder();
for (String arg : args) {
if(buf.length()>0) buf.append(' ');
if(arg.indexOf(' ')>=0 || arg.length()==0)
buf.append('"').append(arg).append('"');
else
buf.append(arg);
}
return buf.toString();
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册