This message was deleted.
# community-support
s
This message was deleted.
c
Nothing built into Gradle; here is what I typically use (covers Windows, MacOS, Linux - other OSs not supported, though that could be added).
Copy code
/**
 * Represents an Operating System for the purposes of build script usage.
 */
sealed class Os(private val name: String) {
    companion object {
        val current by lazy {
            val osName = SystemProperty.OsName.requiredValue.lowercase()
            when {
                osName.contains("windows") -> Windows
                osName.contains("mac os x") || osName.contains("darwin") || osName.contains("osx") -> Unix.MacOs
                osName.contains("linux") -> Unix.Linux
                else -> error("Unknown operating system: $osName")
            }
        }
    }

    object Predicates {
        val Unix : (Os) -> Boolean = { os -> os is Unix }
        val Windows : (Os) -> Boolean = { os -> os is Windows }
    }

    open val pathSeparator = ":"
    open val executableExtension = ""

    override fun toString(): String {
        return "Os(name='$name')"
    }

    data object Windows : Os("Windows") {
        override val executableExtension = ".exe"
        override val pathSeparator = ";"
    }

    sealed class Unix(name : String) : Os(name) {
        data object Linux : Unix("Linux")
        data object MacOs : Unix("MacOS")
    }
}
e
Gradle itself does basically the same thing but includes sunos/solaris and freebsd
v
Ant is a first-class citizen, so just use its classes
Copy code
import org.apache.tools.ant.taskdefs.condition.Os

Os.isFamily(Os.FAMILY_WINDOWS)
...
e
Odd, I tried that before, but the IDE wasn't resolving
Os
. Putting in the FQN worked though. Thanks!
👌 1
v
If you do it in Groovy DSL, it often happens that the imports are partly colored red while actually working
e
It was with the Kotlin DSL. I tried again in another IDE and it took a few seconds for it to show up. Maybe an indexing issue
👌 1