Find sbt.bat in windows $PATH

This commit is contained in:
Adrien Piquerez 2021-07-14 10:25:20 +02:00
parent c4e6cf54d2
commit 2287f3e384
1 changed files with 3 additions and 2 deletions

View File

@ -60,11 +60,12 @@ object BuildServerConnection {
private def sbtScriptInPath: Option[String] = {
// For those who use an old sbt script, the -Dsbt.script is not set
// As a fallback we try to find the sbt script in $PATH
val fileName = if (Properties.isWin) "sbt.bat" else "sbt"
val envPath = Option(System.getenv("PATH")).getOrElse("")
val allPaths = envPath.split(File.pathSeparator).map(Paths.get(_))
allPaths
.map(_.resolve("sbt"))
.find(file => Files.exists(file))
.map(_.resolve(fileName))
.find(file => Files.exists(file) && Files.isExecutable(file))
.map(_.toString.replaceAllLiterally(" ", "%20"))
}
}