Skip to content

Commit e289e7c

Browse files
authored
Split internal distribution handling into separate internal plugin (#57869)
* Split internal distribution logic into separate plugin * Remove moved func test from DistributionDownloadPluginIT * Assert internal plugin is only appied on internal build * Extract common abstract test specification for plugin func tests * Provide proper failure if unexpected non jdk bundled bwc version is requested
1 parent 4c69f3d commit e289e7c

File tree

15 files changed

+570
-156
lines changed

15 files changed

+570
-156
lines changed
Lines changed: 204 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,204 @@
1+
/*
2+
* Licensed to Elasticsearch under one or more contributor
3+
* license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright
5+
* ownership. Elasticsearch licenses this file to you under
6+
* the Apache License, Version 2.0 (the "License"); you may
7+
* not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
20+
package org.elasticsearch.gradle
21+
22+
import org.elasticsearch.gradle.fixtures.AbstractGradleFuncTest
23+
import org.gradle.testkit.runner.GradleRunner
24+
import org.gradle.testkit.runner.TaskOutcome
25+
import org.junit.Rule
26+
import org.junit.rules.TemporaryFolder
27+
28+
import java.lang.management.ManagementFactory
29+
30+
class InternalDistributionDownloadPluginFuncTest extends AbstractGradleFuncTest {
31+
32+
def "plugin application fails on non internal build"() {
33+
given:
34+
buildFile.text = """
35+
plugins {
36+
id 'elasticsearch.internal-distribution-download'
37+
}
38+
"""
39+
40+
when:
41+
def result = gradleRunner("createExtractedTestDistro").buildAndFail()
42+
43+
then:
44+
assertOutputContains(result.output, "Plugin 'elasticsearch.internal-distribution-download' is not supported. " +
45+
"Use 'elasticsearch.distribution-download' plugin instead")
46+
}
47+
48+
def "resolves current version from local build"() {
49+
given:
50+
internalBuild()
51+
localDistroSetup()
52+
def distroVersion = VersionProperties.getElasticsearch()
53+
buildFile << """
54+
apply plugin: 'elasticsearch.internal-distribution-download'
55+
56+
elasticsearch_distributions {
57+
test_distro {
58+
version = "$distroVersion"
59+
type = "archive"
60+
platform = "linux"
61+
architecture = Architecture.current();
62+
}
63+
}
64+
tasks.register("createExtractedTestDistro") {
65+
dependsOn elasticsearch_distributions.test_distro.extracted
66+
}
67+
"""
68+
69+
when:
70+
def result = gradleRunner("createExtractedTestDistro").build()
71+
72+
then:
73+
result.task(":distribution:archives:linux-tar:buildTar").outcome == TaskOutcome.SUCCESS
74+
result.task(":extractElasticsearchLinux$distroVersion").outcome == TaskOutcome.SUCCESS
75+
assertExtractedDistroIsCreated(distroVersion, 'current-marker.txt')
76+
}
77+
78+
def "resolves bwc versions from source"() {
79+
given:
80+
internalBuild()
81+
bwcMinorProjectSetup()
82+
def distroVersion = "8.1.0"
83+
buildFile << """
84+
apply plugin: 'elasticsearch.internal-distribution-download'
85+
86+
elasticsearch_distributions {
87+
test_distro {
88+
version = "8.1.0"
89+
type = "archive"
90+
platform = "linux"
91+
architecture = Architecture.current();
92+
}
93+
}
94+
tasks.register("createExtractedTestDistro") {
95+
dependsOn elasticsearch_distributions.test_distro.extracted
96+
}
97+
"""
98+
when:
99+
def result = gradleRunner("createExtractedTestDistro").build()
100+
then:
101+
result.task(":distribution:bwc:minor:buildBwcTask").outcome == TaskOutcome.SUCCESS
102+
result.task(":extractElasticsearchLinux8.1.0").outcome == TaskOutcome.SUCCESS
103+
assertExtractedDistroIsCreated(distroVersion,'bwc-marker.txt')
104+
}
105+
106+
def "fails on resolving bwc versions with no bundled jdk"() {
107+
given:
108+
internalBuild()
109+
bwcMinorProjectSetup()
110+
def distroVersion = "8.1.0"
111+
buildFile << """
112+
apply plugin: 'elasticsearch.internal-distribution-download'
113+
114+
elasticsearch_distributions {
115+
test_distro {
116+
version = "8.1.0"
117+
type = "archive"
118+
platform = "linux"
119+
architecture = Architecture.current();
120+
bundledJdk = false
121+
}
122+
}
123+
tasks.register("createExtractedTestDistro") {
124+
dependsOn elasticsearch_distributions.test_distro.extracted
125+
}
126+
"""
127+
when:
128+
def result = gradleRunner("createExtractedTestDistro").buildAndFail()
129+
then:
130+
assertOutputContains(result.output, "Configuring a snapshot bwc distribution ('test_distro') " +
131+
"without a bundled JDK is not supported.")
132+
}
133+
134+
private File internalBuild() {
135+
buildFile << """plugins {
136+
id 'elasticsearch.global-build-info'
137+
}
138+
import org.elasticsearch.gradle.Architecture
139+
import org.elasticsearch.gradle.info.BuildParams
140+
141+
BuildParams.init { it.setIsInternal(true) }
142+
143+
import org.elasticsearch.gradle.BwcVersions
144+
import org.elasticsearch.gradle.Version
145+
146+
Version currentVersion = Version.fromString("9.0.0")
147+
BwcVersions versions = new BwcVersions(new TreeSet<>(
148+
Arrays.asList(Version.fromString("8.0.0"), Version.fromString("8.0.1"), Version.fromString("8.1.0"), currentVersion)),
149+
currentVersion)
150+
151+
BuildParams.init { it.setBwcVersions(versions) }
152+
"""
153+
}
154+
155+
156+
private void bwcMinorProjectSetup() {
157+
settingsFile << """
158+
include ':distribution:bwc:minor'
159+
"""
160+
def bwcSubProjectFolder = testProjectDir.newFolder("distribution", "bwc", "minor")
161+
new File(bwcSubProjectFolder, 'bwc-marker.txt') << "bwc=minor"
162+
new File(bwcSubProjectFolder, 'build.gradle') << """
163+
apply plugin:'base'
164+
configurations.create("linux-tar")
165+
tasks.register("buildBwcTask", Tar) {
166+
from('bwc-marker.txt')
167+
archiveExtension = "tar.gz"
168+
compression = Compression.GZIP
169+
}
170+
artifacts {
171+
it.add("linux-tar", buildBwcTask)
172+
}
173+
"""
174+
}
175+
176+
private void localDistroSetup() {
177+
settingsFile << """
178+
include ":distribution:archives:linux-tar"
179+
"""
180+
def bwcSubProjectFolder = testProjectDir.newFolder("distribution", "archives", "linux-tar")
181+
new File(bwcSubProjectFolder, 'current-marker.txt') << "current"
182+
new File(bwcSubProjectFolder, 'build.gradle') << """
183+
apply plugin:'distribution'
184+
tasks.register("buildTar", Tar) {
185+
from('current-marker.txt')
186+
archiveExtension = "tar.gz"
187+
compression = Compression.GZIP
188+
}
189+
artifacts {
190+
it.add("default", buildTar)
191+
}
192+
"""
193+
buildFile << """
194+
"""
195+
196+
}
197+
198+
boolean assertExtractedDistroIsCreated(String version, String markerFileName) {
199+
File extractedFolder = new File(testProjectDir.root, "build/elasticsearch-distros/extracted_elasticsearch_${version}_archive_linux_default")
200+
assert extractedFolder.exists()
201+
assert new File(extractedFolder, markerFileName).exists()
202+
true
203+
}
204+
}
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
/*
2+
* Licensed to Elasticsearch under one or more contributor
3+
* license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright
5+
* ownership. Elasticsearch licenses this file to you under
6+
* the Apache License, Version 2.0 (the "License"); you may
7+
* not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
20+
package org.elasticsearch.gradle.fixtures
21+
22+
import org.gradle.testkit.runner.GradleRunner
23+
import org.junit.Rule
24+
import org.junit.rules.TemporaryFolder
25+
import spock.lang.Specification
26+
27+
import java.lang.management.ManagementFactory
28+
29+
abstract class AbstractGradleFuncTest extends Specification{
30+
31+
@Rule
32+
TemporaryFolder testProjectDir = new TemporaryFolder()
33+
34+
File settingsFile
35+
File buildFile
36+
37+
def setup() {
38+
settingsFile = testProjectDir.newFile('settings.gradle')
39+
settingsFile << "rootProject.name = 'hello-world'"
40+
buildFile = testProjectDir.newFile('build.gradle')
41+
}
42+
43+
GradleRunner gradleRunner(String... arguments) {
44+
GradleRunner.create()
45+
.withDebug(ManagementFactory.getRuntimeMXBean().getInputArguments().toString().indexOf("-agentlib:jdwp") > 0)
46+
.withProjectDir(testProjectDir.root)
47+
.withArguments(arguments)
48+
.withPluginClasspath()
49+
.forwardOutput()
50+
}
51+
52+
def assertOutputContains(String givenOutput, String expected) {
53+
assert normalizedString(givenOutput).contains(normalizedString(expected))
54+
true
55+
}
56+
57+
String normalizedString(String input) {
58+
return input.readLines().join("\n")
59+
}
60+
61+
}

buildSrc/src/integTest/java/org/elasticsearch/gradle/DistributionDownloadPluginIT.java

Lines changed: 0 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -41,22 +41,6 @@ public class DistributionDownloadPluginIT extends GradleIntegrationTestCase {
4141

4242
// TODO: check reuse of root task across projects MOVE TO UNIT TEST
4343
// TODO: future: check integ-test-zip to maven, snapshots to snapshot service for external project
44-
45-
public void testCurrent() throws Exception {
46-
String projectName = ":distribution:archives:linux-tar";
47-
assertExtractedDistro(
48-
VersionProperties.getElasticsearch(),
49-
"archive",
50-
"linux",
51-
null,
52-
null,
53-
"tests.local_distro.config",
54-
"default",
55-
"tests.local_distro.project",
56-
projectName
57-
);
58-
}
59-
6044
public void testCurrentExternal() throws Exception {
6145
checkService(
6246
VersionProperties.getElasticsearch(),
@@ -70,22 +54,6 @@ public void testCurrentExternal() throws Exception {
7054
);
7155
}
7256

73-
public void testBwc() throws Exception {
74-
assertExtractedDistro(
75-
"8.1.0",
76-
"archive",
77-
"linux",
78-
null,
79-
null,
80-
"tests.local_distro.config",
81-
"linux-tar",
82-
"tests.local_distro.project",
83-
":distribution:bwc:minor",
84-
"tests.current_version",
85-
"8.0.0"
86-
);
87-
}
88-
8957
public void testBwcExternal() throws Exception {
9058
checkService(
9159
"8.1.0-SNAPSHOT",

0 commit comments

Comments
 (0)