From 6c4e55e7147b18e40717f2c96fccf16edd01d583 Mon Sep 17 00:00:00 2001 From: Mark Vieira Date: Thu, 8 Feb 2024 12:27:09 -0800 Subject: [PATCH] Fix file path when looking for docker exclusions file (#105304) --- .../internal/conventions/util/Util.java | 40 +++++++++---------- .../internal/ElasticsearchTestBasePlugin.java | 1 + .../DockerEnvironmentAwareTestContainer.java | 2 +- 3 files changed, 22 insertions(+), 21 deletions(-) diff --git a/build-conventions/src/main/java/org/elasticsearch/gradle/internal/conventions/util/Util.java b/build-conventions/src/main/java/org/elasticsearch/gradle/internal/conventions/util/Util.java index 5cdc72ebde38..39a4ec3f30e8 100644 --- a/build-conventions/src/main/java/org/elasticsearch/gradle/internal/conventions/util/Util.java +++ b/build-conventions/src/main/java/org/elasticsearch/gradle/internal/conventions/util/Util.java @@ -119,29 +119,29 @@ public class Util { return project.getExtensions().getByType(JavaPluginExtension.class).getSourceSets(); } - public static File locateElasticsearchWorkspace(Gradle gradle) { - if(gradle.getRootProject().getName().startsWith("build-tools")) { - File buildToolsParent = gradle.getRootProject().getRootDir().getParentFile(); - if(versionFileExists(buildToolsParent)) { - return buildToolsParent; - } + public static File locateElasticsearchWorkspace(Gradle gradle) { + if (gradle.getRootProject().getName().startsWith("build-tools")) { + File buildToolsParent = gradle.getRootProject().getRootDir().getParentFile(); + if (versionFileExists(buildToolsParent)) { return buildToolsParent; } - if (gradle.getParent() == null) { - // See if any of these included builds is the Elasticsearch gradle - for (IncludedBuild includedBuild : gradle.getIncludedBuilds()) { - if (versionFileExists(includedBuild.getProjectDir())) { - return includedBuild.getProjectDir(); - } - } - - // Otherwise assume this gradle is the root elasticsearch workspace - return gradle.getRootProject().getRootDir(); - } else { - // We're an included build, so keep looking - return locateElasticsearchWorkspace(gradle.getParent()); - } + return buildToolsParent; } + if (gradle.getParent() == null) { + // See if any of these included builds is the Elasticsearch gradle + for (IncludedBuild includedBuild : gradle.getIncludedBuilds()) { + if (versionFileExists(includedBuild.getProjectDir())) { + return includedBuild.getProjectDir(); + } + } + + // Otherwise assume this gradle is the root elasticsearch workspace + return gradle.getRootProject().getRootDir(); + } else { + // We're an included build, so keep looking + return locateElasticsearchWorkspace(gradle.getParent()); + } + } private static boolean versionFileExists(File rootDir) { return new File(rootDir, "build-tools-internal/version.properties").exists(); diff --git a/build-tools-internal/src/main/java/org/elasticsearch/gradle/internal/ElasticsearchTestBasePlugin.java b/build-tools-internal/src/main/java/org/elasticsearch/gradle/internal/ElasticsearchTestBasePlugin.java index 31b62c4ac700..ed2dfb577e03 100644 --- a/build-tools-internal/src/main/java/org/elasticsearch/gradle/internal/ElasticsearchTestBasePlugin.java +++ b/build-tools-internal/src/main/java/org/elasticsearch/gradle/internal/ElasticsearchTestBasePlugin.java @@ -144,6 +144,7 @@ public class ElasticsearchTestBasePlugin implements Plugin { // don't track these as inputs since they contain absolute paths and break cache relocatability File gradleUserHome = project.getGradle().getGradleUserHomeDir(); nonInputProperties.systemProperty("gradle.user.home", gradleUserHome); + nonInputProperties.systemProperty("workspace.dir", Util.locateElasticsearchWorkspace(project.getGradle())); // we use 'temp' relative to CWD since this is per JVM and tests are forbidden from writing to CWD nonInputProperties.systemProperty("java.io.tmpdir", test.getWorkingDir().toPath().resolve("temp")); diff --git a/test/fixtures/testcontainer-utils/src/main/java/org/elasticsearch/test/fixtures/testcontainers/DockerEnvironmentAwareTestContainer.java b/test/fixtures/testcontainer-utils/src/main/java/org/elasticsearch/test/fixtures/testcontainers/DockerEnvironmentAwareTestContainer.java index be8d597c2601..11063dc4cf10 100644 --- a/test/fixtures/testcontainer-utils/src/main/java/org/elasticsearch/test/fixtures/testcontainers/DockerEnvironmentAwareTestContainer.java +++ b/test/fixtures/testcontainer-utils/src/main/java/org/elasticsearch/test/fixtures/testcontainers/DockerEnvironmentAwareTestContainer.java @@ -115,7 +115,7 @@ public abstract class DockerEnvironmentAwareTestContainer extends GenericContain } private static List getLinuxExclusionList() { - File exclusionsFile = new File(DOCKER_ON_LINUX_EXCLUSIONS_FILE); + File exclusionsFile = new File(System.getProperty("workspace.dir"), DOCKER_ON_LINUX_EXCLUSIONS_FILE); if (exclusionsFile.exists()) { try { return Files.readAllLines(exclusionsFile.toPath())