@@ -215,9 +215,9 @@ public boolean showSettingsDialog(AppSettings settings, boolean loadFromRegistry
215215 }
216216
217217
218- private boolean is64Bit (String arch ) {
219- if (arch .equals ("x86" )) {
220- return false ;
218+ private boolean is64Bit (String arch ) {
219+ if (arch .equals ("x86" )) {
220+ return false ;
221221 } else if (arch .equals ("amd64" )) {
222222 return true ;
223223 } else if (arch .equals ("x86_64" )) {
@@ -240,37 +240,82 @@ private boolean is64Bit(String arch) {
240240 return false ;
241241 } else {
242242 throw new UnsupportedOperationException ("Unsupported architecture: " + arch );
243- }
244- }
245-
246- public Platform getPlatform () {
247- String os = System .getProperty ("os.name" ).toLowerCase ();
248- String arch = System .getProperty ("os.arch" ).toLowerCase ();
249- boolean is64 = is64Bit (arch );
250- if (os .contains ("windows" )) {
251- if (arch .startsWith ("arm" ) || arch .startsWith ("aarch" )) {
252- return is64 ? Platform .Windows_ARM64 : Platform .Windows_ARM32 ;
253- } else {
254- return is64 ? Platform .Windows64 : Platform .Windows32 ;
255- }
256- } else if (os .contains ("linux" ) || os .contains ("freebsd" )
257- || os .contains ("sunos" ) || os .contains ("unix" )) {
258- if (arch .startsWith ("arm" ) || arch .startsWith ("aarch" )) {
259- return is64 ? Platform .Linux_ARM64 : Platform .Linux_ARM32 ;
260- } else {
261- return is64 ? Platform .Linux64 : Platform .Linux32 ;
262- }
263- } else if (os .contains ("mac os x" ) || os .contains ("darwin" )) {
264- if (arch .startsWith ("ppc" )) {
265- return is64 ? Platform .MacOSX_PPC64 : Platform .MacOSX_PPC32 ;
266- } else if (arch .startsWith ("aarch" )) {
267- return Platform .MacOSX_ARM64 ; // no 32-bit version
268- } else {
269- return is64 ? Platform .MacOSX64 : Platform .MacOSX32 ;
270- }
271- } else {
272- throw new UnsupportedOperationException ("The specified platform: " + os + " is not supported." );
273- }
243+ }
244+ }
245+
246+ private boolean isArmArchitecture (String arch ) {
247+ return arch .startsWith ("arm" ) || arch .startsWith ("aarch" );
248+ }
249+
250+ private boolean isX86Architecture (String arch ) {
251+ return arch .equals ("x86" )
252+ || arch .equals ("amd64" )
253+ || arch .equals ("x86_64" )
254+ || arch .equals ("i386" )
255+ || arch .equals ("i686" )
256+ || arch .equals ("universal" );
257+ }
258+
259+ private UnsupportedOperationException unsupported32Bit (String osName ) {
260+ return new UnsupportedOperationException ("32-bit " + osName + " is not supported." );
261+ }
262+
263+ private Platform getWindowsPlatform (String arch , boolean is64 ) {
264+ if (isArmArchitecture (arch )) {
265+ if (!is64 ) {
266+ throw unsupported32Bit ("Windows" );
267+ }
268+ return Platform .Windows_ARM64 ;
269+ }
270+ if (isX86Architecture (arch )) {
271+ if (!is64 ) {
272+ throw unsupported32Bit ("Windows" );
273+ }
274+ return Platform .Windows64 ;
275+ }
276+ throw new UnsupportedOperationException ("Unsupported architecture: " + arch );
277+ }
278+
279+ private Platform getLinuxPlatform (String arch , boolean is64 ) {
280+ if (isArmArchitecture (arch )) {
281+ return is64 ? Platform .Linux_ARM64 : Platform .Linux_ARM32 ;
282+ }
283+ if (isX86Architecture (arch )) {
284+ if (!is64 ) {
285+ throw unsupported32Bit ("Linux" );
286+ }
287+ return Platform .Linux64 ;
288+ }
289+ throw new UnsupportedOperationException ("Unsupported architecture: " + arch );
290+ }
291+
292+ private Platform getMacPlatform (String arch , boolean is64 ) {
293+ if (arch .startsWith ("aarch" )) {
294+ return Platform .MacOSX_ARM64 ; // no 32-bit version
295+ }
296+ if (isX86Architecture (arch )) {
297+ if (!is64 ) {
298+ throw unsupported32Bit ("macOS" );
299+ }
300+ return Platform .MacOSX64 ;
301+ }
302+ throw new UnsupportedOperationException ("Unsupported architecture: " + arch );
303+ }
304+
305+ public Platform getPlatform () {
306+ String os = System .getProperty ("os.name" ).toLowerCase ();
307+ String arch = System .getProperty ("os.arch" ).toLowerCase ();
308+ boolean is64 = is64Bit (arch );
309+ if (os .contains ("windows" )) {
310+ return getWindowsPlatform (arch , is64 );
311+ } else if (os .contains ("linux" ) || os .contains ("freebsd" )
312+ || os .contains ("sunos" ) || os .contains ("unix" )) {
313+ return getLinuxPlatform (arch , is64 );
314+ } else if (os .contains ("mac os x" ) || os .contains ("darwin" )) {
315+ return getMacPlatform (arch , is64 );
316+ } else {
317+ throw new UnsupportedOperationException ("The specified platform: " + os + " is not supported." );
318+ }
274319 }
275320
276321 public String getBuildInfo () {
0 commit comments