Hello, Obtaining OS/Arch information dynamically is a known need in many applications. However, there is no standard API for doing so. As a result, libraries and applications came up with their own ways to fill the gap, whether internal or API. Some examples:
* Apache Commons Lang: arch[0] and OS[1] * Gradle: arch[2] and OS[3] * Google's Gradle plugin arch and OS[4] * Maven OS[5] * JavaFX OS[6] and OS and arch in its build[7] * jextract OS[8] Perhaps the most telling evidence comes from the SO questions on how to find the OS[9][10] and arch[11] (an in-depth one). While they all rely on System.getProperty, each has its own parsing scheme, and some do it better than others. Some search for "darwin" for macOS; some search for "nix", "nux" and "aix" for Linux; some do a minimal effort. The JDK already has (at least one) internal API for OS[12], version[13] and arch[14]. I suggest that the JDK provide a standard extendible API that all consumers can use since it is at the best position to know what values its string-y properties can mean. At the very least, detecting MacOS, Linux, and Windows OS's, and AMD64 and Aarch64 archs will solve the vast majority of cases as these are the platforms the JDK builds for[15]. Is this a conceptually acceptable addition to the JDK? Best, Nir [0] https://commons.apache.org/proper/commons-lang/apidocs/org/apache/commons/lang3/arch/package-summary.html [1] OS: https://commons.apache.org/proper/commons-lang/apidocs/org/apache/commons/lang3/SystemUtils.html [2] https://docs.gradle.org/current/javadoc/org/gradle/nativeplatform/platform/Architecture.html [3] https://docs.gradle.org/current/javadoc/org/gradle/nativeplatform/platform/OperatingSystem.html [4] https://github.com/google/osdetector-gradle-plugin [5] https://github.com/apache/maven/blob/e7e3d149c826b6f6cda4bf8fc5e1ac55f6ff4935/impl/maven-impl/src/main/java/org/apache/maven/impl/util/Os.java [6] https://github.com/openjdk/jfx/blob/c4917c1dcb3475444d1b4f49d1c049b19524634b/modules/javafx.base/src/main/java/com/sun/javafx/PlatformUtil.java#L56 [7] https://github.com/openjdk/jfx/blob/c4917c1dcb3475444d1b4f49d1c049b19524634b/build.gradle#L352 [8] https://github.com/openjdk/jextract/blob/1e6737c22376fe66986a20837135699b9cf692d2/test/lib/testlib/JextractToolRunner.java#L56 [9] https://stackoverflow.com/questions/228477/how-do-i-programmatically-determine-operating-system-in-java [10] https://stackoverflow.com/questions/2357758/what-does-system-getpropertyos-name-return-in-latest-windows-oss [11] https://stackoverflow.com/questions/10846105/all-possible-values-os-arch-in-32bit-jre-and-in-64bit-jre [12] https://github.com/openjdk/jdk/blob/master/src/java.base/share/classes/jdk/internal/util/OperatingSystem.java [13] https://github.com/openjdk/jdk/blob/master/src/java.base/share/classes/jdk/internal/util/OSVersion.java [14] https://github.com/openjdk/jdk/blob/master/src/java.base/share/classes/jdk/internal/util/Architecture.java [15] https://jdk.java.net/archive/
