From 6a5d9195aa6b50ccdcd5ce4e1231b05eae91868d Mon Sep 17 00:00:00 2001 From: Jake Landis Date: Thu, 5 Mar 2020 17:41:17 -0600 Subject: [PATCH] =?UTF-8?q?[7.x]=20Ensure=20only=20plugin=20REST=20tests?= =?UTF-8?q?=20are=20run=20for=20plugins=20(#5318=E2=80=A6=20(#53196)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This commit fixes ensures that for external builds (e.g. plugin development) that the REST tests that are copied are properly filtered to only include the API by default. The code prior to this change resulted in including both the API and tests since the copy.include resulted as an empty list by default since the stream is empty unless explicitly configured. related #52114 fixes #53183 --- .../gradle/test/rest/CopyRestApiTask.java | 12 +++++++++--- .../gradle/test/rest/CopyRestTestsTask.java | 8 +++++--- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/buildSrc/src/main/java/org/elasticsearch/gradle/test/rest/CopyRestApiTask.java b/buildSrc/src/main/java/org/elasticsearch/gradle/test/rest/CopyRestApiTask.java index 810762a08e8..1cb3034419b 100644 --- a/buildSrc/src/main/java/org/elasticsearch/gradle/test/rest/CopyRestApiTask.java +++ b/buildSrc/src/main/java/org/elasticsearch/gradle/test/rest/CopyRestApiTask.java @@ -51,7 +51,7 @@ import java.util.stream.Collectors; * @see RestResourcesPlugin */ public class CopyRestApiTask extends DefaultTask { - private static final String COPY_TO = "rest-api-spec/api"; + private static final String REST_API_PREFIX = "rest-api-spec/api"; final ListProperty includeCore = getProject().getObjects().listProperty(String.class); final ListProperty includeXpack = getProject().getObjects().listProperty(String.class); @@ -109,7 +109,7 @@ public class CopyRestApiTask extends DefaultTask { @OutputDirectory public File getOutputDir() { - return new File(getTestSourceSet().getOutput().getResourcesDir(), COPY_TO); + return new File(getTestSourceSet().getOutput().getResourcesDir(), REST_API_PREFIX); } @TaskAction @@ -132,7 +132,13 @@ public class CopyRestApiTask extends DefaultTask { project.copy(c -> { c.from(project.zipTree(coreConfig.getSingleFile())); c.into(getTestSourceSet().getOutput().getResourcesDir()); // this ends up as the same dir as outputDir - c.include(includeCore.get().stream().map(prefix -> COPY_TO + "/" + prefix + "*/**").collect(Collectors.toList())); + if (includeCore.get().isEmpty()) { + c.include(REST_API_PREFIX + "/**"); + } else { + c.include( + includeCore.get().stream().map(prefix -> REST_API_PREFIX + "/" + prefix + "*/**").collect(Collectors.toList()) + ); + } }); } // only copy x-pack specs if explicitly instructed diff --git a/buildSrc/src/main/java/org/elasticsearch/gradle/test/rest/CopyRestTestsTask.java b/buildSrc/src/main/java/org/elasticsearch/gradle/test/rest/CopyRestTestsTask.java index 046bb5a6d1a..9e9d1e0d9e7 100644 --- a/buildSrc/src/main/java/org/elasticsearch/gradle/test/rest/CopyRestTestsTask.java +++ b/buildSrc/src/main/java/org/elasticsearch/gradle/test/rest/CopyRestTestsTask.java @@ -48,7 +48,7 @@ import java.util.stream.Collectors; * @see RestResourcesPlugin */ public class CopyRestTestsTask extends DefaultTask { - private static final String COPY_TO = "rest-api-spec/test"; + private static final String REST_TEST_PREFIX = "rest-api-spec/test"; final ListProperty includeCore = getProject().getObjects().listProperty(String.class); final ListProperty includeXpack = getProject().getObjects().listProperty(String.class); @@ -103,7 +103,7 @@ public class CopyRestTestsTask extends DefaultTask { @OutputDirectory public File getOutputDir() { - return new File(getTestSourceSet().getOutput().getResourcesDir(), COPY_TO); + return new File(getTestSourceSet().getOutput().getResourcesDir(), REST_TEST_PREFIX); } @TaskAction @@ -128,7 +128,9 @@ public class CopyRestTestsTask extends DefaultTask { project.copy(c -> { c.from(project.zipTree(coreConfig.getSingleFile())); c.into(getTestSourceSet().getOutput().getResourcesDir()); // this ends up as the same dir as outputDir - c.include(includeCore.get().stream().map(prefix -> COPY_TO + "/" + prefix + "*/**").collect(Collectors.toList())); + c.include( + includeCore.get().stream().map(prefix -> REST_TEST_PREFIX + "/" + prefix + "*/**").collect(Collectors.toList()) + ); }); } }