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

if (OS_NAME.contains('windows')) {
    DefaultWindows.INSTANCE
} else if (OS_NAME.contains('mac os x') || OS_NAME.contains('darwin') || OS_NAME.contains('osx')) {
    DefaultMacOsX.INSTANCE
} else if (OS_NAME.contains('linux')) {
    DefaultLinux.INSTANCE
} else if (OS_NAME.contains('freebsd')) {
    DefaultFreeBSD.INSTANCE
} else if (OS_NAME.contains('sunos') || OS_NAME.contains('solaris')) {
    DefaultSolaris.INSTANCE
} else if (OS_NAME.contains('netbsd')) {
    DefaultNetBSD.INSTANCE
} else {
    // Not strictly true, but a good guess
    DefaultGenericUnix.INSTANCE
}

Access to other operating systems

If you need access to the information of an operating system other than the current, use the instance() method on the appropriate interface i.e.,

import org.ysb33r.grolifant5.api.core.os.Windows

final windows = Windows.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.