From c740f251f4257a16988b584899291ab8d1e975a9 Mon Sep 17 00:00:00 2001 From: Federico Fissore Date: Mon, 13 Apr 2015 12:05:00 +0200 Subject: [PATCH] SAM boards stop compiling due to way of handling params with spaces on different OSs. Fixed --- .../src/processing/app/debug/Compiler.java | 13 ++++---- .../ArgumentsWithSpaceAwareCommandLine.java | 32 +++++++++++++++++++ 2 files changed, 39 insertions(+), 6 deletions(-) create mode 100644 arduino-core/src/processing/app/tools/ArgumentsWithSpaceAwareCommandLine.java diff --git a/arduino-core/src/processing/app/debug/Compiler.java b/arduino-core/src/processing/app/debug/Compiler.java index 4e85e85c5..2da6d7341 100644 --- a/arduino-core/src/processing/app/debug/Compiler.java +++ b/arduino-core/src/processing/app/debug/Compiler.java @@ -54,6 +54,7 @@ import processing.app.preproc.PdePreprocessor; import processing.app.legacy.PApplet; import processing.app.packages.LegacyUserLibrary; import processing.app.packages.UserLibrary; +import processing.app.tools.ArgumentsWithSpaceAwareCommandLine; public class Compiler implements MessageConsumer { @@ -319,10 +320,10 @@ public class Compiler implements MessageConsumer { if (maxDataSize > 0) { System.out .println(I18n - .format( - _("Global variables use {0} bytes ({2}%%) of dynamic memory, leaving {3} bytes for local variables. Maximum is {1} bytes."), - dataSize, maxDataSize, dataSize * 100 / maxDataSize, - maxDataSize - dataSize)); + .format( + _("Global variables use {0} bytes ({2}%%) of dynamic memory, leaving {3} bytes for local variables. Maximum is {1} bytes."), + dataSize, maxDataSize, dataSize * 100 / maxDataSize, + maxDataSize - dataSize)); } else { System.out.println(I18n .format(_("Global variables use {0} bytes of dynamic memory."), dataSize)); @@ -736,9 +737,9 @@ public class Compiler implements MessageConsumer { } }); - CommandLine commandLine = new CommandLine(command[0]); + CommandLine commandLine = new ArgumentsWithSpaceAwareCommandLine(command[0]); for (int i = 1; i < command.length; i++) { - commandLine.addArgument(command[i]); + commandLine.addArgument(command[i], false); } int result; diff --git a/arduino-core/src/processing/app/tools/ArgumentsWithSpaceAwareCommandLine.java b/arduino-core/src/processing/app/tools/ArgumentsWithSpaceAwareCommandLine.java new file mode 100644 index 000000000..775b4c2b0 --- /dev/null +++ b/arduino-core/src/processing/app/tools/ArgumentsWithSpaceAwareCommandLine.java @@ -0,0 +1,32 @@ +package processing.app.tools; + +import org.apache.commons.exec.CommandLine; +import processing.app.BaseNoGui; +import processing.app.Platform; +import processing.app.helpers.OSUtils; + +import java.io.File; + +public class ArgumentsWithSpaceAwareCommandLine extends CommandLine { + + public ArgumentsWithSpaceAwareCommandLine(String executable) { + super(executable); + } + + public ArgumentsWithSpaceAwareCommandLine(File executable) { + super(executable); + } + + public ArgumentsWithSpaceAwareCommandLine(CommandLine other) { + super(other); + } + + @Override + public CommandLine addArgument(String argument, boolean handleQuoting) { + if (argument.contains(" ") && OSUtils.isWindows()) { + argument = argument.replaceAll("\"", "").replaceAll("'", ""); + } + + return super.addArgument(argument, handleQuoting); + } +}