-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Expand file tree
/
Copy pathTest.java
More file actions
147 lines (116 loc) · 3.5 KB
/
Test.java
File metadata and controls
147 lines (116 loc) · 3.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
import java.io.File;
import java.nio.file.FileSystems;
import java.nio.file.Path;
import org.apache.commons.lang3.SystemUtils;
public class Test {
/**
* Should only be called on windows
*/
private void onlyOnWindows() {}
/**
* Should only be called on unix-like systems
*/
private void onlyOnUnix() {}
void testWindows() {
if (System.getProperty("os.name").contains("Windows")) {
onlyOnWindows();
}
if (System.getProperty("os.name").toLowerCase().contains("windows")) {
onlyOnWindows();
}
if (System.getProperty("os.name").toLowerCase().contains("window")) {
onlyOnWindows();
}
if (System.getProperty("os.name").toUpperCase().contains("WINDOWS")) {
onlyOnWindows();
}
if (SystemUtils.IS_OS_WINDOWS) {
onlyOnWindows();
} else {
onlyOnUnix();
}
if (SystemUtils.IS_OS_WINDOWS_XP) {
onlyOnWindows();
} else {
// Might be another version of windows
}
if (File.pathSeparatorChar == ';') {
onlyOnWindows();
}
if (File.pathSeparator == ";") {
onlyOnWindows();
}
if (File.separatorChar == '\\') {
onlyOnWindows();
}
if (File.separator == "\\") {
onlyOnWindows();
}
if (System.getProperty("path.separator").equals(";")) {
onlyOnWindows();
}
}
void testUnix() {
if (Path.of("whatever").getFileSystem().supportedFileAttributeViews().contains("posix")) {
onlyOnUnix();
}
if (FileSystems.getDefault().supportedFileAttributeViews().contains("posix")) {
onlyOnUnix();
}
if (SystemUtils.IS_OS_UNIX) {
onlyOnUnix();
} else {
// Reasonable assumption, maybe not 100% accurate, but it's 'good enough'
onlyOnWindows();
}
if (File.pathSeparatorChar == ':') {
onlyOnUnix();
}
if (File.pathSeparator == ":") {
onlyOnUnix();
}
if (File.separatorChar == '/') {
onlyOnUnix();
}
if (File.separator == "/") {
onlyOnUnix();
}
if (System.getProperty("path.separator").equals(":")) {
onlyOnUnix();
}
}
void testLinux() {
if (System.getProperty("os.name").toLowerCase().contains("linux")) {
onlyOnUnix();
}
if (System.getProperty("os.name").contains("Linux")) {
onlyOnUnix();
}
if (SystemUtils.IS_OS_LINUX) {
onlyOnUnix();
} else {
// Might be another different unix-like system, so this can't be `onlyOnWindows()`.
}
if (!SystemUtils.IS_OS_LINUX) {
// Might be another different unix-like system, so this can't be `onlyOnWindows()`.
} else {
onlyOnUnix();
}
}
void testMacOs() {
if (System.getProperty("os.name").contains("Mac OS X")) {
onlyOnUnix();
}
if (System.getProperty("os.name").toLowerCase().contains("mac")) {
onlyOnUnix();
}
if (SystemUtils.IS_OS_MAC) {
onlyOnUnix();
} else {
// Can't assume this is windows, it could be another unix-like OS
}
if (SystemUtils.IS_OS_MAC_OSX_MOJAVE) {
onlyOnUnix();
}
}
}