mirror of
https://github.com/github/codeql.git
synced 2026-04-29 10:45:15 +02:00
Java: Add Guard Classes for checking OS
This commit is contained in:
34
java/ql/test/library-tests/os/Test.java
Normal file
34
java/ql/test/library-tests/os/Test.java
Normal file
@@ -0,0 +1,34 @@
|
||||
import java.nio.file.FileSystems;
|
||||
import java.nio.file.Path;
|
||||
|
||||
public class Test {
|
||||
void test() {
|
||||
if (System.getProperty("os.name").contains("Windows")) {
|
||||
|
||||
}
|
||||
|
||||
if (System.getProperty("os.name").toLowerCase().contains("windows")) {
|
||||
|
||||
}
|
||||
|
||||
if (System.getProperty("os.name").contains("Linux")) {
|
||||
|
||||
}
|
||||
|
||||
if (System.getProperty("os.name").contains("Mac OS X")) {
|
||||
|
||||
}
|
||||
|
||||
if (System.getProperty("os.name").toLowerCase().contains("mac")) {
|
||||
|
||||
}
|
||||
|
||||
if (Path.of("whatever").getFileSystem().supportedFileAttributeViews().contains("posix")) {
|
||||
|
||||
}
|
||||
|
||||
if (FileSystems.getDefault().supportedFileAttributeViews().contains("posix")) {
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
5
java/ql/test/library-tests/os/unix-test.expected
Normal file
5
java/ql/test/library-tests/os/unix-test.expected
Normal file
@@ -0,0 +1,5 @@
|
||||
| Test.java:14:13:14:59 | contains(...) |
|
||||
| Test.java:18:13:18:62 | contains(...) |
|
||||
| Test.java:22:13:22:71 | contains(...) |
|
||||
| Test.java:26:13:26:95 | contains(...) |
|
||||
| Test.java:30:13:30:84 | contains(...) |
|
||||
5
java/ql/test/library-tests/os/unix-test.ql
Normal file
5
java/ql/test/library-tests/os/unix-test.ql
Normal file
@@ -0,0 +1,5 @@
|
||||
import default
|
||||
import semmle.code.java.os.OSCheck
|
||||
|
||||
from IsUnixGuard isUnix
|
||||
select isUnix
|
||||
2
java/ql/test/library-tests/os/windows-test.expected
Normal file
2
java/ql/test/library-tests/os/windows-test.expected
Normal file
@@ -0,0 +1,2 @@
|
||||
| Test.java:6:13:6:61 | contains(...) |
|
||||
| Test.java:10:13:10:75 | contains(...) |
|
||||
5
java/ql/test/library-tests/os/windows-test.ql
Normal file
5
java/ql/test/library-tests/os/windows-test.ql
Normal file
@@ -0,0 +1,5 @@
|
||||
import default
|
||||
import semmle.code.java.os.OSCheck
|
||||
|
||||
from IsWindowsGuard isWindows
|
||||
select isWindows
|
||||
Reference in New Issue
Block a user