Merge pull request #14815 from rjernst/run_with_debug
Add --debug-jvm option to run and integTest tasks
This commit is contained in:
commit
541b34e6d4
|
@ -455,5 +455,9 @@ mvn -Dtests.coverage verify jacoco:report
|
||||||
|
|
||||||
== Debugging from an IDE
|
== Debugging from an IDE
|
||||||
|
|
||||||
If you want to run elasticsearch from your IDE, you should execute gradle run
|
If you want to run elasticsearch from your IDE, the `gradle run` task
|
||||||
It opens a remote debugging port that you can connect with your IDE.
|
supports a remote debugging option:
|
||||||
|
|
||||||
|
---------------------------------------------------------------------------
|
||||||
|
gradle run --debug-jvm
|
||||||
|
---------------------------------------------------------------------------
|
||||||
|
|
15
build.gradle
15
build.gradle
|
@ -171,7 +171,20 @@ task clean(type: GradleBuild) {
|
||||||
tasks = ['clean']
|
tasks = ['clean']
|
||||||
}
|
}
|
||||||
|
|
||||||
task run() {
|
// we need to add the same --debug-jvm option as
|
||||||
|
// the real RunTask has, so we can pass it through
|
||||||
|
class Run extends DefaultTask {
|
||||||
|
boolean debug = false
|
||||||
|
|
||||||
|
@org.gradle.api.internal.tasks.options.Option(
|
||||||
|
option = "debug-jvm",
|
||||||
|
description = "Enable debugging configuration, to allow attaching a debugger to elasticsearch."
|
||||||
|
)
|
||||||
|
public void setDebug(boolean enabled) {
|
||||||
|
project.project(':distribution').run.clusterConfig.debug = enabled
|
||||||
|
}
|
||||||
|
}
|
||||||
|
task run(type: Run) {
|
||||||
dependsOn ':distribution:run'
|
dependsOn ':distribution:run'
|
||||||
description = 'Runs elasticsearch in the foreground'
|
description = 'Runs elasticsearch in the foreground'
|
||||||
group = 'Verification'
|
group = 'Verification'
|
||||||
|
|
|
@ -39,6 +39,9 @@ class ClusterConfiguration {
|
||||||
@Input
|
@Input
|
||||||
boolean daemonize = true
|
boolean daemonize = true
|
||||||
|
|
||||||
|
@Input
|
||||||
|
boolean debug = false
|
||||||
|
|
||||||
@Input
|
@Input
|
||||||
String jvmArgs = System.getProperty('tests.jvm.argline', '')
|
String jvmArgs = System.getProperty('tests.jvm.argline', '')
|
||||||
|
|
||||||
|
|
|
@ -212,7 +212,7 @@ class ClusterFormationTasks {
|
||||||
static Task configureStartTask(String name, Project project, Task setup, File cwd, ClusterConfiguration config, String clusterName, File pidFile, File home) {
|
static Task configureStartTask(String name, Project project, Task setup, File cwd, ClusterConfiguration config, String clusterName, File pidFile, File home) {
|
||||||
Map esEnv = [
|
Map esEnv = [
|
||||||
'JAVA_HOME' : project.javaHome,
|
'JAVA_HOME' : project.javaHome,
|
||||||
'ES_GC_OPTS': config.jvmArgs
|
'JAVA_OPTS': config.jvmArgs
|
||||||
]
|
]
|
||||||
List<String> esProps = config.systemProperties.collect { key, value -> "-D${key}=${value}" }
|
List<String> esProps = config.systemProperties.collect { key, value -> "-D${key}=${value}" }
|
||||||
for (Map.Entry<String, String> property : System.properties.entrySet()) {
|
for (Map.Entry<String, String> property : System.properties.entrySet()) {
|
||||||
|
@ -235,6 +235,13 @@ class ClusterFormationTasks {
|
||||||
|
|
||||||
// this closure is converted into ant nodes by groovy's AntBuilder
|
// this closure is converted into ant nodes by groovy's AntBuilder
|
||||||
Closure antRunner = {
|
Closure antRunner = {
|
||||||
|
// we must add debug options inside the closure so the config is read at execution time, as
|
||||||
|
// gradle task options are not processed until the end of the configuration phase
|
||||||
|
if (config.debug) {
|
||||||
|
println 'Running elasticsearch in debug mode, suspending until connected on port 8000'
|
||||||
|
esEnv['JAVA_OPTS'] += ' -agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=8000'
|
||||||
|
}
|
||||||
|
|
||||||
exec(executable: executable, spawn: config.daemonize, dir: cwd, taskname: 'elasticsearch') {
|
exec(executable: executable, spawn: config.daemonize, dir: cwd, taskname: 'elasticsearch') {
|
||||||
esEnv.each { key, value -> env(key: key, value: value) }
|
esEnv.each { key, value -> env(key: key, value: value) }
|
||||||
(esArgs + esProps).each { arg(value: it) }
|
(esArgs + esProps).each { arg(value: it) }
|
||||||
|
|
|
@ -22,6 +22,7 @@ import com.carrotsearch.gradle.junit4.RandomizedTestingTask
|
||||||
import org.elasticsearch.gradle.BuildPlugin
|
import org.elasticsearch.gradle.BuildPlugin
|
||||||
import org.gradle.api.Project
|
import org.gradle.api.Project
|
||||||
import org.gradle.api.Task
|
import org.gradle.api.Task
|
||||||
|
import org.gradle.api.internal.tasks.options.Option
|
||||||
import org.gradle.api.plugins.JavaBasePlugin
|
import org.gradle.api.plugins.JavaBasePlugin
|
||||||
import org.gradle.api.tasks.Input
|
import org.gradle.api.tasks.Input
|
||||||
import org.gradle.util.ConfigureUtil
|
import org.gradle.util.ConfigureUtil
|
||||||
|
@ -79,6 +80,14 @@ class RestIntegTestTask extends RandomizedTestingTask {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Option(
|
||||||
|
option = "debug-jvm",
|
||||||
|
description = "Enable debugging configuration, to allow attaching a debugger to elasticsearch."
|
||||||
|
)
|
||||||
|
public void setDebug(boolean enabled) {
|
||||||
|
clusterConfig.debug = enabled;
|
||||||
|
}
|
||||||
|
|
||||||
@Input
|
@Input
|
||||||
void cluster(Closure closure) {
|
void cluster(Closure closure) {
|
||||||
ConfigureUtil.configure(closure, clusterConfig)
|
ConfigureUtil.configure(closure, clusterConfig)
|
||||||
|
|
|
@ -2,6 +2,7 @@ package org.elasticsearch.gradle.test
|
||||||
|
|
||||||
import org.gradle.api.DefaultTask
|
import org.gradle.api.DefaultTask
|
||||||
import org.gradle.api.Project
|
import org.gradle.api.Project
|
||||||
|
import org.gradle.api.internal.tasks.options.Option
|
||||||
|
|
||||||
class RunTask extends DefaultTask {
|
class RunTask extends DefaultTask {
|
||||||
|
|
||||||
|
@ -13,6 +14,14 @@ class RunTask extends DefaultTask {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Option(
|
||||||
|
option = "debug-jvm",
|
||||||
|
description = "Enable debugging configuration, to allow attaching a debugger to elasticsearch."
|
||||||
|
)
|
||||||
|
public void setDebug(boolean enabled) {
|
||||||
|
clusterConfig.debug = enabled;
|
||||||
|
}
|
||||||
|
|
||||||
static void configure(Project project) {
|
static void configure(Project project) {
|
||||||
RunTask task = project.tasks.create(
|
RunTask task = project.tasks.create(
|
||||||
name: 'run',
|
name: 'run',
|
||||||
|
|
Loading…
Reference in New Issue