Ensure rest api specs are always copied before using test classpath (#46514)
(cherry picked from commit 45202903b4fea3a43f62594fd357ab3c98c3dd15)
This commit is contained in:
parent
7461259ba6
commit
e5d315f6e1
|
@ -22,10 +22,12 @@ import org.elasticsearch.gradle.VersionProperties
|
||||||
import org.elasticsearch.gradle.testclusters.ElasticsearchCluster
|
import org.elasticsearch.gradle.testclusters.ElasticsearchCluster
|
||||||
import org.elasticsearch.gradle.testclusters.RestTestRunnerTask
|
import org.elasticsearch.gradle.testclusters.RestTestRunnerTask
|
||||||
import org.elasticsearch.gradle.testclusters.TestClustersPlugin
|
import org.elasticsearch.gradle.testclusters.TestClustersPlugin
|
||||||
|
import org.elasticsearch.gradle.tool.Boilerplate
|
||||||
import org.elasticsearch.gradle.tool.ClasspathUtils
|
import org.elasticsearch.gradle.tool.ClasspathUtils
|
||||||
import org.gradle.api.DefaultTask
|
import org.gradle.api.DefaultTask
|
||||||
import org.gradle.api.Task
|
import org.gradle.api.Task
|
||||||
import org.gradle.api.execution.TaskExecutionAdapter
|
import org.gradle.api.execution.TaskExecutionAdapter
|
||||||
|
import org.gradle.api.file.FileCopyDetails
|
||||||
import org.gradle.api.logging.Logger
|
import org.gradle.api.logging.Logger
|
||||||
import org.gradle.api.logging.Logging
|
import org.gradle.api.logging.Logging
|
||||||
import org.gradle.api.tasks.Copy
|
import org.gradle.api.tasks.Copy
|
||||||
|
@ -39,6 +41,7 @@ import org.gradle.process.CommandLineArgumentProvider
|
||||||
import java.nio.charset.StandardCharsets
|
import java.nio.charset.StandardCharsets
|
||||||
import java.nio.file.Files
|
import java.nio.file.Files
|
||||||
import java.util.stream.Stream
|
import java.util.stream.Stream
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A wrapper task around setting up a cluster and running rest tests.
|
* A wrapper task around setting up a cluster and running rest tests.
|
||||||
*/
|
*/
|
||||||
|
@ -121,9 +124,9 @@ class RestIntegTestTask extends DefaultTask {
|
||||||
runner.systemProperty('test.cluster', System.getProperty("tests.cluster"))
|
runner.systemProperty('test.cluster', System.getProperty("tests.cluster"))
|
||||||
}
|
}
|
||||||
|
|
||||||
// copy the rest spec/tests into the test resources
|
// copy the rest spec/tests onto the test classpath
|
||||||
Task copyRestSpec = createCopyRestSpecTask()
|
Copy copyRestSpec = createCopyRestSpecTask()
|
||||||
runner.dependsOn(copyRestSpec)
|
project.sourceSets.test.output.builtBy(copyRestSpec)
|
||||||
|
|
||||||
// this must run after all projects have been configured, so we know any project
|
// this must run after all projects have been configured, so we know any project
|
||||||
// references can be accessed as a fully configured
|
// references can be accessed as a fully configured
|
||||||
|
@ -222,50 +225,37 @@ class RestIntegTestTask extends DefaultTask {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
Copy createCopyRestSpecTask() {
|
||||||
* Creates a task (if necessary) to copy the rest spec files.
|
Boilerplate.maybeCreate(project.configurations, 'restSpec') {
|
||||||
*
|
project.dependencies.add(
|
||||||
* @param project The project to add the copy task to
|
'restSpec',
|
||||||
* @param includePackagedTests true if the packaged tests should be copied, false otherwise
|
ClasspathUtils.isElasticsearchProject() ? project.project(':rest-api-spec') :
|
||||||
*/
|
"org.elasticsearch:rest-api-spec:${VersionProperties.elasticsearch}"
|
||||||
Task createCopyRestSpecTask() {
|
)
|
||||||
project.configurations {
|
|
||||||
restSpec
|
|
||||||
}
|
}
|
||||||
project.dependencies {
|
|
||||||
restSpec ClasspathUtils.isElasticsearchProject() ? project.project(':rest-api-spec') :
|
return Boilerplate.maybeCreate(project.tasks, 'copyRestSpec', Copy) { Copy copy ->
|
||||||
"org.elasticsearch:rest-api-spec:${VersionProperties.elasticsearch}"
|
copy.dependsOn project.configurations.restSpec
|
||||||
}
|
copy.into(project.sourceSets.test.output.resourcesDir)
|
||||||
Task copyRestSpec = project.tasks.findByName('copyRestSpec')
|
copy.from({ project.zipTree(project.configurations.restSpec.singleFile) }) {
|
||||||
if (copyRestSpec != null) {
|
includeEmptyDirs = false
|
||||||
return copyRestSpec
|
include 'rest-api-spec/**'
|
||||||
}
|
filesMatching('rest-api-spec/test/**') { FileCopyDetails details ->
|
||||||
Map copyRestSpecProps = [
|
if (includePackaged == false) {
|
||||||
name : 'copyRestSpec',
|
details.exclude()
|
||||||
type : Copy,
|
}
|
||||||
dependsOn: [project.configurations.restSpec, 'processTestResources']
|
|
||||||
]
|
|
||||||
copyRestSpec = project.tasks.create(copyRestSpecProps) {
|
|
||||||
into project.sourceSets.test.output.resourcesDir
|
|
||||||
}
|
|
||||||
project.afterEvaluate {
|
|
||||||
copyRestSpec.from({ project.zipTree(project.configurations.restSpec.singleFile) }) {
|
|
||||||
include 'rest-api-spec/api/**'
|
|
||||||
if (includePackaged) {
|
|
||||||
include 'rest-api-spec/test/**'
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
if (project.plugins.hasPlugin(IdeaPlugin)) {
|
if (project.plugins.hasPlugin(IdeaPlugin)) {
|
||||||
project.idea {
|
project.idea {
|
||||||
module {
|
module {
|
||||||
if (scopes.TEST != null) {
|
if (scopes.TEST != null) {
|
||||||
scopes.TEST.plus.add(project.configurations.restSpec)
|
scopes.TEST.plus.add(project.configurations.restSpec)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return copyRestSpec
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,6 +20,7 @@ package org.elasticsearch.gradle.tool;
|
||||||
|
|
||||||
import org.gradle.api.Action;
|
import org.gradle.api.Action;
|
||||||
import org.gradle.api.NamedDomainObjectContainer;
|
import org.gradle.api.NamedDomainObjectContainer;
|
||||||
|
import org.gradle.api.PolymorphicDomainObjectContainer;
|
||||||
import org.gradle.api.Project;
|
import org.gradle.api.Project;
|
||||||
import org.gradle.api.Task;
|
import org.gradle.api.Task;
|
||||||
import org.gradle.api.UnknownTaskException;
|
import org.gradle.api.UnknownTaskException;
|
||||||
|
@ -52,6 +53,16 @@ public abstract class Boilerplate {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static <T> T maybeCreate(PolymorphicDomainObjectContainer<T> collection, String name, Class<T> type, Action<T> action) {
|
||||||
|
return Optional.ofNullable(collection.findByName(name))
|
||||||
|
.orElseGet(() -> {
|
||||||
|
T result = collection.create(name, type);
|
||||||
|
action.execute(result);
|
||||||
|
return result;
|
||||||
|
});
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
public static <T extends Task> TaskProvider<T> maybeRegister(TaskContainer tasks, String name, Class<T> clazz, Action<T> action) {
|
public static <T extends Task> TaskProvider<T> maybeRegister(TaskContainer tasks, String name, Class<T> clazz, Action<T> action) {
|
||||||
try {
|
try {
|
||||||
return tasks.named(name, clazz);
|
return tasks.named(name, clazz);
|
||||||
|
|
Loading…
Reference in New Issue