Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introduce external build-tools JavaRestTestPlugin #77603

Merged
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions build-tools-internal/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -102,9 +102,9 @@ gradlePlugin {
id = 'elasticsearch.java'
implementationClass = 'org.elasticsearch.gradle.internal.ElasticsearchJavaPlugin'
}
javaRestTest {
id = 'elasticsearch.java-rest-test'
implementationClass = 'org.elasticsearch.gradle.internal.test.rest.JavaRestTestPlugin'
internalJavaRestTest {
id = 'elasticsearch.internal-java-rest-test'
implementationClass = 'org.elasticsearch.gradle.internal.test.rest.InternalJavaRestTestPlugin'
}
jdkDownload {
id = 'elasticsearch.jdk-download'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
/**
* Apply this plugin to run the Java based REST tests.
*/
public class JavaRestTestPlugin implements Plugin<Project> {
public class InternalJavaRestTestPlugin implements Plugin<Project> {

public static final String SOURCE_SET_NAME = "javaRestTest";

Expand Down
4 changes: 4 additions & 0 deletions build-tools/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@ gradlePlugin {
id = 'elasticsearch.esplugin'
implementationClass = 'org.elasticsearch.gradle.plugin.PluginBuildPlugin'
}
javaRestTest {
id = 'elasticsearch.java-rest-test'
implementationClass = 'org.elasticsearch.gradle.test.JavaRestTestPlugin'
}
testclusters {
id = 'elasticsearch.testclusters'
implementationClass = 'org.elasticsearch.gradle.testclusters.TestClustersPlugin'
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0 and the Server Side Public License, v 1; you may not use this file except
* in compliance with, at your election, the Elastic License 2.0 or the Server
* Side Public License, v 1.
*/

package org.elasticsearch.gradle.test

import org.elasticsearch.gradle.VersionProperties
import org.elasticsearch.gradle.fixtures.AbstractGradleFuncTest
import org.gradle.testkit.runner.TaskOutcome

class JavaRestTestPluginFuncTest extends AbstractGradleFuncTest {

def "declares default dependencies"() {
given:
buildFile << """
plugins {
id 'elasticsearch.java-rest-test'
}
"""

when:
def result = gradleRunner("dependencies").build()
def output = normalized(result.output)
then:
output.contains(normalized("""
javaRestTestImplementation - Implementation only dependencies for source set 'java rest test'. (n)
/--- org.elasticsearch.test:framework:${VersionProperties.elasticsearch} (n)"""))
}

def "javaRestTest does nothing when there are no tests"() {
given:
buildFile << """
plugins {
id 'elasticsearch.java-rest-test'
}
repositories {
mavenCentral()
}
dependencies {
javaRestTestImplementation "org.elasticsearch.test:framework:7.14.0"
}
"""

when:
def result = gradleRunner("javaRestTest").build()
then:
result.task(':compileJavaRestTestJava').outcome == TaskOutcome.NO_SOURCE
result.task(':javaRestTest').outcome == TaskOutcome.NO_SOURCE
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0 and the Server Side Public License, v 1; you may not use this file except
* in compliance with, at your election, the Elastic License 2.0 or the Server
* Side Public License, v 1.
*/

package org.elasticsearch.gradle.test;

import org.elasticsearch.gradle.VersionProperties;
import org.elasticsearch.gradle.plugin.PluginBuildPlugin;
import org.elasticsearch.gradle.testclusters.ElasticsearchCluster;
import org.elasticsearch.gradle.testclusters.StandaloneRestIntegTestTask;
import org.elasticsearch.gradle.testclusters.TestClustersPlugin;
import org.gradle.api.NamedDomainObjectContainer;
import org.gradle.api.Plugin;
import org.gradle.api.Project;
import org.gradle.api.plugins.JavaBasePlugin;
import org.gradle.api.tasks.SourceSetContainer;
import org.gradle.api.tasks.TaskProvider;
import org.gradle.api.tasks.bundling.Zip;
import org.gradle.language.base.plugins.LifecycleBasePlugin;

import static org.elasticsearch.gradle.plugin.PluginBuildPlugin.BUNDLE_PLUGIN_TASK_NAME;

public class JavaRestTestPlugin implements Plugin<Project> {

public static final String JAVA_REST_TEST = "javaRestTest";

@Override
public void apply(Project project) {
project.getPluginManager().apply(GradleTestPolicySetupPlugin.class);
project.getPluginManager().apply(TestClustersPlugin.class);
project.getPluginManager().apply(JavaBasePlugin.class);

// Setup source set and dependencies
var sourceSets = project.getExtensions().getByType(SourceSetContainer.class);
var testSourceSet = sourceSets.maybeCreate(JAVA_REST_TEST);
var javaRestTestImplementation = project.getConfigurations().getByName(testSourceSet.getImplementationConfigurationName());

String elasticsearchVersion = VersionProperties.getElasticsearch();
javaRestTestImplementation.defaultDependencies(
deps -> deps.add(project.getDependencies().create("org.elasticsearch.test:framework:" + elasticsearchVersion))
);

// Register test cluster
NamedDomainObjectContainer<ElasticsearchCluster> testClusters = (NamedDomainObjectContainer<ElasticsearchCluster>) project
.getExtensions()
.getByName(TestClustersPlugin.EXTENSION_NAME);
var cluster = testClusters.maybeCreate(JAVA_REST_TEST);

// Register test task
TaskProvider<StandaloneRestIntegTestTask> javaRestTestTask = project.getTasks()
.register(JAVA_REST_TEST, StandaloneRestIntegTestTask.class, task -> {
task.useCluster(cluster);
task.setTestClassesDirs(testSourceSet.getOutput().getClassesDirs());
task.setClasspath(testSourceSet.getRuntimeClasspath());

var nonInputProperties = new SystemPropertyCommandLineArgumentProvider();
nonInputProperties.systemProperty("tests.rest.cluster", () -> String.join(",", cluster.getAllHttpSocketURI()));
nonInputProperties.systemProperty("tests.cluster", () -> String.join(",", cluster.getAllTransportPortURI()));
nonInputProperties.systemProperty("tests.clustername", () -> cluster.getName());
task.getJvmArgumentProviders().add(nonInputProperties);
});

// Register plugin bundle with test cluster
project.getPlugins().withType(PluginBuildPlugin.class, p -> {
TaskProvider<Zip> bundle = project.getTasks().withType(Zip.class).named(BUNDLE_PLUGIN_TASK_NAME);
cluster.plugin(bundle.flatMap(Zip::getArchiveFile));
javaRestTestTask.configure(t -> t.dependsOn(bundle));
});

// Wire up to check task
project.getTasks().named(LifecycleBasePlugin.CHECK_TASK_NAME).configure(check -> check.dependsOn(javaRestTestTask));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,15 @@
import org.gradle.api.artifacts.type.ArtifactTypeDefinition;
import org.gradle.api.attributes.Attribute;
import org.gradle.api.internal.artifacts.ArtifactAttributes;
import org.gradle.api.plugins.BasePlugin;
import org.gradle.api.plugins.JavaBasePlugin;
import org.gradle.api.plugins.JavaPlugin;
import org.gradle.api.tasks.Copy;
import org.gradle.api.tasks.SourceSet;
import org.gradle.api.tasks.SourceSetContainer;
import org.gradle.api.tasks.TaskProvider;
import org.gradle.api.tasks.bundling.Zip;
import org.gradle.language.base.plugins.LifecycleBasePlugin;

import java.io.File;

Expand Down Expand Up @@ -85,6 +88,9 @@ public void apply(Project project) {
cluster.plugin(bundle.flatMap(Zip::getArchiveFile));
yamlRestTestTask.configure(t -> t.dependsOn(bundle));
});

// Wire up to check task
project.getTasks().named(LifecycleBasePlugin.CHECK_TASK_NAME).configure(check -> check.dependsOn(yamlRestTestTask));
}

private static void setupDefaultDependencies(
Expand All @@ -107,7 +113,7 @@ private TaskProvider<StandaloneRestIntegTestTask> setupTestTask(
SourceSet testSourceSet,
ElasticsearchCluster cluster
) {
return project.getTasks().register("yamlRestTest", StandaloneRestIntegTestTask.class, task -> {
return project.getTasks().register(YAML_REST_TEST, StandaloneRestIntegTestTask.class, task -> {
task.useCluster(cluster);
task.setTestClassesDirs(testSourceSet.getOutput().getClassesDirs());
task.setClasspath(testSourceSet.getRuntimeClasspath());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
import org.gradle.api.artifacts.ProjectDependency;
import org.gradle.api.plugins.JavaBasePlugin;
import org.gradle.api.plugins.JavaPlugin;
import org.gradle.api.plugins.JavaPluginConvention;
import org.gradle.api.plugins.JavaPluginExtension;
import org.gradle.api.provider.Provider;
import org.gradle.api.services.BuildService;
Expand Down
2 changes: 1 addition & 1 deletion client/rest-high-level/qa/ssl-enabled/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
import org.elasticsearch.gradle.internal.test.RestIntegTestTask
import org.elasticsearch.gradle.internal.info.BuildParams

apply plugin: 'elasticsearch.java-rest-test'
apply plugin: 'elasticsearch.internal-java-rest-test'
dependencies {
javaRestTestImplementation(testArtifact(project(':client:rest-high-level')))
}
Expand Down
2 changes: 1 addition & 1 deletion modules/kibana/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* in compliance with, at your election, the Elastic License 2.0 or the Server
* Side Public License, v 1.
*/
apply plugin: 'elasticsearch.java-rest-test'
apply plugin: 'elasticsearch.internal-java-rest-test'

esplugin {
description 'Plugin exposing APIs for Kibana system indices'
Expand Down
2 changes: 1 addition & 1 deletion modules/lang-mustache/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
*/
apply plugin: 'elasticsearch.internal-yaml-rest-test'
apply plugin: 'elasticsearch.yaml-rest-compat-test'
apply plugin: 'elasticsearch.java-rest-test'
apply plugin: 'elasticsearch.internal-java-rest-test'
apply plugin: 'elasticsearch.internal-cluster-test'

esplugin {
Expand Down
2 changes: 1 addition & 1 deletion modules/reindex/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import org.elasticsearch.gradle.internal.test.AntFixture
apply plugin: 'elasticsearch.test-with-dependencies'
apply plugin: 'elasticsearch.jdk-download'
apply plugin: 'elasticsearch.internal-yaml-rest-test'
apply plugin: 'elasticsearch.java-rest-test'
apply plugin: 'elasticsearch.internal-java-rest-test'
apply plugin: 'elasticsearch.yaml-rest-compat-test'
apply plugin: 'elasticsearch.internal-cluster-test'

Expand Down
8 changes: 3 additions & 5 deletions modules/transport-netty4/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,13 @@
* Side Public License, v 1.
*/


import org.elasticsearch.gradle.internal.info.BuildParams
import org.elasticsearch.gradle.internal.test.RestIntegTestTask
import org.elasticsearch.gradle.internal.test.rest.JavaRestTestPlugin
import org.elasticsearch.gradle.internal.test.rest.InternalJavaRestTestPlugin
import org.elasticsearch.gradle.internal.test.InternalClusterTestPlugin

apply plugin: 'elasticsearch.internal-yaml-rest-test'
apply plugin: 'elasticsearch.yaml-rest-compat-test'
apply plugin: 'elasticsearch.java-rest-test'
apply plugin: 'elasticsearch.internal-java-rest-test'
apply plugin: 'elasticsearch.internal-cluster-test'

/*
Expand Down Expand Up @@ -65,7 +63,7 @@ TaskProvider<Test> pooledInternalClusterTest = tasks.register("pooledInternalClu

TaskProvider<RestIntegTestTask> pooledJavaRestTest = tasks.register("pooledJavaRestTest", RestIntegTestTask) {
SourceSetContainer sourceSets = project.getExtensions().getByType(SourceSetContainer.class);
SourceSet javaRestTestSourceSet = sourceSets.getByName(JavaRestTestPlugin.SOURCE_SET_NAME)
SourceSet javaRestTestSourceSet = sourceSets.getByName(InternalJavaRestTestPlugin.SOURCE_SET_NAME)
setTestClassesDirs(javaRestTestSourceSet.getOutput().getClassesDirs())
setClasspath(javaRestTestSourceSet.getRuntimeClasspath())

Expand Down
11 changes: 10 additions & 1 deletion plugins/examples/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ subprojects { p ->
enabled = false
}
}

// configure project dependencies for yaml rest test plugin.
// plugin defaults to external available artifacts
p.getPluginManager().withPlugin("elasticsearch.yaml-rest-test", new Action<AppliedPlugin>() {
Expand All @@ -19,6 +19,15 @@ subprojects { p ->
p.dependencies.add("restTestSpecs", p.dependencies.project(path:':rest-api-spec', configuration:'basicRestSpecs'))
}
})

// configure project dependencies for java rest test plugin.
// plugin defaults to external available artifacts
p.getPluginManager().withPlugin("elasticsearch.java-rest-test", new Action<AppliedPlugin>() {
@Override
void execute(AppliedPlugin appliedPlugin) {
p.dependencies.add("javaRestTestImplementation", project(":test:framework"))
}
})
}

configure(project('painless-whitelist')) {
Expand Down
2 changes: 1 addition & 1 deletion qa/system-indices/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
*/

apply plugin: 'elasticsearch.internal-es-plugin'
apply plugin: 'elasticsearch.java-rest-test'
apply plugin: 'elasticsearch.internal-java-rest-test'

esplugin {
name 'system-indices-qa'
Expand Down
2 changes: 1 addition & 1 deletion test/external-modules/die-with-dignity/build.gradle
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import org.elasticsearch.gradle.internal.info.BuildParams
import org.elasticsearch.gradle.util.GradleUtils

apply plugin: 'elasticsearch.java-rest-test'
apply plugin: 'elasticsearch.internal-java-rest-test'
apply plugin: 'elasticsearch.internal-es-plugin'

esplugin {
Expand Down
2 changes: 1 addition & 1 deletion x-pack/plugin/async-search/qa/security/build.gradle
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
apply plugin: 'elasticsearch.java-rest-test'
apply plugin: 'elasticsearch.internal-java-rest-test'

dependencies {
javaRestTestImplementation(testArtifact(project(xpackModule('core'))))
Expand Down
2 changes: 1 addition & 1 deletion x-pack/plugin/data-streams/qa/multi-node/build.gradle
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import org.elasticsearch.gradle.internal.info.BuildParams

apply plugin: 'elasticsearch.java-rest-test'
apply plugin: 'elasticsearch.internal-java-rest-test'

File repoDir = file("$buildDir/testclusters/repo")

Expand Down
2 changes: 1 addition & 1 deletion x-pack/plugin/data-streams/qa/rest/build.gradle
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import org.elasticsearch.gradle.internal.info.BuildParams

apply plugin: 'elasticsearch.java-rest-test'
apply plugin: 'elasticsearch.internal-java-rest-test'
apply plugin: 'elasticsearch.internal-yaml-rest-test'
apply plugin: 'elasticsearch.yaml-rest-compat-test'

Expand Down
2 changes: 1 addition & 1 deletion x-pack/plugin/deprecation/qa/rest/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import org.elasticsearch.gradle.util.GradleUtils
import org.elasticsearch.gradle.internal.info.BuildParams

apply plugin: 'elasticsearch.internal-es-plugin'
apply plugin: 'elasticsearch.java-rest-test'
apply plugin: 'elasticsearch.internal-java-rest-test'

esplugin {
description 'Deprecated query plugin'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
apply plugin: 'elasticsearch.java-rest-test'
apply plugin: 'elasticsearch.internal-java-rest-test'

import org.elasticsearch.gradle.internal.info.BuildParams

Expand Down
2 changes: 1 addition & 1 deletion x-pack/plugin/enrich/qa/rest-with-security/build.gradle
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
apply plugin: 'elasticsearch.java-rest-test'
apply plugin: 'elasticsearch.internal-java-rest-test'

import org.elasticsearch.gradle.internal.info.BuildParams

Expand Down
2 changes: 1 addition & 1 deletion x-pack/plugin/enrich/qa/rest/build.gradle
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
apply plugin: 'elasticsearch.java-rest-test'
apply plugin: 'elasticsearch.internal-java-rest-test'
apply plugin: 'elasticsearch.internal-yaml-rest-test'
apply plugin: 'elasticsearch.yaml-rest-compat-test'

Expand Down
2 changes: 1 addition & 1 deletion x-pack/plugin/eql/qa/correctness/build.gradle
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
apply plugin: 'elasticsearch.java-rest-test'
apply plugin: 'elasticsearch.internal-java-rest-test'
apply plugin: 'elasticsearch.build'
apply plugin: 'elasticsearch.internal-testclusters'
tasks.named("test").configure { enabled = false }
Expand Down
2 changes: 1 addition & 1 deletion x-pack/plugin/eql/qa/rest/build.gradle
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
apply plugin: 'elasticsearch.java-rest-test'
apply plugin: 'elasticsearch.internal-java-rest-test'
apply plugin: 'elasticsearch.internal-yaml-rest-test'
apply plugin: 'elasticsearch.yaml-rest-compat-test'

Expand Down
2 changes: 1 addition & 1 deletion x-pack/plugin/eql/qa/security/build.gradle
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
apply plugin: 'elasticsearch.java-rest-test'
apply plugin: 'elasticsearch.internal-java-rest-test'

import org.elasticsearch.gradle.internal.info.BuildParams

Expand Down
2 changes: 1 addition & 1 deletion x-pack/plugin/fleet/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

apply plugin: 'elasticsearch.internal-es-plugin'
apply plugin: 'elasticsearch.internal-cluster-test'
apply plugin: 'elasticsearch.java-rest-test'
apply plugin: 'elasticsearch.internal-java-rest-test'

esplugin {
name 'x-pack-fleet'
Expand Down
Loading