@@ -21,9 +21,9 @@ package org.elasticsearch.gradle.test
2121import org.apache.tools.ant.DefaultLogger
2222import org.apache.tools.ant.taskdefs.condition.Os
2323import org.elasticsearch.gradle.BuildPlugin
24+ import org.elasticsearch.gradle.BwcVersions
2425import org.elasticsearch.gradle.LoggedExec
2526import org.elasticsearch.gradle.Version
26- import org.elasticsearch.gradle.BwcVersions
2727import org.elasticsearch.gradle.VersionProperties
2828import org.elasticsearch.gradle.plugin.PluginBuildPlugin
2929import org.elasticsearch.gradle.plugin.PluginPropertiesExtension
@@ -39,11 +39,13 @@ import org.gradle.api.logging.Logger
3939import org.gradle.api.tasks.Copy
4040import org.gradle.api.tasks.Delete
4141import org.gradle.api.tasks.Exec
42+ import org.gradle.internal.jvm.Jvm
4243
4344import java.nio.charset.StandardCharsets
4445import java.nio.file.Paths
4546import java.util.concurrent.TimeUnit
4647import java.util.stream.Collectors
48+
4749/**
4850 * A helper for creating tasks to build a cluster that is used by a task, and tear down the cluster when the task is finished.
4951 */
@@ -917,15 +919,7 @@ class ClusterFormationTasks {
917919 onlyIf { node. pidFile. exists() }
918920 // the pid file won't actually be read until execution time, since the read is wrapped within an inner closure of the GString
919921 ext. pid = " ${ -> node.pidFile.getText('UTF-8').trim()} "
920- File jps
921- if (Os . isFamily(Os . FAMILY_WINDOWS )) {
922- jps = getJpsExecutableByName(project, " jps.exe" )
923- } else {
924- jps = getJpsExecutableByName(project, " jps" )
925- }
926- if (! jps. exists()) {
927- throw new GradleException (" jps executable not found; ensure that you're running Gradle with the JDK rather than the JRE" )
928- }
922+ final File jps = Jvm . forHome(project. runtimeJavaHome). getExecutable(' jps' )
929923 commandLine jps, ' -l'
930924 standardOutput = new ByteArrayOutputStream ()
931925 doLast {
@@ -944,10 +938,6 @@ class ClusterFormationTasks {
944938 }
945939 }
946940
947- private static File getJpsExecutableByName (Project project , String jpsExecutableName ) {
948- return Paths . get(project. runtimeJavaHome. toString(), " bin/" + jpsExecutableName). toFile()
949- }
950-
951941 /* * Adds a task to kill an elasticsearch node with the given pidfile */
952942 static Task configureStopTask (String name , Project project , Object depends , NodeInfo node ) {
953943 return project. tasks. create(name : name, type : LoggedExec , dependsOn : depends) {
0 commit comments