|
@@ -20,6 +20,7 @@ package org.elasticsearch.gradle.testfixtures;
|
|
|
|
|
|
|
|
import com.avast.gradle.dockercompose.ComposeExtension;
|
|
import com.avast.gradle.dockercompose.ComposeExtension;
|
|
|
import com.avast.gradle.dockercompose.DockerComposePlugin;
|
|
import com.avast.gradle.dockercompose.DockerComposePlugin;
|
|
|
|
|
+import com.avast.gradle.dockercompose.ServiceInfo;
|
|
|
import com.avast.gradle.dockercompose.tasks.ComposeUp;
|
|
import com.avast.gradle.dockercompose.tasks.ComposeUp;
|
|
|
import org.elasticsearch.gradle.OS;
|
|
import org.elasticsearch.gradle.OS;
|
|
|
import org.elasticsearch.gradle.SystemPropertyCommandLineArgumentProvider;
|
|
import org.elasticsearch.gradle.SystemPropertyCommandLineArgumentProvider;
|
|
@@ -58,9 +59,6 @@ public class TestFixturesPlugin implements Plugin<Project> {
|
|
|
ext.set("testFixturesDir", testfixturesDir);
|
|
ext.set("testFixturesDir", testfixturesDir);
|
|
|
|
|
|
|
|
if (project.file(DOCKER_COMPOSE_YML).exists()) {
|
|
if (project.file(DOCKER_COMPOSE_YML).exists()) {
|
|
|
- // the project that defined a test fixture can also use it
|
|
|
|
|
- extension.fixtures.add(project);
|
|
|
|
|
-
|
|
|
|
|
Task buildFixture = project.getTasks().create("buildFixture");
|
|
Task buildFixture = project.getTasks().create("buildFixture");
|
|
|
Task pullFixture = project.getTasks().create("pullFixture");
|
|
Task pullFixture = project.getTasks().create("pullFixture");
|
|
|
Task preProcessFixture = project.getTasks().create("preProcessFixture");
|
|
Task preProcessFixture = project.getTasks().create("preProcessFixture");
|
|
@@ -106,6 +104,7 @@ public class TestFixturesPlugin implements Plugin<Project> {
|
|
|
configureServiceInfoForTask(
|
|
configureServiceInfoForTask(
|
|
|
postProcessFixture,
|
|
postProcessFixture,
|
|
|
project,
|
|
project,
|
|
|
|
|
+ false,
|
|
|
(name, port) -> postProcessFixture.getExtensions()
|
|
(name, port) -> postProcessFixture.getExtensions()
|
|
|
.getByType(ExtraPropertiesExtension.class).set(name, port)
|
|
.getByType(ExtraPropertiesExtension.class).set(name, port)
|
|
|
);
|
|
);
|
|
@@ -144,6 +143,7 @@ public class TestFixturesPlugin implements Plugin<Project> {
|
|
|
configureServiceInfoForTask(
|
|
configureServiceInfoForTask(
|
|
|
task,
|
|
task,
|
|
|
fixtureProject,
|
|
fixtureProject,
|
|
|
|
|
+ true,
|
|
|
(name, host) ->
|
|
(name, host) ->
|
|
|
task.getExtensions().getByType(SystemPropertyCommandLineArgumentProvider.class).systemProperty(name, host)
|
|
task.getExtensions().getByType(SystemPropertyCommandLineArgumentProvider.class).systemProperty(name, host)
|
|
|
);
|
|
);
|
|
@@ -165,14 +165,23 @@ public class TestFixturesPlugin implements Plugin<Project> {
|
|
|
);
|
|
);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- private void configureServiceInfoForTask(Task task, Project fixtureProject, BiConsumer<String, Integer> consumer) {
|
|
|
|
|
|
|
+ private void configureServiceInfoForTask(
|
|
|
|
|
+ Task task, Project fixtureProject, boolean enableFilter, BiConsumer<String, Integer> consumer
|
|
|
|
|
+ ) {
|
|
|
// Configure ports for the tests as system properties.
|
|
// Configure ports for the tests as system properties.
|
|
|
// We only know these at execution time so we need to do it in doFirst
|
|
// We only know these at execution time so we need to do it in doFirst
|
|
|
|
|
+ TestFixtureExtension extension = task.getProject().getExtensions().getByType(TestFixtureExtension.class);
|
|
|
task.doFirst(new Action<Task>() {
|
|
task.doFirst(new Action<Task>() {
|
|
|
@Override
|
|
@Override
|
|
|
public void execute(Task theTask) {
|
|
public void execute(Task theTask) {
|
|
|
fixtureProject.getExtensions().getByType(ComposeExtension.class).getServicesInfos()
|
|
fixtureProject.getExtensions().getByType(ComposeExtension.class).getServicesInfos()
|
|
|
- .forEach((service, infos) -> {
|
|
|
|
|
|
|
+ .entrySet().stream()
|
|
|
|
|
+ .filter(entry -> enableFilter == false ||
|
|
|
|
|
+ extension.isServiceRequired(entry.getKey(), fixtureProject.getPath())
|
|
|
|
|
+ )
|
|
|
|
|
+ .forEach(entry -> {
|
|
|
|
|
+ String service = entry.getKey();
|
|
|
|
|
+ ServiceInfo infos = entry.getValue();
|
|
|
infos.getTcpPorts()
|
|
infos.getTcpPorts()
|
|
|
.forEach((container, host) -> {
|
|
.forEach((container, host) -> {
|
|
|
String name = "test.fixtures." + service + ".tcp." + container;
|
|
String name = "test.fixtures." + service + ".tcp." + container;
|