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 and getNativePrefix methods. (A scan of the Gradle 3.2.1 codebase seem to yield no usage either).

  • No public static fields called WINDOWS, MACOSX etc. These are now a static field called INSTANCE on each of the specific operating system implementations.

  • getSharedLibrarySuffix and getSharedLibraryName have been added.

  • Support for NetBSD.

  • getHomeVar to get the name of the environment variable for home directories.

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.2.5 to determine an operating system is

if (OS_NAME.contains('windows')) {
    Windows.INSTANCE
} else if (OS_NAME.contains('mac os x') || OS_NAME.contains('darwin') || OS_NAME.contains('osx')) {
    MacOsX.INSTANCE
} else if (OS_NAME.contains('linux')) {
    Linux.INSTANCE
} else if (OS_NAME.contains('freebsd')) {
    FreeBSD.INSTANCE
} else if (OS_NAME.contains('sunos') || OS_NAME.contains('solaris')) {
    Solaris.INSTANCE
} else if (OS_NAME.contains('netbsd')) {
    NetBSD.INSTANCE
} else {
    // Not strictly true, but a good guess
    GenericUnix.INSTANCE
}

Contributing fixes

Found a bug or need a method? Please raise an issue and preferably provide a pull request with features implemented for all supported operating systems.