15
15
*/
16
16
package com .diffplug .common .swt .os ;
17
17
18
-
19
18
import java .io .ByteArrayOutputStream ;
20
19
import java .io .IOException ;
21
20
import java .io .InputStream ;
27
26
28
27
/** Enum representing an OS and its underlying CPU architecture. */
29
28
public 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 ;
31
30
32
31
public boolean isWindows () {
33
- return this == WIN_x64 || this == WIN_x86 ;
32
+ return this == WIN_x64 || this == WIN_x86 || this == WIN_unknown ;
34
33
}
35
34
36
35
public boolean isLinux () {
37
- return this == LINUX_x64 || this == LINUX_x86 ;
36
+ return this == LINUX_x64 || this == LINUX_x86 || this == LINUX_unknown ;
38
37
}
39
38
40
39
public boolean isMac () {
41
- return this == MAC_x64 || this == MAC_silicon ;
40
+ return this == MAC_x64 || this == MAC_silicon || this == MAC_unknown ;
42
41
}
43
42
44
43
public boolean isMacOrLinux () {
@@ -70,6 +69,10 @@ public Arch getArch() {
70
69
return Arch .x86 ;
71
70
case MAC_silicon :
72
71
return Arch .arm64 ;
72
+ case WIN_unknown :
73
+ case MAC_unknown :
74
+ case LINUX_unknown :
75
+ return Arch .unknown ;
73
76
default :
74
77
throw unsupportedException (this );
75
78
}
@@ -82,7 +85,7 @@ public String os() {
82
85
83
86
/** SWT-style x86/x86_64 */
84
87
public String arch () {
85
- return getArch ().x86x64arm64 ("x86" , "x86_64" , "aarch64" );
88
+ return getArch ().x86x64arm64unknown ("x86" , "x86_64" , "aarch64" , "unknown " );
86
89
}
87
90
88
91
/** os().arch() */
@@ -92,7 +95,7 @@ public String osDotArch() {
92
95
93
96
/** windowing.os.arch */
94
97
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 ( );
96
99
}
97
100
98
101
/** 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
144
147
case "amd64" :
145
148
return LINUX_x64 ;
146
149
default :
147
- throw new IllegalArgumentException ( "Unknown os.arch " + os_arch + "'." ) ;
150
+ return LINUX_unknown ;
148
151
}
149
152
} else {
150
153
throw new IllegalArgumentException ("Unknown os.name '" + os_name + "'." );
@@ -175,14 +178,10 @@ private static void drain(InputStream input, OutputStream output) throws IOExcep
175
178
/** Calculates the running OS. */
176
179
private static OS calculateRunning (Function <String , String > systemProperty ) {
177
180
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 ));
186
185
}
187
186
188
187
/** Returns the arch of the currently running JVM. */
@@ -194,7 +193,7 @@ private static Arch runningJvm(Function<String, String> systemProperty) {
194
193
case "64" :
195
194
return "aarch64" .equals (systemProperty .apply ("os.arch" )) ? Arch .arm64 : Arch .x64 ;
196
195
default :
197
- throw new IllegalArgumentException ( "Expcted 32 or 64, was " + sunArchDataModel ) ;
196
+ return Arch . unknown ;
198
197
}
199
198
}
200
199
0 commit comments