Skip to content

Commit 1b37d40

Browse files
authored
Port all task definitions to task avoidance api (#66738) (#66927)
This finishes porting all tasks created in gradle build scripts and plugins to use the task avoidance api (see #56610) * Port all task definitions to task avoidance api * Fix last task created during configuration * Fix test setup in :modules:reindex * Declare proper task inputs
1 parent 9c3149c commit 1b37d40

File tree

24 files changed

+253
-227
lines changed

24 files changed

+253
-227
lines changed

libs/secure-sm/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ tasks.named('forbiddenApisMain').configure {
3737
// JAR hell is part of core which we do not want to add as a dependency
3838
tasks.named("jarHell").configure { enabled = false }
3939

40-
testingConventions {
40+
tasks.named("testingConventions").configure {
4141
naming.clear()
4242
naming {
4343
Tests {

modules/reindex/build.gradle

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import org.apache.tools.ant.taskdefs.condition.Os
2121
import org.elasticsearch.gradle.Architecture
2222
import org.elasticsearch.gradle.OS
2323
import org.elasticsearch.gradle.info.BuildParams
24+
import org.elasticsearch.gradle.test.AntFixture
2425

2526
apply plugin: 'elasticsearch.test-with-dependencies'
2627
apply plugin: 'elasticsearch.jdk-download'
@@ -112,12 +113,12 @@ jdks {
112113

113114
if (Os.isFamily(Os.FAMILY_WINDOWS)) {
114115
logger.warn("Disabling reindex-from-old tests because we can't get the pid file on windows")
115-
javaRestTest {
116+
tasks.named("javaRestTest").configure {
116117
systemProperty "tests.fromOld", "false"
117118
}
118119
} else if (rootProject.rootDir.toString().contains(" ")) {
119120
logger.warn("Disabling reindex-from-old tests because Elasticsearch 1.7 won't start with spaces in the path")
120-
javaRestTest {
121+
tasks.named("javaRestTest").configure {
121122
systemProperty "tests.fromOld", "false"
122123
}
123124
} else {
@@ -129,7 +130,7 @@ if (Os.isFamily(Os.FAMILY_WINDOWS)) {
129130
// see: https://github.com/elastic/elasticsearch/issues/51202
130131
versions = ['2', '1']
131132
}
132-
for (String version : versions) {
133+
versions.each { version ->
133134
// TODO Rene: we should be able to replace these unzip tasks with gradle artifact transforms
134135
TaskProvider<Sync> unzip = tasks.register("unzipEs${version}", Sync) {
135136
Configuration oldEsDependency = configurations['es' + version]
@@ -142,7 +143,7 @@ if (Os.isFamily(Os.FAMILY_WINDOWS)) {
142143
into temporaryDir
143144
}
144145

145-
Task fixture = task("oldEs${version}Fixture", type: org.elasticsearch.gradle.test.AntFixture) {
146+
TaskProvider<AntFixture> fixture = tasks.register("oldEs${version}Fixture", AntFixture) {
146147
dependsOn project.configurations.oldesFixture, jdks.legacy
147148
dependsOn unzip
148149
executable = "${BuildParams.runtimeJavaHome}/bin/java"
@@ -159,13 +160,13 @@ if (Os.isFamily(Os.FAMILY_WINDOWS)) {
159160
}
160161
}
161162

162-
javaRestTest {
163+
tasks.named("javaRestTest").configure {
163164
dependsOn fixture
164165
systemProperty "tests.fromOld", "true"
165166
/* Use a closure on the string to delay evaluation until right before we
166167
* run the integration tests so that we can be sure that the file is
167168
* ready. */
168-
nonInputProperties.systemProperty "es${version}.port", "${-> fixture.addressAndPort}"
169+
nonInputProperties.systemProperty "es${version}.port", "${-> fixture.get().addressAndPort}"
169170
}
170171
}
171172
}

plugins/discovery-gce/build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,12 @@ tasks.named("dependencyLicenses").configure {
3434
mapping from: /google-.*/, to: 'google'
3535
}
3636

37-
check {
37+
tasks.named("check").configure {
3838
// also execute the QA tests when testing the plugin
3939
dependsOn 'qa:gce:check'
4040
}
4141

42-
test {
42+
tasks.named("test").configure {
4343
// this is needed for insecure plugins, remove if possible!
4444
systemProperty 'tests.artifact', project.name
4545
}

plugins/repository-azure/azure-storage-blob/build.gradle

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,16 +29,15 @@ List<String> classesToRewrite = ['com/azure/storage/blob/implementation/AppendBl
2929
'com/azure/storage/blob/implementation/PageBlobsImpl$PageBlobsService.class',
3030
'com/azure/storage/blob/implementation/ServicesImpl$ServicesService.class']
3131

32-
tasks.create('extractClientClasses', Copy).configure {
32+
tasks.register('extractClientClasses', Copy).configure {
3333
from({ zipTree(configurations.originalJar.singleFile) }) {
3434
include "com/azure/storage/blob/implementation/**"
3535
}
3636
into project.file('build/original')
3737
}
3838

3939
def modifiedOutput = project.layout.buildDirectory.dir('modified')
40-
def makePublic = tasks.create('makeClientClassesPublic', JavaClassPublicifier)
41-
makePublic.configure {
40+
def makePublic = tasks.register('makeClientClassesPublic', JavaClassPublicifier) {
4241
dependsOn 'extractClientClasses'
4342
classFiles = classesToRewrite
4443
inputDir = project.layout.buildDirectory.dir('original')

plugins/repository-azure/build.gradle

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -371,13 +371,12 @@ tasks.named("processYamlRestTestResources").configure {
371371
MavenFilteringHack.filter(it, expansions)
372372
}
373373

374-
internalClusterTest {
374+
tasks.named("internalClusterTest").configure {
375375
// this is tested explicitly in a separate test task
376376
exclude '**/AzureStorageCleanupThirdPartyTests.class'
377377
}
378378

379-
testClusters {
380-
yamlRestTest {
379+
testClusters.matching { it.name == "yamlRestTest" }.configureEach {
381380
keystore 'azure.client.integration_test.account', azureAccount
382381
if (azureKey != null && azureKey.isEmpty() == false) {
383382
keystore 'azure.client.integration_test.key', azureKey
@@ -390,15 +389,14 @@ testClusters {
390389
String firstPartOfSeed = BuildParams.testSeed.tokenize(':').get(0)
391390
setting 'thread_pool.repository_azure.max', (Math.abs(Long.parseUnsignedLong(firstPartOfSeed, 16) % 10) + 1).toString(), System.getProperty('ignore.tests.seed') == null ? DEFAULT : IGNORE_VALUE
392391
}
393-
}
394392
}
395393

396-
task azureThirdPartyTest(type: Test) {
394+
tasks.register("azureThirdPartyTest", Test) {
397395
SourceSetContainer sourceSets = project.getExtensions().getByType(SourceSetContainer.class);
398396
SourceSet internalTestSourceSet = sourceSets.getByName(InternalClusterTestPlugin.SOURCE_SET_NAME)
399397
setTestClassesDirs(internalTestSourceSet.getOutput().getClassesDirs())
400398
setClasspath(internalTestSourceSet.getRuntimeClasspath())
401-
dependsOn tasks.internalClusterTest
399+
dependsOn "internalClusterTest"
402400
include '**/AzureStorageCleanupThirdPartyTests.class'
403401
systemProperty 'test.azure.account', azureAccount ? azureAccount : ""
404402
systemProperty 'test.azure.key', azureKey ? azureKey : ""

qa/smoke-test-http/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ dependencies {
2727
testImplementation project(path: ':plugins:transport-nio') // for http
2828
}
2929

30-
integTest {
30+
tasks.named("integTest").configure {
3131
/*
3232
* We have to disable setting the number of available processors as tests in the same JVM randomize processors and will step on each
3333
* other if we allow them to set the number of available processors as it's set-once in Netty.

test/fixtures/gcs-fixture/build.gradle

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,10 @@ dependencies {
2626
api project(':server')
2727
}
2828

29-
preProcessFixture {
30-
dependsOn jar, configurations.runtimeClasspath
29+
def jarTask = tasks.named("jar")
30+
tasks.named("preProcessFixture").configure {
31+
dependsOn jarTask, configurations.runtimeClasspath
32+
inputs.files(jarTask, configurations.runtimeClasspath)
3133
doLast {
3234
file("${testFixturesDir}/shared").mkdirs()
3335
project.copy {

x-pack/docs/build.gradle

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,16 @@ apply plugin: 'elasticsearch.rest-resources'
55
* `// CONSOLE` and `// TESTRESPONSE` but have yet to be converted. Try and
66
* only remove entries from this list. When it is empty we'll remove it
77
* entirely and have a party! There will be cake and everything.... */
8-
buildRestTests.expectedUnconvertedCandidates = [
9-
'en/rest-api/watcher/put-watch.asciidoc',
10-
'en/security/authentication/user-cache.asciidoc',
11-
'en/security/authorization/run-as-privilege.asciidoc',
12-
'en/security/ccs-clients-integrations/http.asciidoc',
13-
'en/rest-api/watcher/stats.asciidoc',
14-
'en/watcher/example-watches/watching-time-series-data.asciidoc',
15-
]
8+
tasks.named("buildRestTests").configure {
9+
expectedUnconvertedCandidates = [
10+
'en/rest-api/watcher/put-watch.asciidoc',
11+
'en/security/authentication/user-cache.asciidoc',
12+
'en/security/authorization/run-as-privilege.asciidoc',
13+
'en/security/ccs-clients-integrations/http.asciidoc',
14+
'en/rest-api/watcher/stats.asciidoc',
15+
'en/watcher/example-watches/watching-time-series-data.asciidoc',
16+
]
17+
}
1618

1719
dependencies {
1820
testImplementation project(path: xpackModule('core'), configuration: 'default')

x-pack/plugin/async/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ dependencies {
1313
compileOnly project(path: xpackModule('core'), configuration: 'default')
1414
}
1515

16-
dependencyLicenses {
16+
tasks.named("dependencyLicenses").configure {
1717
ignoreSha 'x-pack-core'
1818
}
1919

x-pack/plugin/ccr/build.gradle

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ tasks.register('internalClusterTestNoSecurityManager', Test) {
1919
include noSecurityManagerITClasses
2020
systemProperty 'tests.security.manager', 'false'
2121
}
22-
check.dependsOn 'internalClusterTestNoSecurityManager'
22+
tasks.named("check").configure { dependsOn 'internalClusterTestNoSecurityManager' }
2323

2424
tasks.named('internalClusterTest').configure {
2525
exclude noSecurityManagerITClasses
@@ -35,8 +35,10 @@ dependencies {
3535
testImplementation project(path: xpackModule('monitoring'), configuration: 'testArtifacts')
3636
}
3737

38-
testingConventions.naming {
39-
IT {
40-
baseClass "org.elasticsearch.xpack.CcrIntegTestCase"
38+
tasks.named("testingConventions").configure {
39+
naming {
40+
IT {
41+
baseClass "org.elasticsearch.xpack.CcrIntegTestCase"
42+
}
4143
}
4244
}

x-pack/plugin/ccr/qa/downgrade-to-basic-license/build.gradle

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,25 @@ dependencies {
1010
testImplementation project(':x-pack:plugin:ccr:qa')
1111
}
1212

13-
task "leader-cluster"(type: RestIntegTestTask) {
13+
14+
testClusters {
15+
"leader-cluster" {
16+
testDistribution = 'DEFAULT'
17+
setting 'xpack.license.self_generated.type', 'trial'
18+
}
19+
20+
"follow-cluster" {
21+
testDistribution = 'DEFAULT'
22+
setting 'xpack.monitoring.collection.enabled', 'true'
23+
setting 'xpack.license.self_generated.type', 'trial'
24+
setting 'cluster.remote.leader_cluster.seeds', { "\"${testClusters."leader-cluster".getAllTransportPortURI().join(",")}\"" }
25+
}
26+
}
27+
28+
tasks.register("leader-cluster", RestIntegTestTask) {
1429
mustRunAfter("precommit")
1530
systemProperty 'tests.target_cluster', 'leader'
1631
}
17-
testClusters."leader-cluster" {
18-
testDistribution = 'DEFAULT'
19-
setting 'xpack.license.self_generated.type', 'trial'
20-
}
2132

2233
File policyFile = file("${buildDir}/tmp/java.policy")
2334
tasks.register("writeJavaPolicy") {
@@ -35,7 +46,7 @@ tasks.register("writeJavaPolicy") {
3546
}
3647
}
3748

38-
task "follow-cluster"(type: RestIntegTestTask) {
49+
tasks.register("follow-cluster", RestIntegTestTask) {
3950
dependsOn 'writeJavaPolicy', "leader-cluster"
4051
useCluster testClusters."leader-cluster"
4152
systemProperty 'java.security.policy', "file://${policyFile}"
@@ -44,14 +55,6 @@ task "follow-cluster"(type: RestIntegTestTask) {
4455
nonInputProperties.systemProperty 'log', "${-> testClusters."follow-cluster".getFirstNode().getServerLog()}"
4556
}
4657

47-
testClusters."follow-cluster" {
48-
testDistribution = 'DEFAULT'
49-
setting 'xpack.monitoring.collection.enabled', 'true'
50-
setting 'xpack.license.self_generated.type', 'trial'
51-
setting 'cluster.remote.leader_cluster.seeds', { "\"${testClusters."leader-cluster".getAllTransportPortURI().join(",")}\"" }
52-
}
53-
54-
5558
tasks.named("check").configure { dependsOn "follow-cluster" }
5659
// no unit tests for multi-cluster-search, only the rest integration test
5760
tasks.named("test").configure { enabled = false }

x-pack/plugin/ccr/qa/multi-cluster/build.gradle

Lines changed: 24 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -9,51 +9,53 @@ dependencies {
99
testImplementation project(':x-pack:plugin:ccr:qa')
1010
}
1111

12-
task "leader-cluster"(type: RestIntegTestTask) {
13-
mustRunAfter("precommit")
14-
systemProperty 'tests.target_cluster', 'leader'
12+
testClusters {
13+
'leader-cluster' {
14+
testDistribution = 'DEFAULT'
15+
setting 'xpack.license.self_generated.type', 'trial'
16+
}
17+
'middle-cluster' {
18+
testDistribution = 'DEFAULT'
19+
setting 'xpack.license.self_generated.type', 'trial'
20+
setting 'cluster.remote.leader_cluster.seeds',
21+
{ "\"${testClusters.named('leader-cluster').get().getAllTransportPortURI().join(",")}\"" }
22+
}
1523
}
1624

17-
testClusters."leader-cluster" {
18-
testDistribution = 'DEFAULT'
19-
setting 'xpack.license.self_generated.type', 'trial'
25+
tasks.register("leader-cluster", RestIntegTestTask) {
26+
mustRunAfter("precommit")
27+
systemProperty 'tests.target_cluster', 'leader'
2028
}
2129

22-
23-
task "middle-cluster"(type: RestIntegTestTask) {
30+
tasks.register("middle-cluster", RestIntegTestTask) {
2431
dependsOn "leader-cluster"
2532
useCluster testClusters."leader-cluster"
2633
systemProperty 'tests.target_cluster', 'middle'
2734
nonInputProperties.systemProperty 'tests.leader_host',
28-
"${-> testClusters."leader-cluster".getAllHttpSocketURI().get(0)}"
29-
}
30-
testClusters."middle-cluster" {
31-
testDistribution = 'DEFAULT'
32-
setting 'xpack.license.self_generated.type', 'trial'
33-
setting 'cluster.remote.leader_cluster.seeds',
34-
{ "\"${testClusters."leader-cluster".getAllTransportPortURI().join(",")}\"" }
35+
"${-> testClusters.named('leader-cluster').get().getAllHttpSocketURI().get(0)}"
3536
}
3637

37-
task 'follow-cluster'(type: RestIntegTestTask) {
38+
39+
tasks.register('follow-cluster', RestIntegTestTask) {
3840
dependsOn "leader-cluster", "middle-cluster"
3941
useCluster testClusters."leader-cluster"
4042
useCluster testClusters."middle-cluster"
4143
systemProperty 'tests.target_cluster', 'follow'
4244
nonInputProperties.systemProperty 'tests.leader_host',
43-
"${-> testClusters."leader-cluster".getAllHttpSocketURI().get(0)}"
45+
"${-> testClusters.named('leader-cluster').get().getAllHttpSocketURI().get(0)}"
4446
nonInputProperties.systemProperty 'tests.middle_host',
45-
"${-> testClusters."middle-cluster".getAllHttpSocketURI().get(0)}"
47+
"${-> testClusters.named('middle-cluster').get().getAllHttpSocketURI().get(0)}"
4648
}
4749

48-
testClusters."follow-cluster" {
50+
testClusters.matching { it.name == "follow-cluster" }.configureEach {
4951
testDistribution = 'DEFAULT'
5052
setting 'xpack.monitoring.collection.enabled', 'true'
5153
setting 'xpack.license.self_generated.type', 'trial'
5254
setting 'cluster.remote.leader_cluster.seeds',
53-
{ "\"${testClusters."leader-cluster".getAllTransportPortURI().join(",")}\"" }
55+
{ "\"${testClusters.named('leader-cluster').get().getAllTransportPortURI().join(",")}\"" }
5456
setting 'cluster.remote.middle_cluster.seeds',
55-
{ "\"${testClusters."middle-cluster".getAllTransportPortURI().join(",")}\"" }
57+
{ "\"${testClusters.named('middle-cluster').get().getAllTransportPortURI().join(",")}\"" }
5658
}
5759

58-
check.dependsOn "follow-cluster"
60+
tasks.named("check").configure { dependsOn "follow-cluster" }
5961
tasks.named("test").configure { enabled = false } // no unit tests for multi-cluster-search, only the rest integration test

x-pack/plugin/ccr/qa/non-compliant-license/build.gradle

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,27 +9,31 @@ dependencies {
99
testImplementation project(':x-pack:plugin:ccr:qa:')
1010
}
1111

12-
task 'leader-cluster'(type: RestIntegTestTask) {
12+
testClusters {
13+
'leader-cluster' {
14+
testDistribution = 'DEFAULT'
15+
}
16+
17+
'follow-cluster' {
18+
testDistribution = 'DEFAULT'
19+
setting 'xpack.license.self_generated.type', 'trial'
20+
setting 'cluster.remote.leader_cluster.seeds',
21+
{ "\"${testClusters.'leader-cluster'.getAllTransportPortURI().join(",")}\"" }
22+
}
23+
}
24+
25+
tasks.register('leader-cluster', RestIntegTestTask) {
1326
mustRunAfter("precommit")
1427
systemProperty 'tests.target_cluster', 'leader'
1528
}
16-
testClusters.'leader-cluster' {
17-
testDistribution = 'DEFAULT'
18-
}
1929

20-
task 'follow-cluster'(type: RestIntegTestTask) {
30+
tasks.register('follow-cluster', RestIntegTestTask) {
2131
dependsOn 'leader-cluster'
2232
useCluster testClusters.'leader-cluster'
2333
systemProperty 'tests.target_cluster', 'follow'
2434
nonInputProperties.systemProperty 'tests.leader_host',
2535
{ "${testClusters.'follow-cluster'.getAllHttpSocketURI().get(0)}" }
2636
}
27-
testClusters.'follow-cluster' {
28-
testDistribution = 'DEFAULT'
29-
setting 'xpack.license.self_generated.type', 'trial'
30-
setting 'cluster.remote.leader_cluster.seeds',
31-
{ "\"${testClusters.'leader-cluster'.getAllTransportPortURI().join(",")}\"" }
32-
}
3337

3438
tasks.named("check").configure { dependsOn "follow-cluster" }
3539
tasks.named("test").configure { enabled = false }

0 commit comments

Comments
 (0)