Skip to content

Commit abd2722

Browse files
authored
Cleanup subproject creation in build tests (#105998)
Sometimes subprojects are created by build tests. There exists a utility function to define the subproject build file. Yet some tests add the project to settings and then configure through the subprojects directive in the root build file. This commit cleans up two such cases to use explicit subproject build files.
1 parent 3dcfbe0 commit abd2722

File tree

2 files changed

+12
-35
lines changed

2 files changed

+12
-35
lines changed

build-tools-internal/src/integTest/groovy/org/elasticsearch/gradle/internal/JdkDownloadPluginFuncTest.groovy

+9-9
Original file line numberDiff line numberDiff line change
@@ -99,17 +99,17 @@ class JdkDownloadPluginFuncTest extends AbstractGradleFuncTest {
9999
given:
100100
def mockRepoUrl = urlPath(jdkVendor, jdkVersion, platform)
101101
def mockedContent = filebytes(jdkVendor, platform)
102-
3.times {
103-
settingsFile << """
104-
include ':sub-$it'
105-
"""
106-
}
107102
buildFile.text = """
108103
plugins {
109104
id 'elasticsearch.jdk-download' apply false
110105
}
111106
112107
subprojects {
108+
109+
}
110+
"""
111+
3.times {
112+
subProject(':sub-' + it) << """
113113
apply plugin: 'elasticsearch.jdk-download'
114114
115115
jdks {
@@ -126,8 +126,8 @@ class JdkDownloadPluginFuncTest extends AbstractGradleFuncTest {
126126
println "JDK HOME: " + jdks.myJdk
127127
}
128128
}
129-
}
130-
"""
129+
"""
130+
}
131131

132132
when:
133133
def result = WiremockFixture.withWireMock(mockRepoUrl, mockedContent) { server ->
@@ -165,7 +165,7 @@ class JdkDownloadPluginFuncTest extends AbstractGradleFuncTest {
165165
architecture = "x64"
166166
}
167167
}
168-
168+
169169
tasks.register("getJdk", PrintJdk) {
170170
dependsOn jdks.myJdk
171171
jdkPath = jdks.myJdk.getPath()
@@ -174,7 +174,7 @@ class JdkDownloadPluginFuncTest extends AbstractGradleFuncTest {
174174
class PrintJdk extends DefaultTask {
175175
@Input
176176
String jdkPath
177-
177+
178178
@TaskAction void print() {
179179
println "JDK HOME: " + jdkPath
180180
}

build-tools/src/integTest/groovy/org/elasticsearch/gradle/DistributionDownloadPluginFuncTest.groovy

+3-26
Original file line numberDiff line numberDiff line change
@@ -70,25 +70,14 @@ class DistributionDownloadPluginFuncTest extends AbstractGradleFuncTest {
7070
def version = VersionProperties.getElasticsearch()
7171
def platform = ElasticsearchDistribution.Platform.LINUX
7272

73-
3.times {
74-
settingsFile << """
75-
include ':sub-$it'
76-
"""
77-
}
7873
buildFile.text = """
79-
import org.elasticsearch.gradle.Architecture
80-
8174
plugins {
8275
id 'elasticsearch.distribution-download'
8376
}
84-
85-
subprojects {
86-
apply plugin: 'elasticsearch.distribution-download'
87-
88-
${setupTestDistro(version, platform)}
89-
${setupDistroTask()}
90-
}
9177
"""
78+
3.times {
79+
subProject(':sub-' + it) << applyPluginAndSetupDistro(version, platform)
80+
}
9281

9382
when:
9483
def runner = gradleRunner('setupDistro', '-i', '-g', gradleUserHome)
@@ -118,14 +107,6 @@ class DistributionDownloadPluginFuncTest extends AbstractGradleFuncTest {
118107
id 'elasticsearch.distribution-download'
119108
}
120109
121-
${setupTestDistro(version, platform)}
122-
${setupDistroTask()}
123-
124-
"""
125-
}
126-
127-
private static String setupTestDistro(String version, ElasticsearchDistribution.Platform platform) {
128-
return """
129110
elasticsearch_distributions {
130111
test_distro {
131112
version = "$version"
@@ -134,11 +115,7 @@ class DistributionDownloadPluginFuncTest extends AbstractGradleFuncTest {
134115
architecture = Architecture.current();
135116
}
136117
}
137-
"""
138-
}
139118
140-
private static String setupDistroTask() {
141-
return """
142119
tasks.register("setupDistro", Sync) {
143120
from(elasticsearch_distributions.test_distro)
144121
into("build/distro")

0 commit comments

Comments
 (0)