forked from elastic/elasticsearch
/
InternalDistributionDownloadPluginFuncTest.groovy
186 lines (166 loc) · 6.69 KB
/
InternalDistributionDownloadPluginFuncTest.groovy
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
/*
* 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.internal
import org.elasticsearch.gradle.Architecture
import org.elasticsearch.gradle.VersionProperties
import org.elasticsearch.gradle.fixtures.AbstractGradleFuncTest
import org.gradle.testkit.runner.TaskOutcome
class InternalDistributionDownloadPluginFuncTest extends AbstractGradleFuncTest {
def "resolves current version from local build"() {
given:
internalBuild()
localDistroSetup()
def distroVersion = VersionProperties.getElasticsearch()
buildFile << """
apply plugin: 'elasticsearch.internal-distribution-download'
elasticsearch_distributions {
test_distro {
version = "$distroVersion"
type = "archive"
platform = "linux"
architecture = Architecture.current();
}
}
tasks.register("setupDistro", Sync) {
from(elasticsearch_distributions.test_distro)
into("build/distro")
}
"""
when:
def result = gradleRunner("setupDistro", '-g', gradleUserHome).build()
then:
result.task(":distribution:archives:${testArchiveProjectName}:buildExpanded").outcome == TaskOutcome.SUCCESS
result.task(":setupDistro").outcome == TaskOutcome.SUCCESS
assertExtractedDistroIsCreated("build/distro", 'current-marker.txt')
}
def "resolves expanded bwc versions from source"() {
given:
internalBuild()
bwcMinorProjectSetup()
buildFile << """
apply plugin: 'elasticsearch.internal-distribution-download'
elasticsearch_distributions {
test_distro {
version = "8.0.0"
type = "archive"
platform = "linux"
architecture = Architecture.current();
}
}
tasks.register("setupDistro", Sync) {
from(elasticsearch_distributions.test_distro)
into("build/distro")
}
"""
when:
def result = gradleRunner("setupDistro").build()
then:
result.task(":distribution:bwc:minor:buildBwcExpandedTask").outcome == TaskOutcome.SUCCESS
result.task(":setupDistro").outcome == TaskOutcome.SUCCESS
assertExtractedDistroIsCreated("distribution/bwc/minor/build/install/elastic-distro",
'bwc-marker.txt')
}
def "fails on resolving bwc versions with no bundled jdk"() {
given:
internalBuild()
bwcMinorProjectSetup()
buildFile << """
apply plugin: 'elasticsearch.internal-distribution-download'
elasticsearch_distributions {
test_distro {
version = "8.0.0"
type = "archive"
platform = "linux"
architecture = Architecture.current();
bundledJdk = false
}
}
tasks.register("createExtractedTestDistro") {
dependsOn elasticsearch_distributions.test_distro
}
"""
when:
def result = gradleRunner("createExtractedTestDistro").buildAndFail()
then:
assertOutputContains(result.output, "Configuring a snapshot bwc distribution ('test_distro') " +
"without a bundled JDK is not supported.")
}
private void bwcMinorProjectSetup() {
settingsFile << """
include ':distribution:bwc:minor'
"""
def bwcSubProjectFolder = testProjectDir.newFolder("distribution", "bwc", "minor")
new File(bwcSubProjectFolder, 'bwc-marker.txt') << "bwc=minor"
new File(bwcSubProjectFolder, 'build.gradle') << """
apply plugin:'base'
// packed distro
configurations.create("${testArchiveProjectName}")
tasks.register("buildBwcTask", Tar) {
from('bwc-marker.txt')
archiveExtension = "tar.gz"
compression = Compression.GZIP
}
artifacts {
it.add("${testArchiveProjectName}", buildBwcTask)
}
// expanded distro
configurations.create("expanded-${testArchiveProjectName}")
def expandedTask = tasks.register("buildBwcExpandedTask", Copy) {
from('bwc-marker.txt')
into('build/install/elastic-distro')
}
artifacts {
it.add("expanded-${testArchiveProjectName}", file('build/install')) {
builtBy expandedTask
type = 'directory'
}
}
"""
}
private void localDistroSetup() {
settingsFile << """
include ":distribution:archives:${testArchiveProjectName}"
"""
def bwcSubProjectFolder = testProjectDir.newFolder("distribution", "archives", testArchiveProjectName)
new File(bwcSubProjectFolder, 'current-marker.txt') << "current"
new File(bwcSubProjectFolder, 'build.gradle') << """
import org.gradle.api.internal.artifacts.ArtifactAttributes;
apply plugin:'distribution'
def buildTar = tasks.register("buildTar", Tar) {
from('current-marker.txt')
archiveExtension = "tar.gz"
compression = Compression.GZIP
}
def buildExpanded = tasks.register("buildExpanded", Copy) {
from('current-marker.txt')
into("build/local")
}
configurations {
extracted {
attributes {
attribute(ArtifactAttributes.ARTIFACT_FORMAT, "directory")
}
}
}
artifacts {
it.add("default", buildTar)
it.add("extracted", buildExpanded)
}
"""
}
String getTestArchiveProjectName() {
def archSuffix = Architecture.current() == Architecture.AARCH64 ? '-aarch64' : ''
return "linux${archSuffix}-tar"
}
boolean assertExtractedDistroIsCreated(String relativeDistroPath, String markerFileName) {
File extractedFolder = new File(testProjectDir.root, relativeDistroPath)
assert extractedFolder.exists()
assert new File(extractedFolder, markerFileName).exists()
true
}
}