1 /*
2 * Copyright (c) 2000, 2020, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 *
33 String os = System.getProperty("os.name");
34 if (os.equals("Linux")) {
35 return "linux";
36 } else if (os.equals("FreeBSD")) {
37 return "bsd";
38 } else if (os.equals("NetBSD")) {
39 return "bsd";
40 } else if (os.equals("OpenBSD")) {
41 return "bsd";
42 } else if (os.contains("Darwin") || os.contains("OS X")) {
43 return "darwin";
44 } else if (os.startsWith("Windows")) {
45 return "win32";
46 } else {
47 throw new UnsupportedPlatformException("Operating system " + os + " not yet supported");
48 }
49 }
50
51 public static boolean knownCPU(String cpu) {
52 final String[] KNOWN =
53 new String[] {"i386", "x86", "x86_64", "amd64", "ppc64", "ppc64le", "aarch64"};
54
55 for(String s : KNOWN) {
56 if(s.equals(cpu))
57 return true;
58 }
59
60 return false;
61 }
62
63 /* Returns "x86" for x86 based platforms and x86_64 for 64bit x86
64 based platform. Otherwise returns the value of os.arch. If the
65 value is not recognized as supported, an exception is thrown
66 instead. */
67
68 public static String getCPU() throws UnsupportedPlatformException {
69 String cpu = System.getProperty("os.arch");
70
71 // Check that CPU is supported
72 if (!knownCPU(cpu)) {
73 throw new UnsupportedPlatformException("CPU type " + cpu + " not yet supported");
|
1 /*
2 * Copyright (c) 2000, 2022, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 *
33 String os = System.getProperty("os.name");
34 if (os.equals("Linux")) {
35 return "linux";
36 } else if (os.equals("FreeBSD")) {
37 return "bsd";
38 } else if (os.equals("NetBSD")) {
39 return "bsd";
40 } else if (os.equals("OpenBSD")) {
41 return "bsd";
42 } else if (os.contains("Darwin") || os.contains("OS X")) {
43 return "darwin";
44 } else if (os.startsWith("Windows")) {
45 return "win32";
46 } else {
47 throw new UnsupportedPlatformException("Operating system " + os + " not yet supported");
48 }
49 }
50
51 public static boolean knownCPU(String cpu) {
52 final String[] KNOWN =
53 new String[] {"i386", "x86", "x86_64", "amd64", "ppc64", "ppc64le", "aarch64", "riscv64"};
54
55 for(String s : KNOWN) {
56 if(s.equals(cpu))
57 return true;
58 }
59
60 return false;
61 }
62
63 /* Returns "x86" for x86 based platforms and x86_64 for 64bit x86
64 based platform. Otherwise returns the value of os.arch. If the
65 value is not recognized as supported, an exception is thrown
66 instead. */
67
68 public static String getCPU() throws UnsupportedPlatformException {
69 String cpu = System.getProperty("os.arch");
70
71 // Check that CPU is supported
72 if (!knownCPU(cpu)) {
73 throw new UnsupportedPlatformException("CPU type " + cpu + " not yet supported");
|