diff --git a/buildSrc/src/main/groovy/org/elasticsearch/gradle/BuildPlugin.groovy b/buildSrc/src/main/groovy/org/elasticsearch/gradle/BuildPlugin.groovy index e90273ccdbd04..104e297f9425e 100644 --- a/buildSrc/src/main/groovy/org/elasticsearch/gradle/BuildPlugin.groovy +++ b/buildSrc/src/main/groovy/org/elasticsearch/gradle/BuildPlugin.groovy @@ -257,11 +257,7 @@ class BuildPlugin implements Plugin { } } - if (ext.get('buildDocker')) { - (ext.get('requiresDocker') as List).add(task) - } else { - task.onlyIf { false } - } + (ext.get('requiresDocker') as List).add(task) } protected static void checkDockerVersionRecent(String dockerVersion) { diff --git a/buildSrc/src/main/java/org/elasticsearch/gradle/testclusters/TestClusterConfiguration.java b/buildSrc/src/main/java/org/elasticsearch/gradle/testclusters/TestClusterConfiguration.java index 1ccbeabd4b88a..6a8dda49030cf 100644 --- a/buildSrc/src/main/java/org/elasticsearch/gradle/testclusters/TestClusterConfiguration.java +++ b/buildSrc/src/main/java/org/elasticsearch/gradle/testclusters/TestClusterConfiguration.java @@ -116,11 +116,7 @@ default void waitForConditions( } catch (TestClustersException e) { throw e; } catch (Exception e) { - if (lastException == null) { - lastException = e; - } else { - lastException = e; - } + throw e; } } if (conditionMet == false) { @@ -129,7 +125,7 @@ default void waitForConditions( if (lastException == null) { throw new TestClustersException(message); } else { - throw new TestClustersException(message, lastException); + throw new TestClustersException(message + message, lastException); } } logger.info( diff --git a/buildSrc/src/main/java/org/elasticsearch/gradle/testfixtures/TestFixturesPlugin.java b/buildSrc/src/main/java/org/elasticsearch/gradle/testfixtures/TestFixturesPlugin.java index b930955236fb8..a69448ecea77b 100644 --- a/buildSrc/src/main/java/org/elasticsearch/gradle/testfixtures/TestFixturesPlugin.java +++ b/buildSrc/src/main/java/org/elasticsearch/gradle/testfixtures/TestFixturesPlugin.java @@ -34,6 +34,7 @@ import org.gradle.api.tasks.TaskContainer; import org.gradle.api.tasks.testing.Test; +import java.io.File; import java.util.Collections; import java.util.function.BiConsumer; @@ -56,46 +57,47 @@ public void apply(Project project) { disableTaskByType(tasks, ThirdPartyAuditTask.class); disableTaskByType(tasks, JarHellTask.class); + // the project that defined a test fixture can also use it + extension.fixtures.add(project); + Task buildFixture = project.getTasks().create("buildFixture"); Task pullFixture = project.getTasks().create("pullFixture"); Task preProcessFixture = project.getTasks().create("preProcessFixture"); buildFixture.dependsOn(preProcessFixture); pullFixture.dependsOn(preProcessFixture); Task postProcessFixture = project.getTasks().create("postProcessFixture"); + postProcessFixture.dependsOn(buildFixture); + preProcessFixture.onlyIf(spec -> buildFixture.getEnabled()); + postProcessFixture.onlyIf(spec -> buildFixture.getEnabled()); - if (dockerComposeSupported(project) == false) { + if (dockerComposeSupported() == false) { preProcessFixture.setEnabled(false); postProcessFixture.setEnabled(false); buildFixture.setEnabled(false); pullFixture.setEnabled(false); - return; - } - preProcessFixture.onlyIf(spec -> buildFixture.getEnabled()); - postProcessFixture.onlyIf(spec -> buildFixture.getEnabled()); - - project.apply(spec -> spec.plugin(BasePlugin.class)); - project.apply(spec -> spec.plugin(DockerComposePlugin.class)); - ComposeExtension composeExtension = project.getExtensions().getByType(ComposeExtension.class); - composeExtension.setUseComposeFiles(Collections.singletonList(DOCKER_COMPOSE_YML)); - composeExtension.setRemoveContainers(true); - composeExtension.setExecutable( - project.file("/usr/local/bin/docker-compose").exists() ? - "/usr/local/bin/docker-compose" : "/usr/bin/docker-compose" - ); + } else { + project.apply(spec -> spec.plugin(BasePlugin.class)); + project.apply(spec -> spec.plugin(DockerComposePlugin.class)); + ComposeExtension composeExtension = project.getExtensions().getByType(ComposeExtension.class); + composeExtension.setUseComposeFiles(Collections.singletonList(DOCKER_COMPOSE_YML)); + composeExtension.setRemoveContainers(true); + composeExtension.setExecutable( + project.file("/usr/local/bin/docker-compose").exists() ? + "/usr/local/bin/docker-compose" : "/usr/bin/docker-compose" + ); - buildFixture.dependsOn(tasks.getByName("composeUp")); - pullFixture.dependsOn(tasks.getByName("composePull")); - tasks.getByName("composeUp").mustRunAfter(preProcessFixture); - tasks.getByName("composePull").mustRunAfter(preProcessFixture); - postProcessFixture.dependsOn(buildFixture); + buildFixture.dependsOn(tasks.getByName("composeUp")); + pullFixture.dependsOn(tasks.getByName("composePull")); + tasks.getByName("composeUp").mustRunAfter(preProcessFixture); + tasks.getByName("composePull").mustRunAfter(preProcessFixture); - configureServiceInfoForTask( - postProcessFixture, - project, - (name, port) -> postProcessFixture.getExtensions() - .getByType(ExtraPropertiesExtension.class).set(name, port) - ); - extension.fixtures.add(project); + configureServiceInfoForTask( + postProcessFixture, + project, + (name, port) -> postProcessFixture.getExtensions() + .getByType(ExtraPropertiesExtension.class).set(name, port) + ); + } } extension.fixtures @@ -107,7 +109,7 @@ public void apply(Project project) { conditionTaskByType(tasks, extension, TestingConventionsTasks.class); conditionTaskByType(tasks, extension, ComposeUp.class); - if (dockerComposeSupported(project) == false) { + if (dockerComposeSupported() == false) { project.getLogger().warn( "Tests for {} require docker-compose at /usr/local/bin/docker-compose or /usr/bin/docker-compose " + "but none could be found so these will be skipped", project.getPath() @@ -135,7 +137,9 @@ private void conditionTaskByType(TaskContainer tasks, TestFixtureExtension exten taskClass, task -> task.onlyIf(spec -> extension.fixtures.stream() - .anyMatch(fixtureProject -> fixtureProject.getTasks().getByName("buildFixture").getEnabled() == false) == false + .anyMatch(fixtureProject -> + fixtureProject.getTasks().getByName("buildFixture").getEnabled() == false + ) == false ) ); } @@ -168,12 +172,12 @@ private void configureServiceInfoForTask(Task task, Project fixtureProject, BiCo ); } - public boolean dockerComposeSupported(Project project) { + public static boolean dockerComposeSupported() { if (OS.current().equals(OS.WINDOWS)) { return false; } - final boolean hasDockerCompose = project.file("/usr/local/bin/docker-compose").exists() || - project.file("/usr/bin/docker-compose").exists(); + final boolean hasDockerCompose = (new File("/usr/local/bin/docker-compose")).exists() || + (new File("/usr/bin/docker-compose").exists()); return hasDockerCompose && Boolean.parseBoolean(System.getProperty("tests.fixture.enabled", "true")); } diff --git a/distribution/docker/build.gradle b/distribution/docker/build.gradle index e99012513753a..46f456c8c0493 100644 --- a/distribution/docker/build.gradle +++ b/distribution/docker/build.gradle @@ -2,6 +2,7 @@ import org.elasticsearch.gradle.BuildPlugin import org.elasticsearch.gradle.LoggedExec import org.elasticsearch.gradle.MavenFilteringHack import org.elasticsearch.gradle.VersionProperties +import org.elasticsearch.gradle.testfixtures.TestFixturesPlugin apply plugin: 'base' apply plugin: 'elasticsearch.test.fixtures' @@ -77,7 +78,10 @@ void addCopyDockerContextTask(final boolean oss) { } preProcessFixture { - dependsOn assemble + // don't add the tasks to build the docker images if we have no way of testing them + if (TestFixturesPlugin.dockerComposeSupported()) { + dependsOn assemble + } } postProcessFixture.doLast { diff --git a/plugins/repository-s3/build.gradle b/plugins/repository-s3/build.gradle index e3ba48e9b84de..6fec01d9b0e96 100644 --- a/plugins/repository-s3/build.gradle +++ b/plugins/repository-s3/build.gradle @@ -169,24 +169,16 @@ if (useFixture) { File minioAddressFile = new File(project.buildDir, 'generated-resources/s3Fixture.address') - // We can't lazy evaluate a system property for the Minio address passed to JUnit so we write it to a resource file - // and pass its name instead. - task writeMinioAddress { + thirdPartyTest { dependsOn tasks.bundlePlugin, tasks.postProcessFixture outputs.file(minioAddressFile) - doLast { + doFirst { file(minioAddressFile).text = "${ -> minioAddress.call() }" } - } - - thirdPartyTest { - dependsOn writeMinioAddress - inputs.file(minioAddressFile) + // TODO: this could be a nonInputProperties.systemProperty so we don't need a file systemProperty 'test.s3.endpoint', minioAddressFile.name } - BuildPlugin.requireDocker(tasks.thirdPartyTest) - task integTestMinio(type: RestIntegTestTask) { description = "Runs REST tests using the Minio repository." dependsOn tasks.bundlePlugin, tasks.postProcessFixture @@ -200,7 +192,6 @@ if (useFixture) { } } check.dependsOn(integTestMinio) - BuildPlugin.requireDocker(tasks.integTestMinio) testClusters.integTestMinio { keystore 's3.client.integration_test_permanent.access_key', s3PermanentAccessKey