Simplify finding jps (#45677)

This commit simplifies how we find jps to instead use built-in Gradle
functionality for the same.
This commit is contained in:
Jason Tedor 2019-08-16 18:32:12 -04:00
parent 74de6d2c71
commit 200579bfce
No known key found for this signature in database
GPG Key ID: 8CF9C19984731E85

View File

@ -21,9 +21,9 @@ package org.elasticsearch.gradle.test
import org.apache.tools.ant.DefaultLogger
import org.apache.tools.ant.taskdefs.condition.Os
import org.elasticsearch.gradle.BuildPlugin
import org.elasticsearch.gradle.BwcVersions
import org.elasticsearch.gradle.LoggedExec
import org.elasticsearch.gradle.Version
import org.elasticsearch.gradle.BwcVersions
import org.elasticsearch.gradle.VersionProperties
import org.elasticsearch.gradle.plugin.PluginBuildPlugin
import org.elasticsearch.gradle.plugin.PluginPropertiesExtension
@ -39,11 +39,13 @@ import org.gradle.api.logging.Logger
import org.gradle.api.tasks.Copy
import org.gradle.api.tasks.Delete
import org.gradle.api.tasks.Exec
import org.gradle.internal.jvm.Jvm
import java.nio.charset.StandardCharsets
import java.nio.file.Paths
import java.util.concurrent.TimeUnit
import java.util.stream.Collectors
/**
* 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.
*/
@ -917,15 +919,7 @@ class ClusterFormationTasks {
onlyIf { node.pidFile.exists() }
// the pid file won't actually be read until execution time, since the read is wrapped within an inner closure of the GString
ext.pid = "${ -> node.pidFile.getText('UTF-8').trim()}"
File jps
if (Os.isFamily(Os.FAMILY_WINDOWS)) {
jps = getJpsExecutableByName(project, "jps.exe")
} else {
jps = getJpsExecutableByName(project, "jps")
}
if (!jps.exists()) {
throw new GradleException("jps executable not found; ensure that you're running Gradle with the JDK rather than the JRE")
}
final File jps = Jvm.forHome(project.runtimeJavaHome).getExecutable('jps')
commandLine jps, '-l'
standardOutput = new ByteArrayOutputStream()
doLast {
@ -944,10 +938,6 @@ class ClusterFormationTasks {
}
}
private static File getJpsExecutableByName(Project project, String jpsExecutableName) {
return Paths.get(project.runtimeJavaHome.toString(), "bin/" + jpsExecutableName).toFile()
}
/** Adds a task to kill an elasticsearch node with the given pidfile */
static Task configureStopTask(String name, Project project, Object depends, NodeInfo node) {
return project.tasks.create(name: name, type: LoggedExec, dependsOn: depends) {