Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix file paths when running on Windows #999

Merged
merged 2 commits into from
Nov 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Expand Up @@ -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
Expand All @@ -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")
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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(",")

Expand All @@ -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
)
Expand Down
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
Expand Up @@ -2,6 +2,8 @@ package com.earldouglas.sbt.war

import sbt._

import java.io.File

/** Identifies the files that compose the webapp:
*
* - Resources
Expand Down Expand Up @@ -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
Expand Down
Loading