Skip to content

Commit

Permalink
Fix file paths when running on Windows (#999)
Browse files Browse the repository at this point in the history
earldouglas authored Nov 17, 2024
1 parent e1f5684 commit e0c898d
Showing 2 changed files with 23 additions and 5 deletions.
18 changes: 14 additions & 4 deletions src/main/scala/com/earldouglas/sbt/war/SbtWar.scala
Original file line number Diff line number Diff line change
@@ -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
)
10 changes: 9 additions & 1 deletion src/main/scala/com/earldouglas/sbt/war/WebappComponents.scala
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit e0c898d

Please sign in to comment.