Example usage for java.lang ProcessHandle current

List of usage examples for java.lang ProcessHandle current

Introduction

In this page you can find the example usage for java.lang ProcessHandle current.

Prototype

public static ProcessHandle current() 

Source Link

Document

Returns a ProcessHandle for the current process.

Usage

From source file:platform.tooling.support.Runner.java

private Path getCurrentJdkHome() {
    Path executable = ProcessHandle.current().info().command().map(Paths::get).orElse(null);
    if (executable != null && executable.getNameCount() > 2) {
        // noinspection ConstantConditions -- count is 3 or higher: "<JDK_HOME>/bin/java[.exe]"
        return executable.getParent().getParent().toAbsolutePath();
    }/*from   www . j a  v  a  2 s .  co m*/
    String jdkHome = System.getenv("JDK_HOME");
    if (jdkHome != null) {
        return Paths.get(jdkHome).toAbsolutePath();
    }
    String javaHome = System.getenv("JAVA_HOME");
    if (javaHome != null) {
        return Paths.get(javaHome).toAbsolutePath();
    }
    return Paths.get("jdk-" + Runtime.version().feature()).toAbsolutePath();
}