-
Notifications
You must be signed in to change notification settings - Fork 26
/
GradleVersionFuncSpec.groovy
152 lines (130 loc) · 7.15 KB
/
GradleVersionFuncSpec.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
package io.codearte.gradle.nexus.functional
import com.google.common.base.Predicate
import com.google.common.base.Predicates
import io.codearte.gradle.nexus.NexusStagingPlugin
import nebula.test.functional.ExecutionResult
import nebula.test.functional.GradleRunner
import org.gradle.internal.jvm.Jvm
import org.gradle.util.GradleVersion
import spock.lang.Issue
import spock.util.Exceptions
import java.util.regex.Pattern
/**
* Verifies that plugin doesn't fail during Gradle initialization (e.g. due to ClassCastException error) with different "supported" Gradle versions.
*/
class GradleVersionFuncSpec extends BaseNexusStagingFunctionalSpec implements FunctionalSpecHelperTrait {
//Officially 5.0, but 4.10.2 works fine with that plugin
private static final GradleVersion MINIMAL_STABLE_JAVA11_COMPATIBLE_GRADLE_VERSION = GradleVersion.version("4.10.2")
private static final GradleVersion MINIMAL_STABLE_JAVA14_COMPATIBLE_GRADLE_VERSION = GradleVersion.version("6.3")
private static final GradleVersion LATEST_GRADLE5_VERSION = GradleVersion.version("5.6.4")
private static final GradleVersion LATEST_GRADLE_VERSION = GradleVersion.version("6.8.3")
def "should not fail on #legacyModeMessage plugin logic initialization issue with Gradle #requestedGradleVersion"() {
given:
gradleVersion = requestedGradleVersion.version
classpathFilter = Predicates.and(GradleRunner.CLASSPATH_DEFAULT, FILTER_SPOCK_JAR)
memorySafeMode = true //shutdown Daemon after a few seconds of inactivity
and:
buildFile << """
${getApplyPluginBlock()}
${getPluginConfigurationWithNotExistingNexusServer()}
${getLegacyModeConfigurationIfRequested(isInLegacyMode as boolean)} //"as" for Idea
//following to cover regression in @ToString on Extension - https://github.com/Codearte/gradle-nexus-staging-plugin/issues/141
println nexusStaging
""".stripIndent()
when:
ExecutionResult result = runTasksWithFailure('getStagingProfile')
then:
result.wasExecuted(':getStagingProfile')
and:
result.failure.cause.message.contains("Execution failed for task ':getStagingProfile'")
Exceptions.getRootCause(result.failure).with {
getClass() == ConnectException
message.contains("Connection refused")
}
where:
[requestedGradleVersion, isInLegacyMode] << [applyJavaCompatibilityAdjustment(resolveRequestedGradleVersions()).unique(), [false, true]].combinations()
legacyModeMessage = isInLegacyMode ? "(legacy)" : ""
}
@Issue("https://github.com/Codearte/gradle-nexus-staging-plugin/issues/141") //Gradle bug https://github.com/gradle/gradle/issues/11466 - fixed in 6.4
def "should not fail on @ToString for extension class in Gradle 6.x"() {
given:
gradleVersion = LATEST_GRADLE_VERSION.version
and:
buildFile << """
import groovy.transform.ToString
@ToString(includeFields = true, includeNames = true, includePackage = false)
class ToStringBugDemonstrationExtension {
final Property<String> bugId
ToStringBugDemonstrationExtension(Project project) {
bugId = project.getObjects().property(String)
}
}
class ToStringBugDemonstrationPlugin implements Plugin<Project> {
void apply(Project project) {
def extension = project.extensions.create("toStringExtension", ToStringBugDemonstrationExtension, project)
project.task("printBugId") {
doLast {
println "Bug ID: \${extension.bugId}"
}
}
}
}
apply plugin: ToStringBugDemonstrationPlugin
println "ToString: " + toStringExtension //in fact not needed in that case
"""
expect:
runTasksSuccessfully("printBugId")
}
private String getPluginConfigurationWithNotExistingNexusServer() {
return """
nexusStaging {
packageGroup = "fake.one"
serverUrl = "http://localhost:61942/"
}
"""
}
private String getLegacyModeConfigurationIfRequested(boolean isInLegacyMode) {
return """
apply plugin: 'com.bmuschko.nexus'
apply plugin: 'io.codearte.nexus-upload-staging'
buildscript {
dependencies {
classpath 'com.bmuschko:gradle-nexus-plugin:2.3.1'
}
}
"""
}
//To prevent failure when Spock for Groovy 2.4 is run with Groovy 2.3 delivered with Gradle <2.8
//Spock is not needed in this artificial project - just the test classpath leaks to Gradle instance started by Nebula
private static final Pattern SPOCK_JAR_PATTERN = Pattern.compile(".*spock-core-1\\..*.jar")
private static final Predicate<URL> FILTER_SPOCK_JAR = { URL url ->
return !url.toExternalForm().matches(SPOCK_JAR_PATTERN)
} as Predicate<URL>
private List<GradleVersion> resolveRequestedGradleVersions() {
return [GradleVersion.version(NexusStagingPlugin.MINIMAL_SUPPORTED_GRADLE_VERSION), MINIMAL_STABLE_JAVA11_COMPATIBLE_GRADLE_VERSION,
MINIMAL_STABLE_JAVA14_COMPATIBLE_GRADLE_VERSION, LATEST_GRADLE5_VERSION, LATEST_GRADLE_VERSION].unique()
}
//Java 9 testing mechanism taken after pitest-gradle-plugin - https://github.com/szpak/gradle-pitest-plugin
//Jvm class from Spock doesn't work with Java 9 stable releases - otherwise @IgnoreIf could be used - TODO: check with Spock 1.2
private List<GradleVersion> applyJavaCompatibilityAdjustment(List<GradleVersion> requestedGradleVersions) {
if (!Jvm.current().javaVersion.isJava9Compatible()) {
//All supported versions should be Java 8 compatible
return requestedGradleVersions
}
if ((Jvm.current().javaVersion.getMajorVersion() as Integer) >= 14) {
return leaveCurrentJavaCompatibleGradleVersionsOnly(requestedGradleVersions, MINIMAL_STABLE_JAVA14_COMPATIBLE_GRADLE_VERSION)
} else {
return leaveCurrentJavaCompatibleGradleVersionsOnly(requestedGradleVersions, MINIMAL_STABLE_JAVA11_COMPATIBLE_GRADLE_VERSION)
}
}
private List<GradleVersion> leaveCurrentJavaCompatibleGradleVersionsOnly(List<GradleVersion> requestedGradleVersions,
GradleVersion minimalSupportedGradleVersion) {
List<GradleVersion> currentJavaCompatibleGradleVersions = requestedGradleVersions.findAll {
it >= minimalSupportedGradleVersion
}
if (currentJavaCompatibleGradleVersions.size() < 1) {
currentJavaCompatibleGradleVersions.add(minimalSupportedGradleVersion)
}
return currentJavaCompatibleGradleVersions
}
}