1
0
Fork 0
mirror of https://github.com/ethauvin/kobalt.git synced 2025-04-26 08:27:12 -07:00

Fix bug in path parsing on Windows.

This commit is contained in:
Cedric Beust 2015-11-07 08:57:21 -08:00
parent f74810269c
commit e580c3f7bd

View file

@ -1,66 +1,64 @@
package com.beust.kobalt package com.beust.kobalt
import java.io.File import java.io.File
import java.util.*
import java.util.regex.Pattern
public abstract class OperatingSystem { abstract class OperatingSystem {
override fun toString(): String { override fun toString(): String {
return getName() + " " + getVersion() + " " + System.getProperty("os.arch") return getName() + " " + getVersion() + " " + System.getProperty("os.arch")
} }
public fun getName(): String { fun getName(): String {
return System.getProperty("os.name") return System.getProperty("os.name")
} }
public fun getVersion(): String { fun getVersion(): String {
return System.getProperty("os.version") return System.getProperty("os.version")
} }
public open fun isWindows(): Boolean { open fun isWindows(): Boolean {
return false return false
} }
public open fun isUnix(): Boolean { open fun isUnix(): Boolean {
return false return false
} }
public open fun isMacOsX(): Boolean { open fun isMacOsX(): Boolean {
return false return false
} }
public open fun isLinux(): Boolean { open fun isLinux(): Boolean {
return false return false
} }
public abstract fun getNativePrefix(): String abstract fun getNativePrefix(): String
public abstract fun getScriptName(scriptPath: String): String abstract fun getScriptName(scriptPath: String): String
public abstract fun getExecutableName(executablePath: String): String abstract fun getExecutableName(executablePath: String): String
public abstract fun getSharedLibraryName(libraryName: String): String abstract fun getSharedLibraryName(libraryName: String): String
public abstract fun getStaticLibraryName(libraryName: String): String abstract fun getStaticLibraryName(libraryName: String): String
public abstract fun getFamilyName(): String abstract fun getFamilyName(): String
/** /**
* Locates the given executable in the system path. Returns null if not found. * Locates the given executable in the system path. Returns null if not found.
*/ */
public fun findInPath(name: String): File? { fun findInPath(name: String): File? {
val exeName = getExecutableName(name) val exeName = getExecutableName(name)
if (exeName.contains(File.separator)) { if (exeName.contains(File.separator)) {
val candidate = File(exeName) val candidate = File(exeName)
if (candidate.isFile()) { if (candidate.isFile) {
return candidate return candidate
} }
return null return null
} }
for (dir in getPath()) { for (dir in path) {
val candidate = File(dir, exeName) val candidate = File(dir, exeName)
if (candidate.isFile()) { if (candidate.isFile) {
return candidate return candidate
} }
} }
@ -68,29 +66,25 @@ public abstract class OperatingSystem {
return null return null
} }
public fun findAllInPath(name: String): List<File> { // fun findAllInPath(name: String): List<File> {
val all = LinkedList<File>() // val all = LinkedList<File>()
//
// for (dir in getPath()) {
// val candidate = File(dir, name)
// if (candidate.isFile) {
// all.add(candidate)
// }
// }
//
// return all
// }
for (dir in getPath()) { val path: List<File>
val candidate = File(dir, name) get() {
if (candidate.isFile()) { return (System.getenv(getPathVar()) ?: return emptyList()).split(File.pathSeparator).map { File(it) }
all.add(candidate)
}
} }
return all open fun getPathVar(): String {
}
public fun getPath(): List<File> {
val path = System.getenv(getPathVar()) ?: return emptyList<File>()
val entries = ArrayList<File>()
for (entry in path.split(Pattern.quote(File.pathSeparator))) {
entries.add(File(entry))
}
return entries
}
public open fun getPathVar(): String {
return "PATH" return "PATH"
} }
@ -271,18 +265,18 @@ public abstract class OperatingSystem {
} }
companion object { companion object {
public val WINDOWS: Windows = Windows() val WINDOWS: Windows = Windows()
public val MAC_OS: MacOs = MacOs() val MAC_OS: MacOs = MacOs()
public val SOLARIS: Solaris = Solaris() val SOLARIS: Solaris = Solaris()
public val LINUX: Linux = Linux() val LINUX: Linux = Linux()
public val FREE_BSD: FreeBSD = FreeBSD() val FREE_BSD: FreeBSD = FreeBSD()
public val UNIX: Unix = Unix() val UNIX: Unix = Unix()
public fun current(): OperatingSystem { fun current(): OperatingSystem {
return forName(System.getProperty("os.name")) return forName(System.getProperty("os.name"))
} }
public fun forName(os: String): OperatingSystem { fun forName(os: String): OperatingSystem {
val osName = os.toLowerCase() val osName = os.toLowerCase()
if (osName.contains("windows")) { if (osName.contains("windows")) {
return WINDOWS return WINDOWS