Skip to content

Commit 200579b

Browse files
committed
Simplify finding jps (#45677)
This commit simplifies how we find jps to instead use built-in Gradle functionality for the same.
1 parent 74de6d2 commit 200579b

File tree

1 file changed

+4
-14
lines changed

1 file changed

+4
-14
lines changed

buildSrc/src/main/groovy/org/elasticsearch/gradle/test/ClusterFormationTasks.groovy

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@ package org.elasticsearch.gradle.test
2121
import org.apache.tools.ant.DefaultLogger
2222
import org.apache.tools.ant.taskdefs.condition.Os
2323
import org.elasticsearch.gradle.BuildPlugin
24+
import org.elasticsearch.gradle.BwcVersions
2425
import org.elasticsearch.gradle.LoggedExec
2526
import org.elasticsearch.gradle.Version
26-
import org.elasticsearch.gradle.BwcVersions
2727
import org.elasticsearch.gradle.VersionProperties
2828
import org.elasticsearch.gradle.plugin.PluginBuildPlugin
2929
import org.elasticsearch.gradle.plugin.PluginPropertiesExtension
@@ -39,11 +39,13 @@ import org.gradle.api.logging.Logger
3939
import org.gradle.api.tasks.Copy
4040
import org.gradle.api.tasks.Delete
4141
import org.gradle.api.tasks.Exec
42+
import org.gradle.internal.jvm.Jvm
4243

4344
import java.nio.charset.StandardCharsets
4445
import java.nio.file.Paths
4546
import java.util.concurrent.TimeUnit
4647
import 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

Comments
 (0)