Skip to content

Commit d395cbb

Browse files
committed
fix: older downloads working
1 parent 401bf6e commit d395cbb

6 files changed

Lines changed: 394 additions & 550 deletions

File tree

buildSrc/build.gradle

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,4 +40,11 @@ dependencies {
4040

4141
tasks.withType(Jar).configureEach {
4242
it.duplicatesStrategy = DuplicatesStrategy.INCLUDE
43+
}
44+
45+
tasks.withType(Test).configureEach {
46+
useJUnitPlatform()
47+
testLogging {
48+
events('passed', 'skipped', 'failed', 'standardOut', 'standardError')
49+
}
4350
}

buildSrc/src/main/groovy/org/grails/documentation/DownloadPage.groovy

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,27 @@ class DownloadPage {
4141
"https://downloads.apache.org/grails/${directory}/${version}/sources/apache-${artifact}-${version}-src.zip${ext}"
4242
}
4343

44+
/**
45+
* Does not handle pre-release versions as these are not displayed in the select box.
46+
*/
47+
static String resolveOldDownloadUrl(String version) {
48+
def baseUrl = 'https://github.com/apache/grails-core/releases/download'
49+
def parts = ((version.split(/\./)*.replaceAll(/\D.*/, '')*.toInteger()) + [0, 0, 0]).take(3)
50+
def (major, minor, patch) = [parts[0], parts[1], parts[2]]
51+
def artifactName = "apache-grails-$version-bin"
52+
def tag = "v$version"
53+
if (major < 7) {
54+
artifactName = "grails-$version"
55+
if (major == 1 && minor == 1) {
56+
artifactName = "grails-bin-$version"
57+
}
58+
if (major <= 1 && patch == 0) {
59+
tag = "v$major.$minor"
60+
}
61+
}
62+
return "$baseUrl/$tag/${artifactName}.zip"
63+
}
64+
4465
@CompileDynamic
4566
static String renderDownload(String version) {
4667
String redisVersion = '5.0.0'
@@ -165,13 +186,13 @@ class DownloadPage {
165186
mkp.yieldUnescaped(renderDownload(latest.versionText))
166187

167188
h3(class:'columnheader', 'Older Versions')
168-
p 'You can download previous versions as far back as Grails 1.2.0.'
189+
p 'You can download previous versions as far back as Grails 0.1.'
169190
p 'NOTE: Versions prior to 7.0.0-M4 are not ASF releases. Links to those releases are provided here as a convenience.'
170-
div(class:'versionselector') {
171-
select(class:'form-control', onchange:"window.location.href=this.value.startsWith('6') ? 'https://github.com/apache/grails-forge/releases/download/v'+this.value+'/grails-cli-'+this.value+'.zip': 'https://github.com/apache/grails-core/releases/download/v'+this.value+'/grails-'+this.value+'.zip'") {
172-
option(label:'Select a version', disabled:'disabled', selected:'selected')
191+
div(class: 'versionselector') {
192+
select(class: 'form-control', onchange: 'window.location.href=this.value') {
193+
option(label: 'Select a version', disabled: 'disabled', selected: 'selected')
173194
SiteMap.stableVersions(releases)*.versionText.each {
174-
option(value: it, it)
195+
option(value: resolveOldDownloadUrl(it), it)
175196
}
176197
}
177198
}

buildSrc/src/main/groovy/org/grails/documentation/SoftwareVersion.groovy

Lines changed: 37 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -13,25 +13,45 @@ class SoftwareVersion implements Comparable<SoftwareVersion> {
1313

1414
String versionText
1515

16+
/**
17+
* Parses common Grails version formats.
18+
* Examples:
19+
* - 1.0 / 1.0.0
20+
* - 1.0-RC1 / 1.0.RC1 /1.0.0-RC1 / 1.0.0.RC1
21+
* - 1.0.M1 / 1.0.0-M1
22+
* - 1.0.0-SNAPSHOT / 1.0.0.BUILD-SNAPSHOT
23+
*/
1624
static SoftwareVersion build(String version) {
17-
String[] parts = version ? version.split("\\.") : null
18-
SoftwareVersion softVersion
19-
if (parts && parts.length >= 3) {
20-
softVersion = new SoftwareVersion()
21-
softVersion.versionText = version
22-
softVersion.major = parts[0].toInteger()
23-
softVersion.minor = parts[1].toInteger()
24-
if (parts.length > 3) {
25-
softVersion.snapshot = new Snapshot(parts[3])
26-
} else if (parts[2].contains('-')) {
27-
String[] subParts = parts[2].split("-")
28-
softVersion.patch = subParts.first() as int
29-
softVersion.snapshot = new Snapshot(subParts[1..-1].join("-"))
30-
} else {
31-
softVersion.patch = parts[2].toInteger()
32-
}
25+
if (!version) {
26+
return null
3327
}
34-
softVersion
28+
29+
def v = version.trim()
30+
def softVersion = new SoftwareVersion(versionText: v)
31+
32+
// Match: major.minor[.patch][separator qualifier]
33+
// qualifier may be after '-' or '.' (e.g. 1.0-RC1 or 1.0.RC1)
34+
// patch is optional (e.g. 1.0.RC1)
35+
def m = (v =~ /^(\d+)\.(\d+)(?:\.(\d+))?(?:[.-](.+))?$/)
36+
if (!m.matches()) {
37+
return null
38+
}
39+
40+
softVersion.major = m.group(1).toInteger()
41+
softVersion.minor = m.group(2).toInteger()
42+
43+
def patchStr = m.group(3)
44+
def qualifier = m.group(4)
45+
46+
// If patch is missing but the third segment is actually a qualifier (1.0.RC1),
47+
// the regex puts it in qualifier and leaves patch null.
48+
softVersion.patch = patchStr ? patchStr.toInteger() : 0
49+
50+
if (qualifier) {
51+
softVersion.snapshot = new Snapshot(qualifier)
52+
}
53+
54+
return softVersion
3555
}
3656

3757
boolean isSnapshot() {
@@ -66,4 +86,3 @@ class SoftwareVersion implements Comparable<SoftwareVersion> {
6686
}
6787
}
6888
}
69-

buildSrc/src/test/groovy/org/grails/documentation/SoftwareVersionSpec.groovy

Lines changed: 47 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -4,93 +4,77 @@ import spock.lang.Specification
44

55
class SoftwareVersionSpec extends Specification {
66

7-
void "test build snapshot SoftwareVersion from String(#versionText)"() {
7+
void 'test build snapshot SoftwareVersion from String(#versionText)'() {
88
99
when:
10-
SoftwareVersion softwareVersion = SoftwareVersion.build(versionText)
10+
def softwareVersion = SoftwareVersion.build(versionText)
1111
1212
then:
13-
noExceptionThrown()
14-
softwareVersion.snapshot
15-
softwareVersion.snapshot.buildSnapshot == isSnapshot
16-
softwareVersion.snapshot.releaseCandidate == isReleaseCandidate
17-
softwareVersion.snapshot.milestone == isMilestone
13+
noExceptionThrown()
14+
softwareVersion.snapshot
15+
softwareVersion.snapshot.buildSnapshot == isSnapshot
16+
softwareVersion.snapshot.releaseCandidate == isReleaseCandidate
17+
softwareVersion.snapshot.milestone == isMilestone
1818
1919
where:
20-
versionText || isSnapshot | isReleaseCandidate | isMilestone
21-
'5.0.0-SNAPSHOT' || true | false | false
22-
'5.0.0-BUILD-SNAPSHOT' || true | false | false
23-
'5.0.0.BUILD-SNAPSHOT' || true | false | false
20+
versionText || isSnapshot | isReleaseCandidate | isMilestone
21+
'1.0-SNAPSHOT' || true | false | false
22+
'1.0.SNAPSHOT' || true | false | false
23+
'1.0-BUILD-SNAPSHOT' || true | false | false
24+
'1.0.BUILD-SNAPSHOT' || true | false | false
25+
'5.0.0-SNAPSHOT' || true | false | false
26+
'5.0.0-BUILD-SNAPSHOT' || true | false | false
27+
'5.0.0.BUILD-SNAPSHOT' || true | false | false
2428
}
2529
26-
void "test build release-candidate SoftwareVersion from String(#versionText)"() {
30+
void 'test build release-candidate SoftwareVersion from String(#versionText)'() {
2731
2832
when:
29-
SoftwareVersion softwareVersion = SoftwareVersion.build(versionText)
33+
def softwareVersion = SoftwareVersion.build(versionText)
3034
3135
then:
32-
noExceptionThrown()
33-
softwareVersion.snapshot
34-
softwareVersion.snapshot.buildSnapshot == isSnapshot
35-
softwareVersion.snapshot.releaseCandidate == isReleaseCandidate
36-
softwareVersion.snapshot.milestone == isMilestone
37-
softwareVersion.snapshot.releaseCandidateVersion == rcVersion
36+
noExceptionThrown()
37+
softwareVersion.snapshot
38+
softwareVersion.snapshot.buildSnapshot == isSnapshot
39+
softwareVersion.snapshot.releaseCandidate == isReleaseCandidate
40+
softwareVersion.snapshot.milestone == isMilestone
41+
softwareVersion.snapshot.releaseCandidateVersion == rcVersion
3842
3943
where:
40-
versionText || isSnapshot | isReleaseCandidate | isMilestone | rcVersion
41-
'5.0.0-RC1' || false | true | false | 1
42-
'5.0.0-RC2' || false | true | false | 2
43-
'5.0.0.RC1' || false | true | false | 1
44+
versionText || isSnapshot | isReleaseCandidate | isMilestone | rcVersion
45+
'1.0-RC1' || false | true | false | 1
46+
'1.0.RC2' || false | true | false | 2
47+
'5.0.0-RC1' || false | true | false | 1
48+
'5.0.0-RC2' || false | true | false | 2
49+
'5.0.0.RC1' || false | true | false | 1
4450
}
4551
46-
void "test build milestone SoftwareVersion from String(#versionText)"() {
4752
48-
when:
49-
SoftwareVersion softwareVersion = SoftwareVersion.build(versionText)
50-
51-
then:
52-
noExceptionThrown()
53-
softwareVersion.snapshot
54-
softwareVersion.snapshot.buildSnapshot == isSnapshot
55-
softwareVersion.snapshot.releaseCandidate == isReleaseCandidate
56-
softwareVersion.snapshot.milestone == isMilestone
57-
softwareVersion.snapshot.milestoneVersion == milestoneVersion
58-
59-
where:
60-
versionText || isSnapshot | isReleaseCandidate | isMilestone | milestoneVersion
61-
'5.0.0-M1' || false | false | true | 1
62-
'5.0.0-M2' || false | false | true | 2
63-
'5.0.0.M2' || false | false | true | 2
64-
}
65-
66-
void "test that SoftwareVersion is null when build from String(#versionText)"() {
53+
void 'test build milestone SoftwareVersion from String(#versionText)'() {
6754
6855
when:
69-
SoftwareVersion softwareVersion = SoftwareVersion.build(versionText)
56+
def softwareVersion = SoftwareVersion.build(versionText)
7057
7158
then:
72-
noExceptionThrown()
73-
softwareVersion == null
59+
noExceptionThrown()
60+
softwareVersion.snapshot
61+
softwareVersion.snapshot.buildSnapshot == isSnapshot
62+
softwareVersion.snapshot.releaseCandidate == isReleaseCandidate
63+
softwareVersion.snapshot.milestone == isMilestone
64+
softwareVersion.snapshot.milestoneVersion == milestoneVersion
7465
7566
where:
76-
versionText << ['', null]
67+
versionText || isSnapshot | isReleaseCandidate | isMilestone | milestoneVersion
68+
'1.0-M1' || false | false | true | 1
69+
'1.0.M2' || false | false | true | 2
70+
'5.0.0-M1' || false | false | true | 1
71+
'5.0.0-M2' || false | false | true | 2
72+
'5.0.0.M2' || false | false | true | 2
7773
}
7874
79-
void "test compare latest major GA is greater than pre-release"() {
80-
when:
81-
SoftwareVersion gaVersion = SoftwareVersion.build('6.0.0')
82-
SoftwareVersion preRelease = SoftwareVersion.build('6.0.0-RC1')
83-
84-
then:
85-
gaVersion > preRelease
86-
}
87-
88-
void "test pre-release is greater than last stable version"() {
89-
when:
90-
SoftwareVersion lastStableRelease = SoftwareVersion.build('5.3.3')
91-
SoftwareVersion preRelease = SoftwareVersion.build('6.0.0-RC1')
92-
93-
then:
94-
preRelease > lastStableRelease
75+
void 'compareTo orders milestone < rc < final'() {
76+
expect:
77+
SoftwareVersion.build('1.0.M1') < SoftwareVersion.build('1.0.RC1')
78+
SoftwareVersion.build('1.0.RC1') < SoftwareVersion.build('1.0')
9579
}
9680
}

0 commit comments

Comments
 (0)