From f0f55c38a5d3553f664c870b682bc8eb0d667272 Mon Sep 17 00:00:00 2001 From: Eugene Yokota Date: Mon, 24 Jun 2019 19:32:55 -0400 Subject: [PATCH] quote run argument if it contains a whitespace Fixes #4834 --- run/src/main/scala/sbt/Run.scala | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/run/src/main/scala/sbt/Run.scala b/run/src/main/scala/sbt/Run.scala index 0ae16f58b..08b3edc19 100644 --- a/run/src/main/scala/sbt/Run.scala +++ b/run/src/main/scala/sbt/Run.scala @@ -47,7 +47,7 @@ class ForkRun(config: ForkOptions) extends ScalaRun { } def fork(mainClass: String, classpath: Seq[File], options: Seq[String], log: Logger): Process = { - log.info("Running (fork) " + mainClass + " " + options.mkString(" ")) + log.info(s"running (fork) $mainClass ${Run.runOptionsStr(options)}") val scalaOptions = classpathOption(classpath) ::: mainClass :: options.toList val configLogged = @@ -65,7 +65,7 @@ class Run(newLoader: Seq[File] => ClassLoader, trapExit: Boolean) extends ScalaR /** Runs the class 'mainClass' using the given classpath and options using the scala runner.*/ def run(mainClass: String, classpath: Seq[File], options: Seq[String], log: Logger): Try[Unit] = { - log.info("Running " + mainClass + " " + options.mkString(" ")) + log.info(s"running $mainClass ${Run.runOptionsStr(options)}") def execute() = try { @@ -159,4 +159,12 @@ object Run { Success(()) } else Failure(new MessageOnlyException("Nonzero exit code: " + exitCode)) } + + // quotes the option that includes a whitespace + // https://github.com/sbt/sbt/issues/4834 + private[sbt] def runOptionsStr(options: Seq[String]): String = + (options map { + case str if str.contains(" ") => "\"" + str + "\"" + case str => str + }).mkString(" ") }