diff --git a/build.gradle b/build.gradle index 3d53242b4a8..78818dec951 100644 --- a/build.gradle +++ b/build.gradle @@ -171,5 +171,9 @@ task clean(type: GradleBuild) { tasks = ['clean'] } -task run(dependsOn: ':distribution:run') +task run() { + dependsOn ':distribution:run' + description = 'Runs elasticsearch in the foreground' + group = 'Verification' +} diff --git a/buildSrc/src/main/groovy/org/elasticsearch/gradle/plugin/PluginBuildPlugin.groovy b/buildSrc/src/main/groovy/org/elasticsearch/gradle/plugin/PluginBuildPlugin.groovy index 2a95f26ab8b..fbbdb242d45 100644 --- a/buildSrc/src/main/groovy/org/elasticsearch/gradle/plugin/PluginBuildPlugin.groovy +++ b/buildSrc/src/main/groovy/org/elasticsearch/gradle/plugin/PluginBuildPlugin.groovy @@ -18,9 +18,9 @@ */ package org.elasticsearch.gradle.plugin -import nebula.plugin.extraconfigurations.ProvidedBasePlugin import org.elasticsearch.gradle.BuildPlugin import org.elasticsearch.gradle.test.RestIntegTestTask +import org.elasticsearch.gradle.test.RunTask import org.gradle.api.Project import org.gradle.api.Task import org.gradle.api.tasks.bundling.Zip @@ -33,26 +33,21 @@ class PluginBuildPlugin extends BuildPlugin { @Override void apply(Project project) { super.apply(project) - // TODO: add target compatibility (java version) to elasticsearch properties and set for the project configureDependencies(project) // this afterEvaluate must happen before the afterEvaluate added by integTest configure, // so that the file name resolution for installing the plugin will be setup project.afterEvaluate { - project.jar.configure { - baseName project.pluginProperties.extension.name - } - project.bundlePlugin.configure { - baseName project.pluginProperties.extension.name - } - project.integTest.configure { - dependsOn project.bundlePlugin - cluster { - plugin project.pluginProperties.extension.name, project.bundlePlugin.outputs.files - } - } + String name = project.pluginProperties.extension.name + project.jar.baseName = name + project.bundlePlugin.baseName = name + project.integTest.dependsOn(project.bundlePlugin) + project.integTest.clusterConfig.plugin(name, project.bundlePlugin.outputs.files) + project.tasks.run.dependsOn(project.bundlePlugin) + project.tasks.run.clusterConfig.plugin(name, project.bundlePlugin.outputs.files) } - Task bundle = configureBundleTask(project) RestIntegTestTask.configure(project) + RunTask.configure(project) + Task bundle = configureBundleTask(project) project.configurations.archives.artifacts.removeAll { it.archiveTask.is project.jar } project.configurations.getByName('default').extendsFrom = [] project.artifacts { diff --git a/buildSrc/src/main/groovy/org/elasticsearch/gradle/test/ClusterFormationTasks.groovy b/buildSrc/src/main/groovy/org/elasticsearch/gradle/test/ClusterFormationTasks.groovy index b53420334ce..35811a832a2 100644 --- a/buildSrc/src/main/groovy/org/elasticsearch/gradle/test/ClusterFormationTasks.groovy +++ b/buildSrc/src/main/groovy/org/elasticsearch/gradle/test/ClusterFormationTasks.groovy @@ -102,7 +102,7 @@ class ClusterFormationTasks { String camelName = plugin.getKey().replaceAll(/-(\w)/) { _, c -> c.toUpperCase(Locale.ROOT) } String taskName = "${task.name}#install${camelName[0].toUpperCase(Locale.ROOT) + camelName.substring(1)}Plugin" // delay reading the file location until execution time by wrapping in a closure within a GString - String file = "${ -> new File(pluginsTmpDir, plugin.getValue().singleFile.getName()).toURI().toURL().toString() }" + String file = "${-> new File(pluginsTmpDir, plugin.getValue().singleFile.getName()).toURI().toURL().toString()}" Object[] args = [new File(home, 'bin/plugin'), 'install', file] setup = configureExecTask(taskName, project, setup, cwd, args) } @@ -115,8 +115,11 @@ class ClusterFormationTasks { Task start = configureStartTask("${task.name}#start", project, setup, cwd, config, clusterName, pidFile, home) task.dependsOn(start) - Task stop = configureStopTask("${task.name}#stop", project, [], pidFile) - task.finalizedBy(stop) + if (config.daemonize) { + // if we are running in the background, make sure to stop the server when the task completes + Task stop = configureStopTask("${task.name}#stop", project, [], pidFile) + task.finalizedBy(stop) + } } /** Adds a task to extract the elasticsearch distribution */ diff --git a/buildSrc/src/main/groovy/org/elasticsearch/gradle/test/RunTask.groovy b/buildSrc/src/main/groovy/org/elasticsearch/gradle/test/RunTask.groovy index ad14dfe8672..3abc4283304 100644 --- a/buildSrc/src/main/groovy/org/elasticsearch/gradle/test/RunTask.groovy +++ b/buildSrc/src/main/groovy/org/elasticsearch/gradle/test/RunTask.groovy @@ -1,12 +1,23 @@ package org.elasticsearch.gradle.test import org.gradle.api.DefaultTask -import org.gradle.api.tasks.TaskAction +import org.gradle.api.Project class RunTask extends DefaultTask { + ClusterConfiguration clusterConfig = new ClusterConfiguration(httpPort: 9200, transportPort: 9300, daemonize: false) RunTask() { - ClusterFormationTasks.setup(project, this, clusterConfig) + project.afterEvaluate { + ClusterFormationTasks.setup(project, this, clusterConfig) + } + } + + static void configure(Project project) { + RunTask task = project.tasks.create( + name: 'run', + type: RunTask, + description: "Runs elasticsearch with '${project.path}'", + group: 'Verification') } } diff --git a/distribution/build.gradle b/distribution/build.gradle index f2aca91cb86..d6466b6c16c 100644 --- a/distribution/build.gradle +++ b/distribution/build.gradle @@ -19,6 +19,7 @@ import org.apache.tools.ant.filters.FixCrLfFilter import org.elasticsearch.gradle.precommit.DependencyLicensesTask +import org.elasticsearch.gradle.test.RunTask import org.elasticsearch.gradle.MavenFilteringHack // for deb/rpm @@ -196,4 +197,5 @@ DependencyLicensesTask.configure(project) { mapping from: /jackson-.*/, to: 'jackson' } -task run(type:org.elasticsearch.gradle.test.RunTask){} \ No newline at end of file +RunTask.configure(project) +