diff --git a/src/main/scala/com/earldouglas/sbt/war/SbtWar.scala b/src/main/scala/com/earldouglas/sbt/war/SbtWar.scala index 8a5683dd..24948367 100644 --- a/src/main/scala/com/earldouglas/sbt/war/SbtWar.scala +++ b/src/main/scala/com/earldouglas/sbt/war/SbtWar.scala @@ -8,6 +8,7 @@ import sbt.Keys.{`package` => pkg} import sbt.Plugins import sbt._ +import java.io.File import java.nio.file.Files import java.nio.file.Paths import java.util.concurrent.atomic.AtomicReference @@ -20,6 +21,15 @@ import scala.sys.process.{Process => ScalaProcess} */ object SbtWar extends AutoPlugin { + implicit class Exscape(val x: File) { + def getEscapedPath(): String = + if (File.separatorChar == '\\') { + x.getPath().replace("\\", "\\\\") + } else { + x.getPath() + } + } + object autoImport { lazy val War = config("war").hide lazy val warPort = settingKey[Int]("container port") @@ -73,7 +83,7 @@ object SbtWar extends AutoPlugin { .writeString( Paths.get(configurationFile.getPath()), s"""|port=${warPort.value} - |warFile=${pkg.value.getPath()} + |warFile=${pkg.value.getEscapedPath()} |""".stripMargin ) .toFile() @@ -132,7 +142,7 @@ object SbtWar extends AutoPlugin { val resourceMapString = WebappComponentsPlugin.warContents.value .map { case (k, v) => - s"${k}->${v}" + s"${k}->${v.getEscapedPath()}" } .mkString(",") @@ -145,8 +155,8 @@ object SbtWar extends AutoPlugin { s"""|hostname=localhost |port=${warPort.value} |contextPath= - |emptyWebappDir=${emptyDir} - |emptyClassesDir=${emptyDir} + |emptyWebappDir=${emptyDir.getEscapedPath()} + |emptyClassesDir=${emptyDir.getEscapedPath()} |resourceMap=${resourceMapString} |""".stripMargin ) diff --git a/src/main/scala/com/earldouglas/sbt/war/WebappComponents.scala b/src/main/scala/com/earldouglas/sbt/war/WebappComponents.scala index 27ded17b..7eca5500 100644 --- a/src/main/scala/com/earldouglas/sbt/war/WebappComponents.scala +++ b/src/main/scala/com/earldouglas/sbt/war/WebappComponents.scala @@ -2,6 +2,8 @@ package com.earldouglas.sbt.war import sbt._ +import java.io.File + /** Identifies the files that compose the webapp: * * - Resources @@ -51,7 +53,13 @@ object WebappComponents { if classFile.exists() if classFile.isFile() relativeFile <- IO.relativizeFile(classpathDir, classFile) - relativePath = s"WEB-INF/classes/${relativeFile.getPath()}" + relativeFilePath = + if (File.separatorChar == '\\') { + relativeFile.getPath().replace("\\", "/") + } else { + relativeFile.getPath() + } + relativePath = s"WEB-INF/classes/${relativeFilePath}" } yield (relativePath, classFile) classesMappings.toMap