Class SystemUtils

java.lang.Object
org.apache.maven.surefire.booter.SystemUtils

public final class SystemUtils extends Object
JDK 9 support.
Since:
2.20.1
  • Field Details

    • JIGSAW_JAVA_VERSION

      private static final BigDecimal JIGSAW_JAVA_VERSION
    • PROC_STATUS_PID_FIRST_CHARS

      private static final int PROC_STATUS_PID_FIRST_CHARS
      See Also:
  • Constructor Details

    • SystemUtils

      private SystemUtils()
  • Method Details

    • endsWithJavaPath

      public static boolean endsWithJavaPath(String jvmExecPath)
      Parameters:
      jvmExecPath - e.g. /jdk/bin/java, /jdk/jre/bin/java
      Returns:
      true if jvmExecPath is path to java binary executor
    • toJdkHomeFromJvmExec

      public static File toJdkHomeFromJvmExec(String jvmExecutable)
      If jvmExecutable 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 if jvmExecutable 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 File toJdkHomeFromJre()
      If system property java.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 File toJdkHomeFromJre(String jreHome)
      If jreHome is /jdk (since jdk9) or /jdk/jre (prior to jdk9) then the absolute path to JDK home is returned /jdk.
      JRE home directory jreHome must be taken from system property java.home.
      Parameters:
      jreHome - path to /jdk or /jdk/jre
      Returns:
      path to JDK
    • toJdkVersionFromReleaseFile

      public static BigDecimal toJdkVersionFromReleaseFile(File jdkHome)
    • isJava9AtLeast

      public static boolean isJava9AtLeast(String jvmExecutablePath)
    • isBuiltInJava9AtLeast

      public static boolean isBuiltInJava9AtLeast()
    • isJava9AtLeast

      public static boolean isJava9AtLeast(BigDecimal version)
    • platformClassLoader

      public static ClassLoader platformClassLoader()
    • pid

      public static Long pid()
    • pidOnJMX

      static Long pidOnJMX()
    • pidStatusOnLinux

      static Long pidStatusOnLinux() throws 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:
      Exception - i/o and number format exc
    • pidStatusOnLinux

      static Long pidStatusOnLinux(String root) throws Exception
      For testing purposes only.
      Parameters:
      root - shifted to test-classes
      Returns:
      same as in pidStatusOnLinux()
      Throws:
      Exception - same as in pidStatusOnLinux()
    • pidStatusOnBSD

      static Long pidStatusOnBSD() throws 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:
      Exception - if could not read /proc/curproc/status
    • pidStatusOnBSD

      static Long pidStatusOnBSD(String root) throws Exception
      For testing purposes only.
      Parameters:
      root - shifted to test-classes
      Returns:
      same as in pidStatusOnBSD()
      Throws:
      Exception - same as in pidStatusOnBSD()
    • pidOnJava9

      static Long pidOnJava9()
    • reflectClassLoader

      static ClassLoader reflectClassLoader(Class<?> target, String getterMethodName)