[12776] | 1 | // License: GPL. For details, see LICENSE file.
|
---|
| 2 | package org.openstreetmap.josm.tools;
|
---|
| 3 |
|
---|
| 4 | import java.util.Locale;
|
---|
| 5 |
|
---|
| 6 | /**
|
---|
| 7 | * Enum listing the supported platforms (operating system families).
|
---|
| 8 | * @since 12776
|
---|
| 9 | */
|
---|
| 10 | public enum Platform {
|
---|
| 11 |
|
---|
[12781] | 12 | /**
|
---|
| 13 | * Unik-like platform. This is the default when the platform cannot be identified.
|
---|
| 14 | */
|
---|
[12776] | 15 | UNIXOID {
|
---|
| 16 | @Override
|
---|
| 17 | public <T> T accept(PlatformVisitor<T> visitor) {
|
---|
| 18 | return visitor.visitUnixoid();
|
---|
| 19 | }
|
---|
| 20 | },
|
---|
[12781] | 21 | /**
|
---|
| 22 | * Windows platform.
|
---|
| 23 | */
|
---|
[12776] | 24 | WINDOWS {
|
---|
| 25 | @Override
|
---|
| 26 | public <T> T accept(PlatformVisitor<T> visitor) {
|
---|
| 27 | return visitor.visitWindows();
|
---|
| 28 | }
|
---|
| 29 | },
|
---|
[12781] | 30 | /**
|
---|
| 31 | * macOS (previously OS X) platform.
|
---|
| 32 | */
|
---|
[12776] | 33 | OSX {
|
---|
| 34 | @Override
|
---|
| 35 | public <T> T accept(PlatformVisitor<T> visitor) {
|
---|
| 36 | return visitor.visitOsx();
|
---|
| 37 | }
|
---|
| 38 | };
|
---|
| 39 |
|
---|
[12784] | 40 | private static volatile Platform platform;
|
---|
[12776] | 41 |
|
---|
| 42 | /**
|
---|
| 43 | * Support for the visitor pattern.
|
---|
| 44 | * @param <T> type that will be the result of the visiting operation
|
---|
| 45 | * @param visitor the visitor
|
---|
| 46 | * @return result of the operation
|
---|
| 47 | */
|
---|
| 48 | public abstract <T> T accept(PlatformVisitor<T> visitor);
|
---|
| 49 |
|
---|
| 50 | /**
|
---|
| 51 | * Identifies the current operating system family.
|
---|
| 52 | * @return the the current operating system family
|
---|
| 53 | */
|
---|
| 54 | public static Platform determinePlatform() {
|
---|
| 55 | if (platform == null) {
|
---|
[13647] | 56 | String os = Utils.getSystemProperty("os.name");
|
---|
[12776] | 57 | if (os == null) {
|
---|
| 58 | Logging.warn("Your operating system has no name, so I'm guessing its some kind of *nix.");
|
---|
| 59 | platform = Platform.UNIXOID;
|
---|
| 60 | } else if (os.toLowerCase(Locale.ENGLISH).startsWith("windows")) {
|
---|
| 61 | platform = Platform.WINDOWS;
|
---|
| 62 | } else if ("Linux".equals(os) || "Solaris".equals(os) ||
|
---|
| 63 | "SunOS".equals(os) || "AIX".equals(os) ||
|
---|
| 64 | "FreeBSD".equals(os) || "NetBSD".equals(os) || "OpenBSD".equals(os)) {
|
---|
| 65 | platform = Platform.UNIXOID;
|
---|
| 66 | } else if (os.toLowerCase(Locale.ENGLISH).startsWith("mac os x")) {
|
---|
| 67 | platform = Platform.OSX;
|
---|
| 68 | } else {
|
---|
| 69 | Logging.warn("I don't know your operating system '"+os+"', so I'm guessing its some kind of *nix.");
|
---|
| 70 | platform = Platform.UNIXOID;
|
---|
| 71 | }
|
---|
| 72 | }
|
---|
| 73 | return platform;
|
---|
| 74 | }
|
---|
| 75 |
|
---|
| 76 | }
|
---|