@@ -215,59 +215,86 @@ public boolean showSettingsDialog(AppSettings settings, boolean loadFromRegistry
215215 }
216216
217217
218- private boolean is64Bit (String arch ) {
219- if (arch .equals ("x86" )) {
220- return false ;
221- } else if (arch .equals ("amd64" )) {
222- return true ;
223- } else if (arch .equals ("x86_64" )) {
224- return true ;
225- } else if (arch .equals ("ppc" ) || arch .equals ("PowerPC" )) {
226- return false ;
227- } else if (arch .equals ("ppc64" )) {
228- return true ;
229- } else if (arch .equals ("i386" ) || arch .equals ("i686" )) {
230- return false ;
231- } else if (arch .equals ("universal" )) {
232- return false ;
233- } else if (arch .equals ("aarch32" )) {
234- return false ;
235- } else if (arch .equals ("aarch64" )) {
236- return true ;
237- } else if (arch .equals ("armv7" ) || arch .equals ("armv7l" )) {
238- return false ;
239- } else if (arch .equals ("arm" )) {
240- return false ;
241- } else {
242- throw new UnsupportedOperationException ("Unsupported architecture: " + arch );
218+ private boolean is64Bit (String arch ) {
219+ switch (arch ) {
220+ case "amd64" :
221+ case "x86_64" :
222+ case "aarch64" :
223+ case "arm64" :
224+ case "ppc64" :
225+ case "universal" :
226+ return true ;
227+ case "x86" :
228+ case "i386" :
229+ case "i686" :
230+ case "aarch32" :
231+ case "arm" :
232+ case "armv7" :
233+ case "armv7l" :
234+ return false ;
235+ default :
236+ throw new UnsupportedOperationException ("Unsupported architecture: " + arch );
237+ }
238+ }
239+
240+ private boolean isArmArchitecture (String arch ) {
241+ return arch .startsWith ("arm" ) || arch .startsWith ("aarch" );
242+ }
243+
244+ private boolean isX86Architecture (String arch ) {
245+ return arch .equals ("x86" )
246+ || arch .equals ("amd64" )
247+ || arch .equals ("x86_64" )
248+ || arch .equals ("i386" )
249+ || arch .equals ("i686" )
250+ || arch .equals ("universal" );
251+ }
252+
253+ private UnsupportedOperationException unsupported32Bit (String osName ) {
254+ return new UnsupportedOperationException ("32-bit " + osName + " is not supported." );
255+ }
256+
257+ private Platform getWindowsPlatform (String arch , boolean is64 ) {
258+ if (!is64 ) {
259+ // no 32-bit version
260+ throw unsupported32Bit ("Windows" );
243261 }
262+ if (isArmArchitecture (arch )) return Platform .Windows_ARM64 ;
263+ if (isX86Architecture (arch )) return Platform .Windows64 ;
264+ throw new UnsupportedOperationException ("Unsupported architecture: " + arch );
265+ }
266+
267+ private Platform getLinuxPlatform (String arch , boolean is64 ) {
268+ if (!is64 ) {
269+ // no 32-bit version
270+ throw unsupported32Bit ("Linux" );
271+ }
272+ if (isArmArchitecture (arch )) return Platform .Linux_ARM64 ;
273+ if (isX86Architecture (arch )) return Platform .Linux64 ;
274+ throw new UnsupportedOperationException ("Unsupported architecture: " + arch );
275+ }
276+
277+ private Platform getMacPlatform (String arch , boolean is64 ) {
278+ if (!is64 ) {
279+ // no 32-bit version
280+ throw unsupported32Bit ("macOS" );
281+ }
282+ if (isArmArchitecture (arch )) return Platform .MacOSX_ARM64 ;
283+ if (isX86Architecture (arch )) return Platform .MacOSX64 ;
284+ throw new UnsupportedOperationException ("Unsupported architecture: " + arch );
244285 }
245286
246287 public Platform getPlatform () {
247288 String os = System .getProperty ("os.name" ).toLowerCase ();
248289 String arch = System .getProperty ("os.arch" ).toLowerCase ();
249290 boolean is64 = is64Bit (arch );
250291 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- }
292+ return getWindowsPlatform (arch , is64 );
256293 } else if (os .contains ("linux" ) || os .contains ("freebsd" )
257294 || 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- }
295+ return getLinuxPlatform (arch , is64 );
263296 } 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- }
297+ return getMacPlatform (arch , is64 );
271298 } else {
272299 throw new UnsupportedOperationException ("The specified platform: " + os + " is not supported." );
273300 }
0 commit comments