-
Notifications
You must be signed in to change notification settings - Fork 4.6k
/
UpdateDaemonJvmIntegrationTest.groovy
206 lines (164 loc) · 8.32 KB
/
UpdateDaemonJvmIntegrationTest.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
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
/*
* Copyright 2024 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.gradle.interal.buildconfiguration.tasks
import groovy.test.NotYetImplemented
import org.gradle.api.JavaVersion
import org.gradle.buildconfiguration.tasks.UpdateDaemonJvm
import org.gradle.integtests.fixtures.AbstractIntegrationSpec
import org.gradle.integtests.fixtures.AvailableJavaHomes
import org.gradle.integtests.fixtures.jvm.JavaToolchainFixture
import org.gradle.internal.buildconfiguration.DaemonJvmPropertiesDefaults
import org.gradle.internal.buildconfiguration.fixture.DaemonJvmPropertiesFixture
import org.gradle.internal.jvm.Jvm
import org.gradle.test.precondition.Requires
import org.gradle.test.preconditions.IntegTestPreconditions
class UpdateDaemonJvmIntegrationTest extends AbstractIntegrationSpec implements DaemonJvmPropertiesFixture, JavaToolchainFixture {
def "root project has an updateDaemonJvm task only"() {
buildFile << """
def updateDaemonJvm = tasks.named("updateDaemonJvm").get()
assert updateDaemonJvm instanceof ${UpdateDaemonJvm.class.name}
assert updateDaemonJvm.description == "Generates or updates the Gradle Daemon JVM criteria."
"""
settingsFile << """
rootProject.name = 'root'
include("sub")
"""
file("sub").mkdir()
expect:
succeeds("help", "--task", "updateDaemonJvm")
fails(":sub:updateDaemonJvm") // should not exist
}
def "When execute updateDaemonJvm without options Then build properties are populated with default values"() {
when:
run "updateDaemonJvm"
then:
assertJvmCriteria(Jvm.current().javaVersion)
outputContains("Daemon JVM criteria is an incubating feature.")
}
def "When execute updateDaemonJvm for valid version Then build properties are populated with expected values"() {
when:
run "updateDaemonJvm", "--jvm-version=${version.majorVersion}"
then:
assertJvmCriteria(version)
where:
version << [JavaVersion.VERSION_11, JavaVersion.VERSION_15, JavaVersion.VERSION_HIGHER]
}
def "When execute updateDaemonJvm for valid Java 8 versions Then build properties are populated with expected values"() {
when:
run "updateDaemonJvm", "--jvm-version=${version}"
then:
assertJvmCriteria(JavaVersion.VERSION_1_8)
where:
version << ["1.8", "8"]
}
def "When execute updateDaemonJvm with invalid argument --jvm-version option Then fails with expected exception message"() {
when:
fails "updateDaemonJvm", "--jvm-version=$invalidVersion"
then:
failureDescriptionContains("Problem configuring option 'jvm-version' on task ':updateDaemonJvm' from command line.")
failureHasCause("Could not determine Java version from '${invalidVersion}'")
where:
invalidVersion << ["0", "-10", 'asdf']
}
def "When execute updateDaemonJvm with unsupported Java version Then fails with expected exception message"() {
when:
fails "updateDaemonJvm", "--jvm-version=7"
then:
failureDescriptionContains("Execution failed for task ':updateDaemonJvm'")
failureHasCause("Unsupported Java version '7' provided for the 'jvm-version' option. Gradle can only run with Java 8 and above.")
}
def "When execute updateDaemonJvm with unsupported future Java version"() {
// Captures current, but maybe not desired behavior
expect:
succeeds( "updateDaemonJvm", "--jvm-version=10000")
}
def "When execute updateDaemonJvm for valid vendor option Then build properties are populated with expected values"() {
when:
run "updateDaemonJvm", "--jvm-vendor=$vendor"
then:
assertJvmCriteria(DaemonJvmPropertiesDefaults.TOOLCHAIN_VERSION, vendor)
where:
vendor << ["ADOPTIUM", "ADOPTOPENJDK", "AMAZON", "APPLE", "AZUL", "BELLSOFT", "GRAAL_VM", "HEWLETT_PACKARD", "IBM", "JETBRAINS", "MICROSOFT", "ORACLE", "SAP", "TENCENT", "UNKNOWN"]
}
@NotYetImplemented
def "When execute updateDaemonJvm for valid implementation option Then build properties are populated with expected values"() {
when:
run "updateDaemonJvm", "--toolchain-implementation=$implementation"
then:
assertJvmCriteria(DaemonJvmPropertiesDefaults.TOOLCHAIN_VERSION, null, implementation)
where:
implementation << ["VENDOR_SPECIFIC", "J9"]
}
def "When execute updateDaemonJvm specifying different options Then build properties are populated with expected values"() {
when:
run "updateDaemonJvm", "--jvm-version=17", "--jvm-vendor=IBM"
then:
assertJvmCriteria(JavaVersion.VERSION_17, "IBM")
}
def "When execute updateDaemonJvm specifying different options in lower case Then build properties are populated with expected values"() {
when:
run "updateDaemonJvm", "--jvm-version=17", "--jvm-vendor=ibm"
then:
assertJvmCriteria(JavaVersion.VERSION_17, "IBM")
}
def "When execute updateDaemonJvm with unexpected --jvm-vendor option Then fails with expected exception message"() {
when:
fails "updateDaemonJvm", "--jvm-vendor=unknown-vendor"
then:
failureDescriptionContains("Value 'unknown-vendor' given for toolchainVendor is an invalid Java vendor. " +
"Possible values are [ADOPTIUM, ADOPTOPENJDK, AMAZON, APPLE, AZUL, BELLSOFT, GRAAL_VM, HEWLETT_PACKARD, IBM, JETBRAINS, MICROSOFT, ORACLE, SAP, TENCENT, UNKNOWN]")
}
@NotYetImplemented
def "When execute updateDaemonJvm with unexpected --toolchain-implementation option Then fails with expected exception message"() {
when:
fails "updateDaemonJvm", "--toolchain-implementation=unknown-implementation"
then:
failureDescriptionContains("Problem configuring option 'toolchain-implementation' on task ':updateDaemonJvm' from command line.")
failureHasCause("Cannot convert string value 'unknown-implementation' to an enum value of type 'org.gradle.jvm.toolchain.JvmImplementation' " +
"(valid case insensitive values: VENDOR_SPECIFIC, J9)")
}
def "Given already existing build properties When execute updateDaemonJvm with different criteria Then criteria get modified"() {
given:
def otherJvm = AvailableJavaHomes.differentVersion
writeJvmCriteria(Jvm.current())
when:
run "updateDaemonJvm", "--jvm-version=${otherJvm.javaVersion.majorVersion}"
then:
assertJvmCriteria(otherJvm.javaVersion)
}
def "Given defined invalid criteria When execute updateDaemonJvm with different criteria Then criteria get modified using java home"() {
def currentJvm = JavaVersion.current()
given:
writeJvmCriteria(currentJvm, "invalidVendor")
captureJavaHome()
expect:
succeeds("updateDaemonJvm", "--jvm-version=20", "--jvm-vendor=AZUL")
assertJvmCriteria(JavaVersion.VERSION_20, "AZUL")
assertDaemonUsedJvm(Jvm.current())
}
@Requires(IntegTestPreconditions.JavaHomeWithDifferentVersionAvailable)
def "Given defined valid criteria matching with local toolchain When execute updateDaemonJvm with different criteria Then criteria get modified using the expected local toolchain"() {
def otherJvm = AvailableJavaHomes.differentVersion
def otherMetadata = AvailableJavaHomes.getJvmInstallationMetadata(otherJvm)
given:
writeJvmCriteria(otherJvm.javaVersion, otherMetadata.vendor.knownVendor.name())
captureJavaHome()
expect:
withInstallations(otherJvm).succeeds("updateDaemonJvm", "--jvm-version=20", "--jvm-vendor=AZUL")
assertJvmCriteria(JavaVersion.VERSION_20, "AZUL")
assertDaemonUsedJvm(otherJvm)
}
}