1515 */
1616package com .diffplug .common .swt .os ;
1717
18-
1918import java .io .ByteArrayOutputStream ;
2019import java .io .IOException ;
2120import java .io .InputStream ;
2726
2827/** Enum representing an OS and its underlying CPU architecture. */
2928public enum OS {
30- WIN_x64 , WIN_x86 , LINUX_x64 , LINUX_x86 , MAC_x64 , MAC_silicon ;
29+ WIN_x64 , WIN_x86 , LINUX_x64 , LINUX_x86 , MAC_x64 , MAC_silicon , WIN_unknown , LINUX_unknown , MAC_unknown ;
3130
3231 public boolean isWindows () {
33- return this == WIN_x64 || this == WIN_x86 ;
32+ return this == WIN_x64 || this == WIN_x86 || this == WIN_unknown ;
3433 }
3534
3635 public boolean isLinux () {
37- return this == LINUX_x64 || this == LINUX_x86 ;
36+ return this == LINUX_x64 || this == LINUX_x86 || this == LINUX_unknown ;
3837 }
3938
4039 public boolean isMac () {
41- return this == MAC_x64 || this == MAC_silicon ;
40+ return this == MAC_x64 || this == MAC_silicon || this == MAC_unknown ;
4241 }
4342
4443 public boolean isMacOrLinux () {
@@ -70,6 +69,10 @@ public Arch getArch() {
7069 return Arch .x86 ;
7170 case MAC_silicon :
7271 return Arch .arm64 ;
72+ case WIN_unknown :
73+ case MAC_unknown :
74+ case LINUX_unknown :
75+ return Arch .unknown ;
7376 default :
7477 throw unsupportedException (this );
7578 }
@@ -82,7 +85,7 @@ public String os() {
8285
8386 /** SWT-style x86/x86_64 */
8487 public String arch () {
85- return getArch ().x86x64arm64 ("x86" , "x86_64" , "aarch64" );
88+ return getArch ().x86x64arm64unknown ("x86" , "x86_64" , "aarch64" , "unknown " );
8689 }
8790
8891 /** os().arch() */
@@ -92,7 +95,7 @@ public String osDotArch() {
9295
9396 /** windowing.os.arch */
9497 public String toSwt () {
95- return winMacLinux ( "win32" , "cocoa" , "gtk" ) + "." + winMacLinux ( "win32" , "macosx" , "linux" ) + "." + getArch (). x86x64arm64 ( "x86" , "x86_64" , "aarch64" );
98+ return SwtPlatform . fromOS ( this ). toString ( );
9699 }
97100
98101 /** Returns the native OS: 32-bit JVM on 64-bit Windows returns OS.WIN_64. */
@@ -144,7 +147,7 @@ private static OS calculateNative(Function<String, String> systemProperty, Funct
144147 case "amd64" :
145148 return LINUX_x64 ;
146149 default :
147- throw new IllegalArgumentException ( "Unknown os.arch " + os_arch + "'." ) ;
150+ return LINUX_unknown ;
148151 }
149152 } else {
150153 throw new IllegalArgumentException ("Unknown os.name '" + os_name + "'." );
@@ -175,14 +178,10 @@ private static void drain(InputStream input, OutputStream output) throws IOExcep
175178 /** Calculates the running OS. */
176179 private static OS calculateRunning (Function <String , String > systemProperty ) {
177180 Arch runningArch = runningJvm (systemProperty );
178- OS runningOs = NATIVE_OS .winMacLinux (
179- runningArch .x86x64arm64 (OS .WIN_x86 , OS .WIN_x64 , null ),
180- runningArch .x86x64arm64 (null , OS .MAC_x64 , OS .MAC_silicon ),
181- runningArch .x86x64arm64 (OS .LINUX_x86 , OS .LINUX_x64 , null ));
182- if (runningOs == null ) {
183- throw new IllegalArgumentException ("Unsupported OS/Arch combo: " + runningOs + " " + runningArch );
184- }
185- return runningOs ;
181+ return NATIVE_OS .winMacLinux (
182+ runningArch .x86x64arm64unknown (OS .WIN_x86 , OS .WIN_x64 , OS .WIN_unknown , OS .WIN_unknown ),
183+ runningArch .x86x64arm64unknown (OS .MAC_unknown , OS .MAC_x64 , OS .MAC_silicon , OS .MAC_unknown ),
184+ runningArch .x86x64arm64unknown (OS .LINUX_x86 , OS .LINUX_x64 , OS .LINUX_unknown , OS .LINUX_unknown ));
186185 }
187186
188187 /** Returns the arch of the currently running JVM. */
@@ -194,7 +193,7 @@ private static Arch runningJvm(Function<String, String> systemProperty) {
194193 case "64" :
195194 return "aarch64" .equals (systemProperty .apply ("os.arch" )) ? Arch .arm64 : Arch .x64 ;
196195 default :
197- throw new IllegalArgumentException ( "Expcted 32 or 64, was " + sunArchDataModel ) ;
196+ return Arch . unknown ;
198197 }
199198 }
200199
0 commit comments