Bladeren bron

Smarter copying of the rest specs and tests (#52114)

This PR addresses the unnecessary copying of the rest specs and allows
for better semantics for which specs and tests are copied. By default 
the rest specs will get copied if the project applies 
`elasticsearch.standalone-rest-test` or `esplugin` and the project 
has rest tests or you configure the custom extension `restResources`. 

This PR also removes the need for dozens of places where the x-pack 
specs were copied by supporting copying of the x-pack rest specs too. 

The plugin/task introduced here can also copy the rest tests to the 
local project through a similar configuration.

The new plugin/task allows a user to minimize the surface area of 
which rest specs are copied. Per project can be configured to include 
only a subset of the specs (or tests). Configuring a project to only 
copy the specs when actually needed should help with build cache hit 
rates since we can better define what is actually in use. 
However, project level optimizations for build cache hit rates are 
not included with this PR.

Also, with this PR you can no longer use the includePackaged flag on 
integTest task.  

The following items are included in this PR:
* new plugin: `elasticsearch.rest-resources` 
* new tasks: CopyRestApiTask and CopyRestTestsTask - performs the copy 
* new extension 'restResources'
```
restResources {
  restApi {
    includeCore 'foo' , 'bar' //will include the core specs that start with foo and bar
    includeXpack 'baz' //will include x-pack specs that start with baz
  }
  restTests {
    includeCore 'foo', 'bar' //will include the core tests that start with foo and bar
    includeXpack 'baz' //will include the x-pack tests that start with baz
  }
}

```
Jake Landis 5 jaren geleden
bovenliggende
commit
810dc9fce3
49 gewijzigde bestanden met toevoegingen van 743 en 346 verwijderingen
  1. 2 0
      buildSrc/src/main/groovy/org/elasticsearch/gradle/plugin/PluginBuildPlugin.groovy
  2. 1 54
      buildSrc/src/main/groovy/org/elasticsearch/gradle/test/RestIntegTestTask.groovy
  3. 4 1
      buildSrc/src/main/groovy/org/elasticsearch/gradle/test/StandaloneRestTestPlugin.groovy
  4. 1 1
      buildSrc/src/main/java/org/elasticsearch/gradle/precommit/TestingConventionsTasks.java
  5. 195 0
      buildSrc/src/main/java/org/elasticsearch/gradle/test/rest/CopyRestApiTask.java
  6. 141 0
      buildSrc/src/main/java/org/elasticsearch/gradle/test/rest/CopyRestTestsTask.java
  7. 79 0
      buildSrc/src/main/java/org/elasticsearch/gradle/test/rest/RestResourcesExtension.java
  8. 138 0
      buildSrc/src/main/java/org/elasticsearch/gradle/test/rest/RestResourcesPlugin.java
  9. 20 0
      buildSrc/src/main/resources/META-INF/gradle-plugins/elasticsearch.rest-resources.properties
  10. 5 16
      client/rest-high-level/build.gradle
  11. 6 1
      distribution/archives/build.gradle
  12. 0 6
      distribution/docker/build.gradle
  13. 6 0
      docs/build.gradle
  14. 4 11
      qa/mixed-cluster/build.gradle
  15. 0 9
      qa/remote-clusters/build.gradle
  16. 0 15
      qa/rolling-upgrade/build.gradle
  17. 4 2
      qa/smoke-test-multinode/build.gradle
  18. 10 0
      rest-api-spec/build.gradle
  19. 5 6
      x-pack/docs/build.gradle
  20. 0 12
      x-pack/plugin/autoscaling/qa/build.gradle
  21. 6 0
      x-pack/plugin/autoscaling/qa/rest/build.gradle
  22. 7 0
      x-pack/plugin/build.gradle
  23. 0 12
      x-pack/plugin/ccr/qa/build.gradle
  24. 6 0
      x-pack/plugin/ccr/qa/rest/build.gradle
  25. 0 9
      x-pack/plugin/enrich/qa/build.gradle
  26. 6 0
      x-pack/plugin/enrich/qa/rest/build.gradle
  27. 0 9
      x-pack/plugin/eql/qa/build.gradle
  28. 6 0
      x-pack/plugin/eql/qa/rest/build.gradle
  29. 0 17
      x-pack/plugin/graph/qa/build.gradle
  30. 7 6
      x-pack/plugin/graph/qa/with-security/build.gradle
  31. 0 11
      x-pack/plugin/ilm/qa/build.gradle
  32. 6 0
      x-pack/plugin/ilm/qa/rest/build.gradle
  33. 0 17
      x-pack/plugin/ml/qa/build.gradle
  34. 7 7
      x-pack/plugin/ml/qa/ml-with-security/build.gradle
  35. 0 11
      x-pack/plugin/security/qa/build.gradle
  36. 0 18
      x-pack/qa/build.gradle
  37. 6 1
      x-pack/qa/core-rest-tests-with-security/build.gradle
  38. 0 20
      x-pack/qa/full-cluster-restart/build.gradle
  39. 6 0
      x-pack/qa/multi-cluster-search-security/build.gradle
  40. 6 0
      x-pack/qa/multi-cluster-tests-with-security/build.gradle
  41. 0 20
      x-pack/qa/rolling-upgrade-basic/build.gradle
  42. 0 19
      x-pack/qa/rolling-upgrade-multi-cluster/build.gradle
  43. 7 19
      x-pack/qa/rolling-upgrade/build.gradle
  44. 6 0
      x-pack/qa/smoke-test-security-with-mustache/build.gradle
  45. 7 6
      x-pack/qa/smoke-test-watcher-with-security/build.gradle
  46. 6 0
      x-pack/qa/smoke-test-watcher/build.gradle
  47. 13 10
      x-pack/qa/third-party/jira/build.gradle
  48. 7 0
      x-pack/qa/third-party/pagerduty/build.gradle
  49. 7 0
      x-pack/qa/third-party/slack/build.gradle

+ 2 - 0
buildSrc/src/main/groovy/org/elasticsearch/gradle/plugin/PluginBuildPlugin.groovy

@@ -24,6 +24,7 @@ import org.elasticsearch.gradle.NoticeTask
 import org.elasticsearch.gradle.Version
 import org.elasticsearch.gradle.VersionProperties
 import org.elasticsearch.gradle.info.BuildParams
+import org.elasticsearch.gradle.test.rest.RestResourcesPlugin
 import org.elasticsearch.gradle.test.RestIntegTestTask
 import org.elasticsearch.gradle.testclusters.RunTask
 import org.elasticsearch.gradle.testclusters.TestClustersPlugin
@@ -51,6 +52,7 @@ class PluginBuildPlugin implements Plugin<Project> {
     void apply(Project project) {
         project.pluginManager.apply(BuildPlugin)
         project.pluginManager.apply(TestClustersPlugin)
+        project.pluginManager.apply(RestResourcesPlugin)
 
         PluginPropertiesExtension extension = project.extensions.create(PLUGIN_EXTENSION_NAME, PluginPropertiesExtension, project)
         configureDependencies(project)

+ 1 - 54
buildSrc/src/main/groovy/org/elasticsearch/gradle/test/RestIntegTestTask.groovy

@@ -18,18 +18,12 @@
  */
 package org.elasticsearch.gradle.test
 
-import org.elasticsearch.gradle.VersionProperties
-import org.elasticsearch.gradle.info.BuildParams
 import org.elasticsearch.gradle.testclusters.ElasticsearchCluster
 import org.elasticsearch.gradle.testclusters.RestTestRunnerTask
-import org.elasticsearch.gradle.tool.Boilerplate
 import org.gradle.api.DefaultTask
 import org.gradle.api.Task
-import org.gradle.api.file.FileCopyDetails
-import org.gradle.api.tasks.Copy
-import org.gradle.api.tasks.Input
 import org.gradle.api.tasks.testing.Test
-import org.gradle.plugins.ide.idea.IdeaPlugin
+
 /**
  * A wrapper task around setting up a cluster and running rest tests.
  */
@@ -37,10 +31,6 @@ class RestIntegTestTask extends DefaultTask {
 
     protected Test runner
 
-    /** Flag indicating whether the rest tests in the rest spec should be run. */
-    @Input
-    Boolean includePackaged = false
-
     RestIntegTestTask() {
         runner = project.tasks.create("${name}Runner", RestTestRunnerTask.class)
         super.dependsOn(runner)
@@ -69,10 +59,6 @@ class RestIntegTestTask extends DefaultTask {
             runner.systemProperty('test.clustername', System.getProperty("tests.clustername"))
         }
 
-        // copy the rest spec/tests onto the test classpath
-        Copy copyRestSpec = createCopyRestSpecTask()
-        project.sourceSets.test.output.builtBy(copyRestSpec)
-
         // this must run after all projects have been configured, so we know any project
         // references can be accessed as a fully configured
         project.gradle.projectsEvaluated {
@@ -83,12 +69,6 @@ class RestIntegTestTask extends DefaultTask {
         }
     }
 
-    /** Sets the includePackaged property */
-    public void includePackaged(boolean include) {
-        includePackaged = include
-    }
-
-
     @Override
     public Task dependsOn(Object... dependencies) {
         runner.dependsOn(dependencies)
@@ -114,37 +94,4 @@ class RestIntegTestTask extends DefaultTask {
         project.tasks.getByName("${name}Runner").configure(configure)
     }
 
-    Copy createCopyRestSpecTask() {
-        Boilerplate.maybeCreate(project.configurations, 'restSpec') {
-            project.dependencies.add(
-                    'restSpec',
-                    BuildParams.internal ? project.project(':rest-api-spec') :
-                            "org.elasticsearch:rest-api-spec:${VersionProperties.elasticsearch}"
-            )
-        }
-
-        return Boilerplate.maybeCreate(project.tasks, 'copyRestSpec', Copy) { Copy copy ->
-            copy.dependsOn project.configurations.restSpec
-            copy.into(project.sourceSets.test.output.resourcesDir)
-            copy.from({ project.zipTree(project.configurations.restSpec.singleFile) }) {
-                includeEmptyDirs = false
-                include 'rest-api-spec/**'
-                filesMatching('rest-api-spec/test/**') { FileCopyDetails details ->
-                    if (includePackaged == false) {
-                        details.exclude()
-                    }
-                }
-            }
-
-            if (project.plugins.hasPlugin(IdeaPlugin)) {
-                project.idea {
-                    module {
-                        if (scopes.TEST != null) {
-                            scopes.TEST.plus.add(project.configurations.restSpec)
-                        }
-                    }
-                }
-            }
-        }
-    }
 }

+ 4 - 1
buildSrc/src/main/groovy/org/elasticsearch/gradle/test/StandaloneRestTestPlugin.groovy

@@ -26,9 +26,9 @@ import org.elasticsearch.gradle.ExportElasticsearchBuildResourcesTask
 import org.elasticsearch.gradle.info.BuildParams
 import org.elasticsearch.gradle.info.GlobalBuildInfoPlugin
 import org.elasticsearch.gradle.precommit.PrecommitTasks
+import org.elasticsearch.gradle.test.rest.RestResourcesPlugin
 import org.elasticsearch.gradle.testclusters.TestClustersPlugin
 import org.gradle.api.InvalidUserDataException
-import org.gradle.api.JavaVersion
 import org.gradle.api.Plugin
 import org.gradle.api.Project
 import org.gradle.api.artifacts.Configuration
@@ -42,6 +42,7 @@ import org.gradle.api.tasks.compile.JavaCompile
 import org.gradle.api.tasks.testing.Test
 import org.gradle.plugins.ide.eclipse.model.EclipseModel
 import org.gradle.plugins.ide.idea.model.IdeaModel
+
 /**
  * Configures the build to compile tests against Elasticsearch's test framework
  * and run REST tests. Use BuildPlugin if you want to build main code as well
@@ -74,6 +75,8 @@ class StandaloneRestTestPlugin implements Plugin<Project> {
         // only setup tests to build
         SourceSetContainer sourceSets = project.extensions.getByType(SourceSetContainer)
         SourceSet testSourceSet = sourceSets.create('test')
+        // need to apply plugin after test source sets are created
+        project.pluginManager.apply(RestResourcesPlugin)
 
         project.tasks.withType(Test) { Test test ->
             test.testClassesDirs = testSourceSet.output.classesDirs

+ 1 - 1
buildSrc/src/main/java/org/elasticsearch/gradle/precommit/TestingConventionsTasks.java

@@ -250,7 +250,7 @@ public class TestingConventionsTasks extends DefaultTask {
             Files.write(getSuccessMarker().toPath(), new byte[] {}, StandardOpenOption.CREATE);
         } else {
             getLogger().error(problems);
-            throw new IllegalStateException("Testing conventions are not honored");
+            throw new IllegalStateException(String.format("Testing conventions [%s] are not honored", problems));
         }
     }
 

+ 195 - 0
buildSrc/src/main/java/org/elasticsearch/gradle/test/rest/CopyRestApiTask.java

@@ -0,0 +1,195 @@
+/*
+ * Licensed to Elasticsearch under one or more contributor
+ * license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright
+ * ownership. Elasticsearch licenses this file to you under
+ * the Apache License, Version 2.0 (the "License"); you may
+ * not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.elasticsearch.gradle.test.rest;
+
+import org.elasticsearch.gradle.VersionProperties;
+import org.elasticsearch.gradle.info.BuildParams;
+import org.elasticsearch.gradle.tool.Boilerplate;
+import org.gradle.api.DefaultTask;
+import org.gradle.api.Project;
+import org.gradle.api.artifacts.Configuration;
+import org.gradle.api.file.ConfigurableFileCollection;
+import org.gradle.api.file.FileTree;
+import org.gradle.api.provider.ListProperty;
+import org.gradle.api.tasks.Input;
+import org.gradle.api.tasks.InputFiles;
+import org.gradle.api.tasks.OutputDirectory;
+import org.gradle.api.tasks.SkipWhenEmpty;
+import org.gradle.api.tasks.SourceSet;
+import org.gradle.api.tasks.TaskAction;
+import org.gradle.api.tasks.util.PatternFilterable;
+import org.gradle.api.tasks.util.PatternSet;
+import org.gradle.internal.Factory;
+
+import javax.inject.Inject;
+import java.io.File;
+import java.io.IOException;
+import java.nio.file.Files;
+import java.util.Set;
+import java.util.stream.Collectors;
+
+/**
+ * Copies the files needed for the Rest YAML specs to the current projects test resources output directory.
+ * This is intended to be be used from {@link RestResourcesPlugin} since the plugin wires up the needed
+ * configurations and custom extensions.
+ * @see RestResourcesPlugin
+ */
+public class CopyRestApiTask extends DefaultTask {
+    private static final String COPY_TO = "rest-api-spec/api";
+    final ListProperty<String> includeCore = getProject().getObjects().listProperty(String.class);
+    final ListProperty<String> includeXpack = getProject().getObjects().listProperty(String.class);
+
+    Configuration coreConfig;
+    Configuration xpackConfig;
+
+    private final PatternFilterable corePatternSet;
+    private final PatternFilterable xpackPatternSet;
+
+    public CopyRestApiTask() {
+        corePatternSet = getPatternSetFactory().create();
+        xpackPatternSet = getPatternSetFactory().create();
+    }
+
+    @Inject
+    protected Factory<PatternSet> getPatternSetFactory() {
+        throw new UnsupportedOperationException();
+    }
+
+    @Input
+    public ListProperty<String> getIncludeCore() {
+        return includeCore;
+    }
+
+    @Input
+    public ListProperty<String> getIncludeXpack() {
+        return includeXpack;
+    }
+
+    @SkipWhenEmpty
+    @InputFiles
+    public FileTree getInputDir() {
+        xpackPatternSet.setIncludes(includeXpack.get().stream().map(prefix -> prefix + "*/**").collect(Collectors.toList()));
+        ConfigurableFileCollection fileCollection = getProject().files(xpackConfig.getAsFileTree().matching(xpackPatternSet));
+        if (BuildParams.isInternal()) {
+            corePatternSet.setIncludes(includeCore.get().stream().map(prefix -> prefix + "*/**").collect(Collectors.toList()));
+            fileCollection.plus(coreConfig.getAsFileTree().matching(corePatternSet));
+        } else {
+            fileCollection.plus(coreConfig);
+        }
+        // if project has rest tests or the includes are explicitly configured execute the task, else NO-SOURCE due to the null input
+        return projectHasYamlRestTests() || includeCore.get().isEmpty() == false || includeXpack.get().isEmpty() == false
+            ? fileCollection.getAsFileTree()
+            : null;
+    }
+
+    @OutputDirectory
+    public File getOutputDir() {
+        return new File(getTestSourceSet().getOutput().getResourcesDir(), COPY_TO);
+    }
+
+    @TaskAction
+    void copy() {
+        Project project = getProject();
+        // always copy the core specs if the task executes
+        if (BuildParams.isInternal()) {
+            getLogger().debug("Rest specs for project [{}] will be copied to the test resources.", project.getPath());
+            project.copy(c -> {
+                c.from(coreConfig.getSingleFile());
+                c.into(getOutputDir());
+                c.include(corePatternSet.getIncludes());
+            });
+        } else {
+            getLogger().debug(
+                "Rest specs for project [{}] will be copied to the test resources from the published jar (version: [{}]).",
+                project.getPath(),
+                VersionProperties.getElasticsearch()
+            );
+            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()));
+            });
+        }
+        // only copy x-pack specs if explicitly instructed
+        if (includeXpack.get().isEmpty() == false) {
+            getLogger().debug("X-pack rest specs for project [{}] will be copied to the test resources.", project.getPath());
+            project.copy(c -> {
+                c.from(xpackConfig.getSingleFile());
+                c.into(getOutputDir());
+                c.include(xpackPatternSet.getIncludes());
+            });
+        }
+    }
+
+    /**
+     * Returns true if any files with a .yml extension exist the test resources rest-api-spec/test directory (from source or output dir)
+     */
+    private boolean projectHasYamlRestTests() {
+        File testSourceResourceDir = getTestSourceResourceDir();
+        File testOutputResourceDir = getTestOutputResourceDir(); // check output for cases where tests are copied programmatically
+
+        if (testSourceResourceDir == null && testOutputResourceDir == null) {
+            return false;
+        }
+        try {
+            if (testSourceResourceDir != null) {
+                return new File(testSourceResourceDir, "rest-api-spec/test").exists() == false
+                    || Files.walk(testSourceResourceDir.toPath().resolve("rest-api-spec/test"))
+                        .anyMatch(p -> p.getFileName().toString().endsWith("yml"));
+            }
+            if (testOutputResourceDir != null) {
+                return new File(testOutputResourceDir, "rest-api-spec/test").exists() == false
+                    || Files.walk(testOutputResourceDir.toPath().resolve("rest-api-spec/test"))
+                        .anyMatch(p -> p.getFileName().toString().endsWith("yml"));
+            }
+        } catch (IOException e) {
+            throw new IllegalStateException(String.format("Error determining if this project [%s] has rest tests.", getProject()), e);
+        }
+        return false;
+    }
+
+    private File getTestSourceResourceDir() {
+        SourceSet testSources = getTestSourceSet();
+        if (testSources == null) {
+            return null;
+        }
+        Set<File> resourceDir = testSources.getResources()
+            .getSrcDirs()
+            .stream()
+            .filter(f -> f.isDirectory() && f.getParentFile().getName().equals("test") && f.getName().equals("resources"))
+            .collect(Collectors.toSet());
+        assert resourceDir.size() <= 1;
+        if (resourceDir.size() == 0) {
+            return null;
+        }
+        return resourceDir.iterator().next();
+    }
+
+    private File getTestOutputResourceDir() {
+        SourceSet testSources = getTestSourceSet();
+        if (testSources == null) {
+            return null;
+        }
+        return testSources.getOutput().getResourcesDir();
+    }
+
+    private SourceSet getTestSourceSet() {
+        return Boilerplate.getJavaSourceSets(getProject()).findByName("test");
+    }
+}

+ 141 - 0
buildSrc/src/main/java/org/elasticsearch/gradle/test/rest/CopyRestTestsTask.java

@@ -0,0 +1,141 @@
+/*
+ * Licensed to Elasticsearch under one or more contributor
+ * license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright
+ * ownership. Elasticsearch licenses this file to you under
+ * the Apache License, Version 2.0 (the "License"); you may
+ * not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.elasticsearch.gradle.test.rest;
+
+import org.elasticsearch.gradle.VersionProperties;
+import org.elasticsearch.gradle.info.BuildParams;
+import org.elasticsearch.gradle.tool.Boilerplate;
+import org.gradle.api.DefaultTask;
+import org.gradle.api.Project;
+import org.gradle.api.artifacts.Configuration;
+import org.gradle.api.file.ConfigurableFileCollection;
+import org.gradle.api.file.FileTree;
+import org.gradle.api.provider.ListProperty;
+import org.gradle.api.tasks.Input;
+import org.gradle.api.tasks.InputFiles;
+import org.gradle.api.tasks.OutputDirectory;
+import org.gradle.api.tasks.SkipWhenEmpty;
+import org.gradle.api.tasks.SourceSet;
+import org.gradle.api.tasks.TaskAction;
+import org.gradle.api.tasks.util.PatternFilterable;
+import org.gradle.api.tasks.util.PatternSet;
+import org.gradle.internal.Factory;
+
+import javax.inject.Inject;
+import java.io.File;
+import java.util.stream.Collectors;
+
+/**
+ * Copies the Rest YAML test to the current projects test resources output directory.
+ * This is intended to be be used from {@link RestResourcesPlugin} since the plugin wires up the needed
+ * configurations and custom extensions.
+ * @see RestResourcesPlugin
+ */
+public class CopyRestTestsTask extends DefaultTask {
+    private static final String COPY_TO = "rest-api-spec/test";
+    final ListProperty<String> includeCore = getProject().getObjects().listProperty(String.class);
+    final ListProperty<String> includeXpack = getProject().getObjects().listProperty(String.class);
+
+    Configuration coreConfig;
+    Configuration xpackConfig;
+
+    private final PatternFilterable corePatternSet;
+    private final PatternFilterable xpackPatternSet;
+
+    public CopyRestTestsTask() {
+        corePatternSet = getPatternSetFactory().create();
+        xpackPatternSet = getPatternSetFactory().create();
+    }
+
+    @Inject
+    protected Factory<PatternSet> getPatternSetFactory() {
+        throw new UnsupportedOperationException();
+    }
+
+    @Input
+    public ListProperty<String> getIncludeCore() {
+        return includeCore;
+    }
+
+    @Input
+    public ListProperty<String> getIncludeXpack() {
+        return includeXpack;
+    }
+
+    @SkipWhenEmpty
+    @InputFiles
+    public FileTree getInputDir() {
+        xpackPatternSet.setIncludes(includeXpack.get().stream().map(prefix -> prefix + "*/**").collect(Collectors.toList()));
+        ConfigurableFileCollection fileCollection = getProject().files(xpackConfig.getAsFileTree().matching(xpackPatternSet));
+        if (BuildParams.isInternal()) {
+            corePatternSet.setIncludes(includeCore.get().stream().map(prefix -> prefix + "*/**").collect(Collectors.toList()));
+            fileCollection.plus(coreConfig.getAsFileTree().matching(corePatternSet));
+        } else {
+            fileCollection.plus(coreConfig);
+        }
+        // copy tests only if explicitly requested
+        return includeCore.get().isEmpty() == false || includeXpack.get().isEmpty() == false ? fileCollection.getAsFileTree() : null;
+    }
+
+    @OutputDirectory
+    public File getOutputDir() {
+        return new File(getTestSourceSet().getOutput().getResourcesDir(), COPY_TO);
+    }
+
+    @TaskAction
+    void copy() {
+        Project project = getProject();
+        // only copy core tests if explicitly instructed
+        if (includeCore.get().isEmpty() == false) {
+            if (BuildParams.isInternal()) {
+                getLogger().debug("Rest tests for project [{}] will be copied to the test resources.", project.getPath());
+                project.copy(c -> {
+                    c.from(coreConfig.getSingleFile());
+                    c.into(getOutputDir());
+                    c.include(corePatternSet.getIncludes());
+                });
+
+            } else {
+                getLogger().debug(
+                    "Rest tests for project [{}] will be copied to the test resources from the published jar (version: [{}]).",
+                    project.getPath(),
+                    VersionProperties.getElasticsearch()
+                );
+                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()));
+                });
+            }
+        }
+        // only copy x-pack tests if explicitly instructed
+        if (includeXpack.get().isEmpty() == false) {
+            getLogger().debug("X-pack rest tests for project [{}] will be copied to the test resources.", project.getPath());
+            project.copy(c -> {
+                c.from(xpackConfig.getSingleFile());
+                c.into(getOutputDir());
+                c.include(xpackPatternSet.getIncludes());
+            });
+        }
+    }
+
+    private SourceSet getTestSourceSet() {
+        return Boilerplate.getJavaSourceSets(getProject()).findByName("test");
+    }
+}

+ 79 - 0
buildSrc/src/main/java/org/elasticsearch/gradle/test/rest/RestResourcesExtension.java

@@ -0,0 +1,79 @@
+/*
+ * Licensed to Elasticsearch under one or more contributor
+ * license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright
+ * ownership. Elasticsearch licenses this file to you under
+ * the Apache License, Version 2.0 (the "License"); you may
+ * not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.elasticsearch.gradle.test.rest;
+
+import org.elasticsearch.gradle.info.BuildParams;
+import org.gradle.api.Action;
+import org.gradle.api.model.ObjectFactory;
+import org.gradle.api.provider.ListProperty;
+
+import javax.inject.Inject;
+
+/**
+ * Custom extension to configure the {@link CopyRestApiTask}
+ */
+public class RestResourcesExtension {
+
+    final RestResourcesSpec restApi;
+    final RestResourcesSpec restTests;
+
+    @Inject
+    public RestResourcesExtension(ObjectFactory objects) {
+        restApi = new RestResourcesSpec(objects);
+        restTests = new RestResourcesSpec(objects);
+    }
+
+    void restApi(Action<? super RestResourcesSpec> spec) {
+        spec.execute(restApi);
+    }
+
+    void restTests(Action<? super RestResourcesSpec> spec) {
+        spec.execute(restTests);
+    }
+
+    static class RestResourcesSpec {
+
+        private final ListProperty<String> includeCore;
+        private final ListProperty<String> includeXpack;
+
+        RestResourcesSpec(ObjectFactory objects) {
+            includeCore = objects.listProperty(String.class);
+            includeXpack = objects.listProperty(String.class);
+        }
+
+        public void includeCore(String... include) {
+            this.includeCore.addAll(include);
+        }
+
+        public void includeXpack(String... include) {
+            if (BuildParams.isInternal() == false) {
+                throw new IllegalStateException("Can not include x-pack rest resources from an external build.");
+            }
+            this.includeXpack.addAll(include);
+        }
+
+        public ListProperty<String> getIncludeCore() {
+            return includeCore;
+        }
+
+        public ListProperty<String> getIncludeXpack() {
+            return includeXpack;
+        }
+    }
+}

+ 138 - 0
buildSrc/src/main/java/org/elasticsearch/gradle/test/rest/RestResourcesPlugin.java

@@ -0,0 +1,138 @@
+/*
+ * Licensed to Elasticsearch under one or more contributor
+ * license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright
+ * ownership. Elasticsearch licenses this file to you under
+ * the Apache License, Version 2.0 (the "License"); you may
+ * not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.elasticsearch.gradle.test.rest;
+
+import org.elasticsearch.gradle.VersionProperties;
+import org.elasticsearch.gradle.info.BuildParams;
+import org.gradle.api.Plugin;
+import org.gradle.api.Project;
+import org.gradle.api.artifacts.Dependency;
+import org.gradle.api.provider.Provider;
+
+import java.util.Map;
+
+/**
+ * <p>
+ * Gradle plugin to help configure {@link CopyRestApiTask}'s and {@link CopyRestTestsTask} that copies the artifacts needed for the Rest API
+ * spec and YAML based rest tests.
+ * </p>
+ * <strong>Rest API specification:</strong> <br>
+ * When the {@link RestResourcesPlugin} has been applied the {@link CopyRestApiTask} will automatically copy the core Rest API specification
+ * if there are any Rest YAML tests present in source, or copied from {@link CopyRestTestsTask} output. X-pack specs must be explicitly
+ * declared to be copied.
+ * <br>
+ * <i>For example:</i>
+ * <pre>
+ * restResources {
+ *   restApi {
+ *     includeXpack 'enrich'
+ *   }
+ * }
+ * </pre>
+ * Will copy the entire core Rest API specifications (assuming the project has tests) and any of the the X-pack specs starting with enrich*.
+ * It is recommended (but not required) to also explicitly declare which core specs your project depends on to help optimize the caching
+ * behavior.
+ * <i>For example:</i>
+ * <pre>
+ * restResources {
+ *   restApi {
+ *     includeCore 'index', 'cat'
+ *     includeXpack 'enrich'
+ *   }
+ * }
+ * </pre>
+ * <br>
+ * <strong>Rest YAML tests :</strong> <br>
+ * When the {@link RestResourcesPlugin} has been applied the {@link CopyRestTestsTask} will copy the Rest YAML tests if explicitly
+ * configured with `includeCore` or `includeXpack` through the `restResources.restTests` extension.
+ * <i>For example:</i>
+ * <pre>
+ * restResources {
+ *  restApi {
+ *      includeXpack 'graph'
+ *   }
+ *   restTests {
+ *     includeXpack 'graph'
+ *   }
+ * }
+ * </pre>
+ * Will copy any of the the x-pack tests that start with graph, and will copy the X-pack graph specification, as well as the full core
+ * Rest API specification.
+ *
+ * @see CopyRestApiTask
+ * @see CopyRestTestsTask
+ */
+public class RestResourcesPlugin implements Plugin<Project> {
+
+    private static final String EXTENSION_NAME = "restResources";
+
+    @Override
+    public void apply(Project project) {
+        RestResourcesExtension extension = project.getExtensions().create(EXTENSION_NAME, RestResourcesExtension.class);
+
+        Provider<CopyRestTestsTask> copyRestYamlTestTask = project.getTasks()
+            .register("copyYamlTestsTask", CopyRestTestsTask.class, task -> {
+                task.includeCore.set(extension.restTests.getIncludeCore());
+                task.includeXpack.set(extension.restTests.getIncludeXpack());
+                task.coreConfig = project.getConfigurations().create("restTest");
+                if (BuildParams.isInternal()) {
+                    Dependency restTestdependency = project.getDependencies()
+                        .project(Map.of("path", ":rest-api-spec", "configuration", "restTests"));
+                    project.getDependencies().add(task.coreConfig.getName(), restTestdependency);
+
+                    task.xpackConfig = project.getConfigurations().create("restXpackTest");
+                    Dependency restXPackTestdependency = project.getDependencies()
+                        .project(Map.of("path", ":x-pack:plugin", "configuration", "restXpackTests"));
+                    project.getDependencies().add(task.xpackConfig.getName(), restXPackTestdependency);
+                    task.dependsOn(task.xpackConfig);
+                } else {
+                    Dependency dependency = project.getDependencies()
+                        .create("org.elasticsearch:rest-api-spec:" + VersionProperties.getElasticsearch());
+                    project.getDependencies().add(task.coreConfig.getName(), dependency);
+                }
+                task.dependsOn(task.coreConfig);
+            });
+
+        Provider<CopyRestApiTask> copyRestYamlSpecTask = project.getTasks()
+            .register("copyRestApiSpecsTask", CopyRestApiTask.class, task -> {
+                task.includeCore.set(extension.restApi.getIncludeCore());
+                task.includeXpack.set(extension.restApi.getIncludeXpack());
+                task.dependsOn(copyRestYamlTestTask);
+                task.coreConfig = project.getConfigurations().create("restSpec");
+                if (BuildParams.isInternal()) {
+                    Dependency restSpecDependency = project.getDependencies()
+                        .project(Map.of("path", ":rest-api-spec", "configuration", "restSpecs"));
+                    project.getDependencies().add(task.coreConfig.getName(), restSpecDependency);
+
+                    task.xpackConfig = project.getConfigurations().create("restXpackSpec");
+                    Dependency restXpackSpecDependency = project.getDependencies()
+                        .project(Map.of("path", ":x-pack:plugin", "configuration", "restXpackSpecs"));
+                    project.getDependencies().add(task.xpackConfig.getName(), restXpackSpecDependency);
+                    task.dependsOn(task.xpackConfig);
+                } else {
+                    Dependency dependency = project.getDependencies()
+                        .create("org.elasticsearch:rest-api-spec:" + VersionProperties.getElasticsearch());
+                    project.getDependencies().add(task.coreConfig.getName(), dependency);
+                }
+                task.dependsOn(task.coreConfig);
+            });
+
+        project.getTasks().named("processTestResources").configure(t -> t.dependsOn(copyRestYamlSpecTask));
+    }
+}

+ 20 - 0
buildSrc/src/main/resources/META-INF/gradle-plugins/elasticsearch.rest-resources.properties

@@ -0,0 +1,20 @@
+#
+# Licensed to Elasticsearch under one or more contributor
+# license agreements. See the NOTICE file distributed with
+# this work for additional information regarding copyright
+# ownership. Elasticsearch licenses this file to you under
+# the Apache License, Version 2.0 (the "License"); you may
+# not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#    http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+#
+
+implementation-class=org.elasticsearch.gradle.test.rest.RestResourcesPlugin

+ 5 - 16
client/rest-high-level/build.gradle

@@ -25,6 +25,7 @@ apply plugin: 'elasticsearch.rest-test'
 apply plugin: 'nebula.maven-base-publish'
 apply plugin: 'nebula.maven-scm'
 apply plugin: 'com.github.johnrengelman.shadow'
+apply plugin: 'elasticsearch.rest-resources'
 
 group = 'org.elasticsearch.client'
 archivesBaseName = 'elasticsearch-rest-high-level-client'
@@ -37,15 +38,10 @@ publishing {
   }
 }
 
-configurations {
-  restSpec
-}
-
-idea {
-  module {
-    if (scopes.TEST != null) {
-      scopes.TEST.plus.add(project.configurations.restSpec)
-    }
+restResources {
+  //we need to copy the yaml spec so we can check naming (see RestHighlevelClientTests#testApiNamingConventions)
+  restApi {
+    includeCore '*'
   }
 }
 
@@ -72,16 +68,9 @@ dependencies {
     exclude group: 'org.elasticsearch', module: 'elasticsearch-rest-high-level-client'
   }
   testCompile(project(':x-pack:plugin:eql'))
-
-  restSpec project(':rest-api-spec')
 }
 
-//we need to copy the yaml spec so we can check naming (see RestHighlevelClientTests#testApiNamingConventions)
 processTestResources {
-  dependsOn configurations.restSpec // so that configurations resolve
-  from({ zipTree(configurations.restSpec.singleFile) }) {
-    include 'rest-api-spec/api/**'
-  }
   from(project(':client:rest-high-level').file('src/test/resources'))
 }
 

+ 6 - 1
distribution/archives/build.gradle

@@ -317,9 +317,14 @@ configure(subprojects.findAll { it.name == 'integ-test-zip' }) {
 
   group = "org.elasticsearch.distribution.integ-test-zip"
 
+  restResources {
+    restTests {
+      includeCore '*'
+    }
+  }
+
   integTest {
     dependsOn assemble
-    includePackaged = true
   }
 
   processTestResources {

+ 0 - 6
distribution/docker/build.gradle

@@ -14,13 +14,11 @@ configurations {
   dockerPlugins
   dockerSource
   ossDockerSource
-  restSpec
 }
 
 dependencies {
   dockerSource project(path: ":distribution:archives:linux-tar")
   ossDockerSource project(path: ":distribution:archives:oss-linux-tar")
-  restSpec project(':rest-api-spec')
 }
 
 ext.expansions = { oss, local ->
@@ -138,12 +136,8 @@ preProcessFixture {
 }
 
 processTestResources {
-  from({ zipTree(configurations.restSpec.singleFile) }) {
-    include 'rest-api-spec/api/**'
-  }
   from project(':x-pack:plugin:core')
     .file('src/test/resources/org/elasticsearch/xpack/security/transport/ssl/certs/simple/testnode.jks')
-  dependsOn configurations.restSpec
 }
 
 task integTest(type: Test) {

+ 6 - 0
docs/build.gradle

@@ -41,6 +41,12 @@ buildRestTests.expectedUnconvertedCandidates = [
   'reference/ml/anomaly-detection/apis/update-job.asciidoc'
 ]
 
+restResources {
+  restApi {
+    includeCore '*'
+  }
+}
+
 testClusters.integTest {
   if (singleNode().testDistribution == DEFAULT) {
     setting 'xpack.license.self_generated.type', 'trial'

+ 4 - 11
qa/mixed-cluster/build.gradle

@@ -30,17 +30,10 @@ tasks.register("bwcTest") {
   group = 'verification'
 }
 
-configurations {
-  restSpec
-}
-
-dependencies {
-  restSpec project(':rest-api-spec')
-}
-
-processTestResources {
-  from({ zipTree(configurations.restSpec.singleFile) })
-  dependsOn configurations.restSpec
+restResources {
+  restTests {
+    includeCore '*'
+  }
 }
 
 for (Version bwcVersion : bwcVersions.wireCompatible) {

+ 0 - 9
qa/remote-clusters/build.gradle

@@ -25,12 +25,7 @@ apply plugin: 'elasticsearch.distribution-download'
 
 testFixtures.useFixture()
 
-configurations {
-  restSpec
-}
-
 dependencies {
-  restSpec project(':rest-api-spec')
   testCompile project(':client:rest-high-level')
 }
 
@@ -90,12 +85,8 @@ def createAndSetWritable(Object... locations) {
 }
 
 processTestResources {
-  from({ zipTree(configurations.restSpec.singleFile) }) {
-    include 'rest-api-spec/api/**'
-  }
   from project(':x-pack:plugin:core')
     .file('src/test/resources/org/elasticsearch/xpack/security/transport/ssl/certs/simple/testnode.jks')
-  dependsOn configurations.restSpec
 }
 
 task integTest(type: Test) {

+ 0 - 15
qa/rolling-upgrade/build.gradle

@@ -31,21 +31,6 @@ task bwcTest {
   group = 'verification'
 }
 
-configurations {
-  restSpec
-}
-
-dependencies {
-  restSpec project(':rest-api-spec')
-}
-
-processTestResources {
-  from({ zipTree(configurations.restSpec.singleFile) }) {
-    include 'rest-api-spec/api/**'
-  }
-  dependsOn configurations.restSpec
-}
-
 for (Version bwcVersion : bwcVersions.wireCompatible) {
   /*
    * The goal here is to:

+ 4 - 2
qa/smoke-test-multinode/build.gradle

@@ -21,8 +21,10 @@ apply plugin: 'elasticsearch.testclusters'
 apply plugin: 'elasticsearch.standalone-rest-test'
 apply plugin: 'elasticsearch.rest-test'
 
-integTest {
-  includePackaged = true
+restResources {
+  restTests {
+    includeCore '*'
+  }
 }
 
 File repo = file("$buildDir/testclusters/repo")

+ 10 - 0
rest-api-spec/build.gradle

@@ -4,3 +4,13 @@ apply plugin: 'nebula.maven-scm'
 
 test.enabled = false
 jarHell.enabled = false
+
+configurations {
+  restSpecs
+  restTests
+}
+
+artifacts {
+  restSpecs(new File(projectDir, "src/main/resources/rest-api-spec/api"))
+  restTests(new File(projectDir, "src/main/resources/rest-api-spec/test"))
+}

+ 5 - 6
x-pack/docs/build.gradle

@@ -1,5 +1,3 @@
-import java.nio.charset.StandardCharsets
-
 apply plugin: 'elasticsearch.docs-test'
 
 /* List of files that have snippets that probably should be converted to
@@ -21,10 +19,11 @@ dependencies {
   testCompile project(path: xpackProject('plugin').path, configuration: 'testArtifacts')
 }
 
-// copy xpack rest api
-File xpackResources = new File(xpackProject('plugin').projectDir, 'src/test/resources')
-project.copyRestSpec.from(xpackResources) {
-  include 'rest-api-spec/api/**'
+restResources {
+  restApi {
+    includeCore '*'
+    includeXpack '*'
+  }
 }
 
 testClusters.integTest {

+ 0 - 12
x-pack/plugin/autoscaling/qa/build.gradle

@@ -1,18 +1,6 @@
-import org.elasticsearch.gradle.test.RestIntegTestTask
-
 apply plugin: 'elasticsearch.build'
 test.enabled = false
 
 dependencies {
   compile project(':test:framework')
 }
-
-subprojects {
-  project.tasks.withType(RestIntegTestTask) {
-    final File xPackResources = new File(xpackProject('plugin').projectDir, 'src/test/resources')
-    project.copyRestSpec.from(xPackResources) {
-      include 'rest-api-spec/api/**'
-    }
-  }
-
-}

+ 6 - 0
x-pack/plugin/autoscaling/qa/rest/build.gradle

@@ -9,6 +9,12 @@ dependencies {
   testCompile project(path: xpackModule('autoscaling'), configuration: 'runtime')
 }
 
+restResources {
+  restApi {
+    includeXpack 'autoscaling'
+  }
+}
+
 task restTest(type: RestIntegTestTask) {
   mustRunAfter(precommit)
 }

+ 7 - 0
x-pack/plugin/build.gradle

@@ -13,6 +13,13 @@ dependencies {
 // https://github.com/elastic/x-plugins/issues/724
 configurations {
   testArtifacts.extendsFrom testRuntime
+  restXpackSpecs
+  restXpackTests
+}
+
+artifacts {
+  restXpackSpecs(new File(projectDir, "src/test/resources/rest-api-spec/api"))
+  restXpackTests(new File(projectDir, "src/test/resources/rest-api-spec/test"))
 }
 
 task testJar(type: Jar) {

+ 0 - 12
x-pack/plugin/ccr/qa/build.gradle

@@ -1,18 +1,6 @@
-import org.elasticsearch.gradle.test.RestIntegTestTask
-
 apply plugin: 'elasticsearch.build'
 test.enabled = false
 
 dependencies {
   compile project(':test:framework')
 }
-
-subprojects {
-  project.tasks.withType(RestIntegTestTask) {
-    final File xPackResources = new File(xpackProject('plugin').projectDir, 'src/test/resources')
-    project.copyRestSpec.from(xPackResources) {
-      include 'rest-api-spec/api/**'
-    }
-  }
-
-}

+ 6 - 0
x-pack/plugin/ccr/qa/rest/build.gradle

@@ -3,6 +3,12 @@ import org.elasticsearch.gradle.test.RestIntegTestTask
 apply plugin: 'elasticsearch.testclusters'
 apply plugin: 'elasticsearch.standalone-test'
 
+restResources {
+  restApi {
+    includeXpack 'ccr'
+  }
+}
+
 dependencies {
   testCompile project(path: xpackModule('core'), configuration: 'testArtifacts')
   testCompile project(path: xpackModule('ccr'), configuration: 'runtime')

+ 0 - 9
x-pack/plugin/enrich/qa/build.gradle

@@ -6,12 +6,3 @@ test.enabled = false
 dependencies {
   compile project(':test:framework')
 }
-
-subprojects {
-  project.tasks.withType(RestIntegTestTask) {
-    final File xPackResources = new File(xpackProject('plugin').projectDir, 'src/test/resources')
-    project.copyRestSpec.from(xPackResources) {
-      include 'rest-api-spec/api/**'
-    }
-  }
-}

+ 6 - 0
x-pack/plugin/enrich/qa/rest/build.gradle

@@ -2,6 +2,12 @@ apply plugin: 'elasticsearch.testclusters'
 apply plugin: 'elasticsearch.standalone-rest-test'
 apply plugin: 'elasticsearch.rest-test'
 
+restResources {
+  restApi {
+    includeXpack 'enrich'
+  }
+}
+
 dependencies {
   testCompile project(path: xpackModule('enrich'), configuration: 'runtime')
   testCompile project(path: xpackModule('enrich:qa:common'), configuration: 'runtime')

+ 0 - 9
x-pack/plugin/eql/qa/build.gradle

@@ -6,12 +6,3 @@ test.enabled = false
 dependencies {
   compile project(':test:framework')
 }
-
-subprojects {
-  project.tasks.withType(RestIntegTestTask) {
-    final File xPackResources = new File(xpackProject('plugin').projectDir, 'src/test/resources')
-    project.copyRestSpec.from(xPackResources) {
-      include 'rest-api-spec/api/**'
-    }
-  }
-}

+ 6 - 0
x-pack/plugin/eql/qa/rest/build.gradle

@@ -4,6 +4,12 @@ apply plugin: 'elasticsearch.testclusters'
 apply plugin: 'elasticsearch.standalone-rest-test'
 apply plugin: 'elasticsearch.rest-test'
 
+restResources {
+  restApi {
+    includeXpack 'eql'
+  }
+}
+
 dependencies {
   testCompile project(path: xpackModule('eql'), configuration: 'runtime')
   testCompile project(path: xpackModule('eql:qa:common'), configuration: 'runtime')

+ 0 - 17
x-pack/plugin/graph/qa/build.gradle

@@ -1,17 +0,0 @@
-import org.elasticsearch.gradle.test.RestIntegTestTask
-
-subprojects {
-  // HACK: please fix this
-  // we want to add the rest api specs for xpack to qa tests, but we
-  // need to wait until after the project is evaluated to only apply
-  // to those that rest tests. this used to be done automatically
-  // when xpack was a plugin, but now there is no place with xpack as a module.
-  // instead, we should package these and make them easy to use for rest tests,
-  // but currently, they must be copied into the resources of the test runner.
-  project.tasks.withType(RestIntegTestTask) {
-    File xpackResources = new File(xpackProject('plugin').projectDir, 'src/test/resources')
-    project.copyRestSpec.from(xpackResources) {
-      include 'rest-api-spec/api/**'
-    }
-  }
-}

+ 7 - 6
x-pack/plugin/graph/qa/with-security/build.gradle

@@ -7,14 +7,15 @@ dependencies {
 }
 
 // bring in graph rest test suite
-task copyGraphRestTests(type: Copy) {
-  into project.sourceSets.test.output.resourcesDir
-  from project(xpackProject('plugin').path).sourceSets.test.resources.srcDirs
-  include 'rest-api-spec/test/graph/**'
+restResources {
+  restApi {
+    includeXpack 'graph'
+  }
+  restTests {
+    includeXpack 'graph'
+  }
 }
 
-integTest.dependsOn copyGraphRestTests
-
 testClusters.integTest {
   testDistribution = 'DEFAULT'
   setting 'xpack.security.enabled', 'true'

+ 0 - 11
x-pack/plugin/ilm/qa/build.gradle

@@ -1,11 +0,0 @@
-import org.elasticsearch.gradle.test.RestIntegTestTask
-
-subprojects {
-  project.tasks.withType(RestIntegTestTask) {
-    final File xPackResources = new File(xpackProject('plugin').projectDir, 'src/test/resources')
-    project.copyRestSpec.from(xPackResources) {
-      include 'rest-api-spec/api/**'
-    }
-  }
-}
-

+ 6 - 0
x-pack/plugin/ilm/qa/rest/build.gradle

@@ -8,6 +8,12 @@ dependencies {
   testCompile project(path: xpackModule('ilm'), configuration: 'runtime')
 }
 
+restResources {
+  restApi {
+    includeXpack 'ilm', 'slm'
+  }
+}
+
 def clusterCredentials = [username: System.getProperty('tests.rest.cluster.username', 'test_admin'),
                           password: System.getProperty('tests.rest.cluster.password', 'x-pack-test-password')]
 

+ 0 - 17
x-pack/plugin/ml/qa/build.gradle

@@ -1,17 +0,0 @@
-import org.elasticsearch.gradle.test.RestIntegTestTask
-
-subprojects {
-  // HACK: please fix this
-  // we want to add the rest api specs for xpack to qa tests, but we
-  // need to wait until after the project is evaluated to only apply
-  // to those that rest tests. this used to be done automatically
-  // when xpack was a plugin, but now there is no place with xpack as a module.
-  // instead, we should package these and make them easy to use for rest tests,
-  // but currently, they must be copied into the resources of the test runner.
-  project.tasks.withType(RestIntegTestTask) {
-    File xpackResources = new File(xpackProject('plugin').projectDir, 'src/test/resources')
-    project.copyRestSpec.from(xpackResources) {
-      include 'rest-api-spec/api/**'
-    }
-  }
-}

+ 7 - 7
x-pack/plugin/ml/qa/ml-with-security/build.gradle

@@ -9,15 +9,15 @@ dependencies {
 }
 
 // bring in machine learning rest test suite
-task copyMlRestTests(type: Copy) {
-  into project.sourceSets.test.output.resourcesDir
-  from project(xpackProject('plugin').path).sourceSets.test.resources.srcDirs
-  include 'rest-api-spec/test/ml/**'
+restResources {
+  restApi {
+    includeXpack 'ml', 'cat'
+  }
+  restTests {
+    includeXpack 'ml'
+  }
 }
 
-integTest.runner {
-  dependsOn copyMlRestTests
-}
 integTest.runner {
   systemProperty 'tests.rest.blacklist', [
     // Remove this test because it doesn't call an ML endpoint and we don't want

+ 0 - 11
x-pack/plugin/security/qa/build.gradle

@@ -1,11 +0,0 @@
-import org.elasticsearch.gradle.test.RestIntegTestTask
-
-subprojects {
-  project.tasks.withType(RestIntegTestTask) {
-    final File xPackResources = new File(xpackProject('plugin').projectDir, 'src/test/resources')
-    project.copyRestSpec.from(xPackResources) {
-      include 'rest-api-spec/api/**'
-    }
-  }
-}
-

+ 0 - 18
x-pack/qa/build.gradle

@@ -1,27 +1,9 @@
 // this file must exist so that qa projects are found
 // by the elasticsearch x-plugins include mechanism
 
-import org.elasticsearch.gradle.test.RestIntegTestTask
-
 apply plugin: 'elasticsearch.build'
 test.enabled = false
 
 dependencies {
   compile project(':test:framework')
 }
-
-subprojects {
-  // HACK: please fix this
-  // we want to add the rest api specs for xpack to qa tests, but we
-  // need to wait until after the project is evaluated to only apply
-  // to those that rest tests. this used to be done automatically
-  // when xpack was a plugin, but now there is no place with xpack as a module.
-  // instead, we should package these and make them easy to use for rest tests,
-  // but currently, they must be copied into the resources of the test runner.
-  project.tasks.withType(RestIntegTestTask) {
-    File xpackResources = new File(xpackProject('plugin').projectDir, 'src/test/resources')
-    project.copyRestSpec.from(xpackResources) {
-      include 'rest-api-spec/api/**'
-    }
-  }
-}

+ 6 - 1
x-pack/qa/core-rest-tests-with-security/build.gradle

@@ -6,8 +6,13 @@ dependencies {
   testCompile project(':x-pack:qa')
 }
 
+restResources {
+  restTests {
+    includeCore '*'
+  }
+}
+
 integTest {
-  includePackaged = true
   runner {
     systemProperty 'tests.rest.blacklist',
       [

+ 0 - 20
x-pack/qa/full-cluster-restart/build.gradle

@@ -1,8 +1,6 @@
 import org.elasticsearch.gradle.Version
-import org.elasticsearch.gradle.info.BuildParams
 import org.elasticsearch.gradle.testclusters.RestTestRunnerTask
 
-
 apply plugin: 'elasticsearch.testclusters'
 apply plugin: 'elasticsearch.standalone-test'
 
@@ -39,24 +37,6 @@ tasks.register("copyTestNodeKeyMaterial", Copy) {
   into outputDir
 }
 
-configurations {
-  restSpec
-}
-
-dependencies {
-  restSpec project(':rest-api-spec')
-}
-
-processTestResources {
-  dependsOn configurations.restSpec
-  from({ zipTree(configurations.restSpec.singleFile) }) {
-    include 'rest-api-spec/api/**'
-  }
-  from(project(xpackModule('core')).sourceSets.test.resources) {
-    include 'rest-api-spec/api/**'
-  }
-}
-
 for (Version bwcVersion : bwcVersions.indexCompatible) {
   String baseName = "v${bwcVersion}"
 

+ 6 - 0
x-pack/qa/multi-cluster-search-security/build.gradle

@@ -7,6 +7,12 @@ dependencies {
   testCompile project(':x-pack:qa')
 }
 
+restResources {
+  restApi {
+    includeXpack 'security'
+  }
+}
+
 task 'remote-cluster'(type: RestIntegTestTask) {
   mustRunAfter(precommit)
   runner {

+ 6 - 0
x-pack/qa/multi-cluster-tests-with-security/build.gradle

@@ -8,6 +8,12 @@ dependencies {
   testCompile project(':client:rest-high-level')
 }
 
+restResources {
+  restApi {
+    includeXpack 'security', 'transform'
+  }
+}
+
 task 'remote-cluster'(type: RestIntegTestTask) {
   mustRunAfter(precommit)
   runner {

+ 0 - 20
x-pack/qa/rolling-upgrade-basic/build.gradle

@@ -1,5 +1,4 @@
 import org.elasticsearch.gradle.Version
-import org.elasticsearch.gradle.info.BuildParams
 import org.elasticsearch.gradle.testclusters.RestTestRunnerTask
 
 apply plugin: 'elasticsearch.testclusters'
@@ -14,25 +13,6 @@ tasks.register("bwcTest") {
   group = 'verification'
 }
 
-configurations {
-  restSpec
-}
-
-dependencies {
-  restSpec project(':rest-api-spec')
-}
-
-processTestResources {
-  dependsOn configurations.restSpec
-  from({ zipTree(configurations.restSpec.singleFile) }) {
-    include 'rest-api-spec/api/**'
-  }
-  from(project(xpackProject('plugin').path).sourceSets.test.resources) {
-    include 'rest-api-spec/api/**'
-  }
-}
-
-
 for (Version bwcVersion : bwcVersions.wireCompatible) {
   String baseName = "v${bwcVersion}"
 

+ 0 - 19
x-pack/qa/rolling-upgrade-multi-cluster/build.gradle

@@ -1,5 +1,4 @@
 import org.elasticsearch.gradle.Version
-import org.elasticsearch.gradle.info.BuildParams
 import org.elasticsearch.gradle.testclusters.RestTestRunnerTask
 
 apply plugin: 'elasticsearch.testclusters'
@@ -14,24 +13,6 @@ tasks.register("bwcTest") {
   group = 'verification'
 }
 
-configurations {
-  restSpec
-}
-
-dependencies {
-  restSpec project(':rest-api-spec')
-}
-
-processTestResources {
-  dependsOn configurations.restSpec
-  from({ zipTree(configurations.restSpec.singleFile) }) {
-    include 'rest-api-spec/api/**'
-  }
-  from(project(xpackProject('plugin').path).sourceSets.test.resources) {
-    include 'rest-api-spec/api/**'
-  }
-}
-
 for (Version bwcVersion : bwcVersions.wireCompatible) {
   String baseName = "v${bwcVersion}"
 

+ 7 - 19
x-pack/qa/rolling-upgrade/build.gradle

@@ -1,5 +1,4 @@
 import org.elasticsearch.gradle.Version
-import org.elasticsearch.gradle.info.BuildParams
 import org.elasticsearch.gradle.testclusters.RestTestRunnerTask
 
 apply plugin: 'elasticsearch.testclusters'
@@ -10,6 +9,13 @@ dependencies {
   testCompile project(':client:rest-high-level')
 }
 
+restResources {
+  restApi {
+    includeCore '*'
+    includeXpack '*'
+  }
+}
+
 forbiddenPatterns {
   exclude '**/system_key'
 }
@@ -21,24 +27,6 @@ tasks.register("bwcTest") {
   group = 'verification'
 }
 
-configurations {
-  restSpec
-}
-
-dependencies {
-  restSpec project(':rest-api-spec')
-}
-
-processTestResources {
-  dependsOn configurations.restSpec
-  from({ zipTree(configurations.restSpec.singleFile) }) {
-    include 'rest-api-spec/api/**'
-  }
-  from(project(xpackProject('plugin').path).sourceSets.test.resources) {
-    include 'rest-api-spec/api/**'
-  }
-}
-
 task copyTestNodeKeyMaterial(type: Copy) {
   from project(':x-pack:plugin:core').files('src/test/resources/org/elasticsearch/xpack/security/transport/ssl/certs/simple/testnode.pem',
     'src/test/resources/org/elasticsearch/xpack/security/transport/ssl/certs/simple/testnode.crt')

+ 6 - 0
x-pack/qa/smoke-test-security-with-mustache/build.gradle

@@ -6,6 +6,12 @@ dependencies {
   testCompile project(':x-pack:qa')
 }
 
+restResources {
+  restApi {
+    includeXpack 'security'
+  }
+}
+
 testClusters.integTest {
   testDistribution = 'DEFAULT'
   setting 'xpack.watcher.enabled', 'false'

+ 7 - 6
x-pack/qa/smoke-test-watcher-with-security/build.gradle

@@ -6,14 +6,15 @@ dependencies {
   testCompile project(':x-pack:qa')
 }
 
-// bring in watcher rest test suite
-task copyWatcherRestTests(type: Copy) {
-  into project.sourceSets.test.output.resourcesDir
-  from project(xpackProject('plugin').path).sourceSets.test.resources.srcDirs
-  include 'rest-api-spec/test/watcher/**'
+restResources {
+  restApi {
+    includeXpack 'watcher', 'security', 'xpack'
+  }
+  restTests {
+    includeXpack 'watcher'
+  }
 }
 
-integTest.runner.dependsOn copyWatcherRestTests
 testClusters.integTest {
   testDistribution = 'DEFAULT'
   setting 'xpack.ilm.enabled', 'false'

+ 6 - 0
x-pack/qa/smoke-test-watcher/build.gradle

@@ -6,6 +6,12 @@ dependencies {
   testCompile project(':x-pack:qa')
 }
 
+restResources {
+  restApi {
+    includeXpack 'watcher'
+  }
+}
+
 testClusters.integTest {
   testDistribution = 'DEFAULT'
   setting 'xpack.slm.enabled', 'false'

+ 13 - 10
x-pack/qa/third-party/jira/build.gradle

@@ -12,22 +12,17 @@ dependencies {
   testCompile project(path: xpackModule('watcher'), configuration: 'runtime')
 }
 
+restResources {
+  restApi {
+    includeXpack 'watcher'
+  }
+}
 
 String jiraUrl = System.getenv('jira_url')
 String jiraUser = System.getenv('jira_user')
 String jiraPassword = System.getenv('jira_password')
 String jiraProject = System.getenv('jira_project')
 
-testClusters.integTest {
-  setting 'xpack.security.enabled', 'false'
-  setting 'xpack.monitoring.enabled', 'false'
-  setting 'xpack.ml.enabled', 'false'
-  setting 'xpack.license.self_generated.type', 'trial'
-  setting 'logger.org.elasticsearch.xpack.watcher', 'DEBUG'
-  setting 'xpack.notification.jira.account.test.issue_defaults.issuetype.name', 'Bug'
-  setting 'xpack.notification.jira.account.test.issue_defaults.labels.0', 'integration-tests'
-}
-
 task cleanJira(type: DefaultTask) {
   doLast {
     List<String> issues = jiraIssues(jiraProject)
@@ -46,6 +41,14 @@ if (!jiraUrl && !jiraUser && !jiraPassword && !jiraProject) {
   testingConventions.enabled = false
 } else {
   testClusters.integTest {
+    testDistribution = 'DEFAULT'
+    setting 'xpack.security.enabled', 'false'
+    setting 'xpack.monitoring.enabled', 'false'
+    setting 'xpack.ml.enabled', 'false'
+    setting 'xpack.license.self_generated.type', 'trial'
+    setting 'logger.org.elasticsearch.xpack.watcher', 'DEBUG'
+    setting 'xpack.notification.jira.account.test.issue_defaults.issuetype.name', 'Bug'
+    setting 'xpack.notification.jira.account.test.issue_defaults.labels.0', 'integration-tests'
     setting 'xpack.notification.jira.account.test.issue_defaults.project.key', jiraProject
     keystore 'xpack.notification.jira.account.test.secure_url', jiraUrl
     keystore 'xpack.notification.jira.account.test.secure_user', jiraUser

+ 7 - 0
x-pack/qa/third-party/pagerduty/build.gradle

@@ -9,11 +9,18 @@ dependencies {
 
 String pagerDutyServiceKey = System.getenv('pagerduty_service_api_key')
 
+restResources {
+  restApi {
+    includeXpack 'watcher'
+  }
+}
+
 if (!pagerDutyServiceKey) {
   integTest.enabled = false
   testingConventions.enabled = false
 } else {
   testClusters.integTest {
+    testDistribution = 'DEFAULT'
     setting 'xpack.security.enabled', 'false'
     setting 'xpack.monitoring.enabled', 'false'
     setting 'xpack.ml.enabled', 'false'

+ 7 - 0
x-pack/qa/third-party/slack/build.gradle

@@ -7,6 +7,12 @@ dependencies {
   testCompile project(path: xpackModule('watcher'), configuration: 'runtime')
 }
 
+restResources {
+  restApi {
+    includeXpack 'watcher'
+  }
+}
+
 String slackUrl = System.getenv('slack_url')
 
 if (!slackUrl) {
@@ -14,6 +20,7 @@ if (!slackUrl) {
   testingConventions.enabled = false
 } else {
   testClusters.integTest {
+    testDistribution = 'DEFAULT'
     setting 'xpack.security.enabled', 'false'
     setting 'xpack.monitoring.enabled', 'false'
     setting 'xpack.ml.enabled', 'false'