From 842ae5a78e4d9675c6bfb53c5cd4d52026d37bef Mon Sep 17 00:00:00 2001 From: Stefan Zeiger Date: Thu, 21 Jan 2016 17:56:46 +0100 Subject: Use Windows classpath in sh scripts when building in sbt on Windows The generated scripts for "quick" are not portable anyway (neither in the sbt build nor in the ant build) because they contain absolute paths. When using the sh versions on Windows in MSYS or Cygwin, the classpath must be in Windows format because "java" expects it that way. Note that none of this applies to "pack" (and thus to distribution builds) where the classpath is constructed dynamically by the launcher scripts itself. --- project/ScalaTool.scala | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) (limited to 'project') diff --git a/project/ScalaTool.scala b/project/ScalaTool.scala index 559b215c18..a30f5f0a73 100644 --- a/project/ScalaTool.scala +++ b/project/ScalaTool.scala @@ -1,4 +1,5 @@ import sbt._ +import org.apache.commons.lang3.SystemUtils import org.apache.commons.lang3.StringUtils.replaceEach /** @@ -17,6 +18,14 @@ case class ScalaTool(mainClass: String, // `@SCALA_HOME@`) and automatically translated for you. def patchedToolScript(template: String, platform: String) = { val varRegex = """@(\w+)@""" // the group should be able to capture each of the keys of the map below + val platformClasspath = platform match { + case "unix" => + // When building on Windows, use a Windows classpath in the shell script (for MSYS/Cygwin). + // This is only used for "quick", which uses absolute paths, so it is not portable anyway. + if(SystemUtils.IS_OS_WINDOWS) classpath.mkString(";").replace("\\", "\\\\").replaceAll(varRegex, """\${$1}""") + else classpath.mkString(":").replace('\\', '/').replaceAll(varRegex, """\${$1}""") + case "windows" => classpath.mkString(";").replace('/', '\\').replaceAll(varRegex, "%$1%") + } val variables = Map( ("@@" -> "@"), // for backwards compatibility @@ -24,10 +33,7 @@ case class ScalaTool(mainClass: String, ("@properties@" -> (properties map { case (k, v) => s"""-D$k="$v""""} mkString " ")), ("@javaflags@" -> javaOpts), ("@toolflags@" -> toolFlags), - ("@classpath@" -> (platform match { - case "unix" => classpath.mkString(":").replace('\\', '/').replaceAll(varRegex, """\${$1}""") - case "windows" => classpath.mkString(";").replace('/', '\\').replaceAll(varRegex, "%$1%") - })) + ("@classpath@" -> platformClasspath) ) val (from, to) = variables.unzip -- cgit v1.2.3