1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.maven.utils;
20
21 import java.io.File;
22 import java.util.Locale;
23 import java.util.stream.Stream;
24
25
26
27
28
29
30 @Deprecated(since = "4.0.0")
31 public class Os {
32
33
34
35
36 public static final String OS_NAME = System.getProperty("os.name").toLowerCase(Locale.ENGLISH);
37
38
39
40
41 public static final String OS_ARCH = System.getProperty("os.arch").toLowerCase(Locale.ENGLISH);
42
43
44
45
46 public static final String OS_VERSION = System.getProperty("os.version").toLowerCase(Locale.ENGLISH);
47
48
49
50
51 public static final String OS_FAMILY;
52
53
54
55
56 public static final boolean IS_WINDOWS;
57
58
59
60
61 private static final String FAMILY_WINDOWS = "windows";
62
63
64
65
66 private static final String FAMILY_WIN9X = "win9x";
67
68
69
70
71 public static final String FAMILY_NT = "winnt";
72
73
74
75
76 private static final String FAMILY_OS2 = "os/2";
77
78
79
80
81 private static final String FAMILY_NETWARE = "netware";
82
83
84
85
86 private static final String FAMILY_DOS = "dos";
87
88
89
90
91 private static final String FAMILY_MAC = "mac";
92
93
94
95
96 private static final String FAMILY_TANDEM = "tandem";
97
98
99
100
101 private static final String FAMILY_UNIX = "unix";
102
103
104
105
106 private static final String FAMILY_OPENVMS = "openvms";
107
108
109
110
111 private static final String FAMILY_ZOS = "z/os";
112
113
114
115
116 private static final String FAMILY_OS390 = "os/390";
117
118
119
120
121 private static final String FAMILY_OS400 = "os/400";
122
123
124
125
126
127
128
129 private static final String DARWIN = "darwin";
130
131 static {
132
133
134
135 OS_FAMILY = getOsFamily();
136 IS_WINDOWS = isFamily(FAMILY_WINDOWS);
137 }
138
139 private Os() {}
140
141
142
143
144
145
146
147
148
149 public static boolean isFamily(String family) {
150 return isFamily(family, OS_NAME);
151 }
152
153
154
155
156
157
158
159
160
161
162 public static boolean isFamily(String family, String actualOsName) {
163
164 boolean isWindows = actualOsName.contains(FAMILY_WINDOWS);
165 boolean is9x = false;
166 boolean isNT = false;
167 if (isWindows) {
168
169 is9x = (actualOsName.contains("95")
170 || actualOsName.contains("98")
171 || actualOsName.contains("me")
172
173
174 || actualOsName.contains("ce"));
175 isNT = !is9x;
176 }
177 switch (family) {
178 case FAMILY_WINDOWS:
179 return isWindows;
180 case FAMILY_WIN9X:
181 return isWindows && is9x;
182 case FAMILY_NT:
183 return isWindows && isNT;
184 case FAMILY_OS2:
185 return actualOsName.contains(FAMILY_OS2);
186 case FAMILY_NETWARE:
187 return actualOsName.contains(FAMILY_NETWARE);
188 case FAMILY_DOS:
189 return File.pathSeparatorChar == ';' && !isFamily(FAMILY_NETWARE, actualOsName) && !isWindows;
190 case FAMILY_MAC:
191 return actualOsName.contains(FAMILY_MAC) || actualOsName.contains(DARWIN);
192 case FAMILY_TANDEM:
193 return actualOsName.contains("nonstop_kernel");
194 case FAMILY_UNIX:
195 return File.pathSeparatorChar == ':'
196 && !isFamily(FAMILY_OPENVMS, actualOsName)
197 && (!isFamily(FAMILY_MAC, actualOsName) || actualOsName.endsWith("x"));
198 case FAMILY_ZOS:
199 return actualOsName.contains(FAMILY_ZOS) || actualOsName.contains(FAMILY_OS390);
200 case FAMILY_OS400:
201 return actualOsName.contains(FAMILY_OS400);
202 case FAMILY_OPENVMS:
203 return actualOsName.contains(FAMILY_OPENVMS);
204 default:
205 return actualOsName.contains(family.toLowerCase(Locale.US));
206 }
207 }
208
209
210
211
212
213
214 private static String getOsFamily() {
215 return Stream.of(
216 FAMILY_DOS,
217 FAMILY_MAC,
218 FAMILY_NETWARE,
219 FAMILY_NT,
220 FAMILY_OPENVMS,
221 FAMILY_OS2,
222 FAMILY_OS400,
223 FAMILY_TANDEM,
224 FAMILY_UNIX,
225 FAMILY_WIN9X,
226 FAMILY_WINDOWS,
227 FAMILY_ZOS)
228 .filter(Os::isFamily)
229 .findFirst()
230 .orElse(null);
231 }
232 }