Operating System
Many plugin developers are familiar with the OperatingSystem
internal API in Gradle. Unfortunately this remains an internal API and is subject to change.
Grolifant offers a similar public API with a small number of API differences:
-
No
getFamilyName
andgetNativePrefix
methods. (A scan of the Gradle3.2.1
codebase seem to yield to usage either). -
No public static fields called
WINDOWS
,MACOSX
etc. These are now a static field calledINSTANCE
on each of the specific operating system implementations. -
getSharedLibrarySuffix
andgetSharedLibraryName
have been added. -
Support for NetBSD.
Example
OperatingSystem os = OperatingSystem.current() (1)
File findExe = os.findInPath('bash')
File findExe = os.findInPath('bash')
1 | Use current() to the operating system the code is being executed upon. |
Operating system detection
The logic in 5.0.0 to determine an operating system is
static OperatingSystem current() {
if (OS_NAME.contains('windows')) {
return org.ysb33r.grolifant5.api.core.os.Windows.INSTANCE
} else if (OS_NAME.contains('mac os x') || OS_NAME.contains('darwin') || OS_NAME.contains('osx')) {
return org.ysb33r.grolifant5.api.core.os.MacOsX.INSTANCE
} else if (OS_NAME.contains('linux')) {
return org.ysb33r.grolifant5.api.core.os.Linux.INSTANCE
} else if (OS_NAME.contains('freebsd')) {
return org.ysb33r.grolifant5.api.core.os.FreeBSD.INSTANCE
} else if (OS_NAME.contains('sunos') || OS_NAME.contains('solaris')) {
return org.ysb33r.grolifant5.api.core.os.Solaris.INSTANCE
} else if (OS_NAME.contains('netbsd')) {
return org.ysb33r.grolifant5.api.core.os.NetBSD.INSTANCE
}
// Not strictly true, but a good guess
org.ysb33r.grolifant5.api.core.os.GenericUnix.INSTANCE
}