Interface Machine

All Superinterfaces:
Comparable<Machine>
All Known Subinterfaces:
LinuxMachine

public interface Machine extends Comparable<Machine>
Represents combined aspects of a computer that can affect binary compatibility.

Machines define a small string serialization of the form osname.cpuname, as generated by toString() and parsed by parse(String). Machines sort according to their string representation. Subtypes like LinuxMachine may extend this string encoding to incorporate more detail.

  • Field Details

    • LINUX_AMD64

      static final LinuxMachine LINUX_AMD64
      An immutable LinuxMachine with no distribution domain, AMD64 and glibc.
    • LINUX_AARCH64

      static final LinuxMachine LINUX_AARCH64
      An immutable LinuxMachine with no distribution domain, AARCH64 and glibc.
    • LINUX_AMD64_MUSLC

      static final LinuxMachine LINUX_AMD64_MUSLC
      An immutable LinuxMachine with no distribution domain, AMD64 and muslc.
    • LINUX_AARCH64_MUSLC

      static final LinuxMachine LINUX_AARCH64_MUSLC
      An immutable LinuxMachine with no distribution domain, AARCH64 and muslc.
    • MACOS_AMD64

      static final Machine MACOS_AMD64
      An immutable Machine with macOS on AMD64.
    • MACOS_AARCH64

      static final Machine MACOS_AARCH64
      An immutable Machine with macOS on AARCH64.
    • WINDOWS_AMD64

      static final Machine WINDOWS_AMD64
      An immutable Machine with Windows on AMD64.
    • WINDOWS_AARCH64

      static final Machine WINDOWS_AARCH64
      An immutable Machine with Windows on AARCH64.
  • Method Details

    • getOS

      The operating system, without version information.
    • getCPU

      CPUArchitecture getCPU()
      The CPU architecture.
    • of

      static Machine of(OperatingSystem os, CPUArchitecture cpu)
      Returns an object that implements Machine and possibly LinuxMachine (defaulting to glibc as the C library and no distribution domain), given the specified operating system and CPU architecture.
    • parse

      static Machine parse(String spec)
      Converts a string to a machine spec by parsing it in a lenient manner. The string is split into components using the `.` separator, then the first component is matched against the OS and the second against the CPU architecture. If the OS is Linux then the third (if present) may be a C library and the remaining components are reversed DNS components of the distribution website.

      Because a Machine must specify a CPU architecture, if the string form doesn't then a default is picked based on the dominant OS type used on that platform, or if no such type is known then [CPUArchitectures.UNKNOWN] is used:

      - Linux, Windows: AMD64 - Android, any Apple OS including macOS: AARCH64 - Others: UNKNOWN

      Throws:
      IllegalArgumentException - if any component isn't a recognized name or alias.
    • parseAll

      static Set<Machine> parseAll(String spec, boolean supported)

      Converts a string to a machine spec by parsing it in a lenient manner. The string is split into components using the `.` separator, then the first component is matched against the OS and the second against the CPU architecture. If the OS is Linux then the third (if present) may be a C library and the remaining components are reversed DNS components of the distribution website.

      Unlike parse(String), missing components will be expanded to all known CPU architectures and C libraries. An empty string will yield an empty result. The special string "*" will yield a result with all known operating systems and CPU architectures.

      If supported is set to true, combinations that don't represent machines actually in use are excluded. For example parseAll("mac", true) won't return results with CPUArchitectures.RISCV included, because (at the time of writing) there is no Mac with a RISC-V chip and probably there never will be. Windows is likewise taken to only support AMD64, x86 and AARCH64, although other combinations have been used in the past. Free UNIXes like Linux, FreeBSD etc are assumed to support every possible CPU architecture, and Linux is assumed to support every CPU architure and C library in combination. Please note that this support matrix isn't guaranteed to be 100% correct, especially as a release of the library ages.

      Parameters:
      spec - The input to expand.
      supported - Whether to only include combinations that were known to actually be in use at the time of the release of this library.
      Returns:
      An unordered set of all known machines that match the input.
    • current

      static Machine current()
      Returns a machine representing the currently executing JVM's environment, based on reading system properties and file paths. This is currently capable of detecting Windows, Mac and Linux but other operating systems will be detected as OperatingSystems.UNKNOWN. The C library for Linux hosts is detected by looking for /lib/libc.musl-x86_64.so.1.