Package org.apache.maven.surefire.booter
Class SystemUtils
- java.lang.Object
-
- org.apache.maven.surefire.booter.SystemUtils
-
public final class SystemUtils extends java.lang.Object
JDK 9 support.- Since:
- 2.20.1
-
-
Field Summary
Fields Modifier and Type Field Description private static java.math.BigDecimal
JIGSAW_JAVA_VERSION
private static int
PROC_STATUS_PID_FIRST_CHARS
-
Constructor Summary
Constructors Modifier Constructor Description private
SystemUtils()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static boolean
endsWithJavaPath(java.lang.String jvmExecPath)
static boolean
isBuiltInJava9AtLeast()
static boolean
isJava9AtLeast(java.lang.String jvmExecutablePath)
static boolean
isJava9AtLeast(java.math.BigDecimal version)
static java.lang.Long
pid()
(package private) static java.lang.Long
pidOnJava9()
(package private) static java.lang.Long
pidOnJMX()
(package private) static java.lang.Long
pidStatusOnBSD()
The process status.(package private) static java.lang.Long
pidStatusOnBSD(java.lang.String root)
For testing purposes only.(package private) static java.lang.Long
pidStatusOnLinux()
$ cat /proc/self/stat
48982 (cat) R 9744 48982 9744 34818 48982 8192 185 0 0 0 0 0 0 0 20 0 1 0 137436614 103354368 134 18446744073709551615 4194304 4235780 140737488346592 140737488343784 252896458544 0 0 0 0 0 0 0 17 2 0 0 0 0 0
$ SELF_PID=$(cat /proc/self/stat)
$ echo $CPU_ID | gawk '{print $1}'
48982(package private) static java.lang.Long
pidStatusOnLinux(java.lang.String root)
For testing purposes only.static java.lang.ClassLoader
platformClassLoader()
(package private) static java.lang.ClassLoader
reflectClassLoader(java.lang.Class<?> target, java.lang.String getterMethodName)
static java.io.File
toJdkHomeFromJre()
If system propertyjava.home
is/jdk
(since jdk9) or/jdk/jre
(prior to jdk9) then the absolute path to JDK home is returned/jdk
.(package private) static java.io.File
toJdkHomeFromJre(java.lang.String jreHome)
IfjreHome
is/jdk
(since jdk9) or/jdk/jre
(prior to jdk9) then the absolute path to JDK home is returned/jdk
.static java.io.File
toJdkHomeFromJvmExec(java.lang.String jvmExecutable)
IfjvmExecutable
is/jdk/bin/java
(since jdk9) or/jdk/jre/bin/java
(prior to jdk9) then the absolute path to JDK home is returned/jdk
.static java.math.BigDecimal
toJdkVersionFromReleaseFile(java.io.File jdkHome)
-
-
-
Field Detail
-
JIGSAW_JAVA_VERSION
private static final java.math.BigDecimal JIGSAW_JAVA_VERSION
-
PROC_STATUS_PID_FIRST_CHARS
private static final int PROC_STATUS_PID_FIRST_CHARS
- See Also:
- Constant Field Values
-
-
Method Detail
-
endsWithJavaPath
public static boolean endsWithJavaPath(java.lang.String jvmExecPath)
- Parameters:
jvmExecPath
- e.g. /jdk/bin/java, /jdk/jre/bin/java- Returns:
true
ifjvmExecPath
is path to java binary executor
-
toJdkHomeFromJvmExec
public static java.io.File toJdkHomeFromJvmExec(java.lang.String jvmExecutable)
IfjvmExecutable
is/jdk/bin/java
(since jdk9) or/jdk/jre/bin/java
(prior to jdk9) then the absolute path to JDK home is returned/jdk
.
Null is returned ifjvmExecutable
is incorrect.- Parameters:
jvmExecutable
- /jdk/bin/java* or /jdk/jre/bin/java*- Returns:
- path to jdk directory; or
null
if wrong path or directory layout of JDK installation.
-
toJdkHomeFromJre
public static java.io.File toJdkHomeFromJre()
If system propertyjava.home
is/jdk
(since jdk9) or/jdk/jre
(prior to jdk9) then the absolute path to JDK home is returned/jdk
.- Returns:
- path to JDK
-
toJdkHomeFromJre
static java.io.File toJdkHomeFromJre(java.lang.String jreHome)
IfjreHome
is/jdk
(since jdk9) or/jdk/jre
(prior to jdk9) then the absolute path to JDK home is returned/jdk
.
JRE home directoryjreHome
must be taken from system propertyjava.home
.- Parameters:
jreHome
- path to /jdk or /jdk/jre- Returns:
- path to JDK
-
toJdkVersionFromReleaseFile
public static java.math.BigDecimal toJdkVersionFromReleaseFile(java.io.File jdkHome)
-
isJava9AtLeast
public static boolean isJava9AtLeast(java.lang.String jvmExecutablePath)
-
isBuiltInJava9AtLeast
public static boolean isBuiltInJava9AtLeast()
-
isJava9AtLeast
public static boolean isJava9AtLeast(java.math.BigDecimal version)
-
platformClassLoader
public static java.lang.ClassLoader platformClassLoader()
-
pid
public static java.lang.Long pid()
-
pidOnJMX
static java.lang.Long pidOnJMX()
-
pidStatusOnLinux
static java.lang.Long pidStatusOnLinux() throws java.lang.Exception
$ cat /proc/self/stat
48982 (cat) R 9744 48982 9744 34818 48982 8192 185 0 0 0 0 0 0 0 20 0 1 0 137436614 103354368 134 18446744073709551615 4194304 4235780 140737488346592 140737488343784 252896458544 0 0 0 0 0 0 0 17 2 0 0 0 0 0
$ SELF_PID=$(cat /proc/self/stat)
$ echo $CPU_ID | gawk '{print $1}'
48982- Returns:
- self PID
- Throws:
java.lang.Exception
- i/o and number format exc
-
pidStatusOnLinux
static java.lang.Long pidStatusOnLinux(java.lang.String root) throws java.lang.Exception
For testing purposes only.- Parameters:
root
- shifted to test-classes- Returns:
- same as in
pidStatusOnLinux()
- Throws:
java.lang.Exception
- same as inpidStatusOnLinux()
-
pidStatusOnBSD
static java.lang.Long pidStatusOnBSD() throws java.lang.Exception
The process status. This file is read-only and returns a single line containing multiple space-separated fields.
See procfs status
# cat /proc/curproc/status
cat 60424 60386 60424 60386 5,0 ctty 972854153,236415 0,0 0,1043 nochan 0 0 0,0 prisoner
Fields are:
comm pid ppid pgid sid maj, min ctty, sldr start user/system time wmsg euid ruid rgid,egid, groups[1 .. NGROUPS] hostname- Returns:
- current PID
- Throws:
java.lang.Exception
- if could not read /proc/curproc/status
-
pidStatusOnBSD
static java.lang.Long pidStatusOnBSD(java.lang.String root) throws java.lang.Exception
For testing purposes only.- Parameters:
root
- shifted to test-classes- Returns:
- same as in
pidStatusOnBSD()
- Throws:
java.lang.Exception
- same as inpidStatusOnBSD()
-
pidOnJava9
static java.lang.Long pidOnJava9()
-
reflectClassLoader
static java.lang.ClassLoader reflectClassLoader(java.lang.Class<?> target, java.lang.String getterMethodName)
-
-