From ccf3e443b555646323411938f3ace03a6ed97db3 Mon Sep 17 00:00:00 2001 From: Jay Modi Date: Fri, 17 Jan 2020 10:56:22 -0700 Subject: [PATCH] Improve file filter for insecure repo tests (#51121) (#51170) Tests in BuildPluginIT copy the workspace but exclude the build directories based on whether the directory string representation includes `/build/` or not. This check is problematic if the directory of the project has a parent directory also named `build`. The change in this commit checks to see if the path relative to the project directory has any path parts equal to `build`. --- .../java/org/elasticsearch/gradle/BuildPluginIT.java | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/buildSrc/src/test/java/org/elasticsearch/gradle/BuildPluginIT.java b/buildSrc/src/test/java/org/elasticsearch/gradle/BuildPluginIT.java index c69a23021f5..57864326629 100644 --- a/buildSrc/src/test/java/org/elasticsearch/gradle/BuildPluginIT.java +++ b/buildSrc/src/test/java/org/elasticsearch/gradle/BuildPluginIT.java @@ -31,6 +31,7 @@ import java.io.IOException; import java.io.InputStream; import java.nio.charset.StandardCharsets; import java.nio.file.Files; +import java.nio.file.Path; import java.util.Arrays; import java.util.List; import java.util.zip.ZipEntry; @@ -84,7 +85,16 @@ public class BuildPluginIT extends GradleIntegrationTestCase { private void runInsecureArtifactRepositoryTest(final String name, final String url, final List lines) throws IOException { final File projectDir = getProjectDir("elasticsearch.build"); - FileUtils.copyDirectory(projectDir, tmpDir.getRoot(), pathname -> pathname.getPath().contains("/build/") == false); + final Path projectDirPath = projectDir.toPath(); + FileUtils.copyDirectory(projectDir, tmpDir.getRoot(), file -> { + final Path relativePath = projectDirPath.relativize(file.toPath()); + for (Path segment : relativePath) { + if (segment.toString().equals("build")) { + return false; + } + } + return true; + }); final List buildGradleLines = Files.readAllLines(tmpDir.getRoot().toPath().resolve("build.gradle"), StandardCharsets.UTF_8); buildGradleLines.addAll(lines); Files.write(tmpDir.getRoot().toPath().resolve("build.gradle"), buildGradleLines, StandardCharsets.UTF_8);