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