Skip to content

Commit 6d2bcda

Browse files
committed
Consider native version in selfupdate, fix tests and add coverage.
1 parent c7374b7 commit 6d2bcda

File tree

12 files changed

+73
-64
lines changed

12 files changed

+73
-64
lines changed

src/main/bash/sdkman-selfupdate.sh

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,17 @@ function __sdk_selfupdate() {
3535
fi
3636

3737
sdkman_remote_script_version=$(__sdkman_secure_curl "$sdkman_script_version_api")
38+
sdkman_remote_native_version=$(__sdkman_secure_curl "$sdkman_native_version_api")
39+
3840
sdkman_local_script_version=$(cat "$SDKMAN_DIR/var/version")
41+
sdkman_local_native_version=$(cat "$SDKMAN_DIR/var/version_native")
42+
3943
__sdkman_echo_debug "Script: local version: $sdkman_local_script_version; remote version: $sdkman_remote_script_version"
44+
__sdkman_echo_debug "Native: local version: $sdkman_local_native_version; remote version: $sdkman_remote_native_version"
4045

4146
force_selfupdate="$1"
4247
export sdkman_debug_mode
43-
if [[ "$sdkman_local_script_version" == "$sdkman_remote_script_version" && "$force_selfupdate" != "force" ]]; then
48+
if [[ "$sdkman_local_script_version" == "$sdkman_remote_script_version" && "$sdkman_local_native_version" == "$sdkman_remote_native_version" && "$force_selfupdate" != "force" ]]; then
4449
echo "No update available at this time."
4550
elif [[ "$sdkman_beta_channel" == "true" ]]; then
4651
__sdkman_secure_curl "${SDKMAN_CANDIDATES_API}/selfupdate/beta/${SDKMAN_PLATFORM}" | bash

src/test/groovy/sdkman/env/SdkmanBashEnvBuilder.groovy

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,10 @@ class SdkmanBashEnvBuilder {
2121
private List candidates = ['groovy', 'grails', 'java']
2222
private boolean offlineMode = false
2323
private String candidatesApi = "http://localhost:8080/2"
24-
private String sdkmanVersion = "5.0.0"
2524
private String jdkHome = "/path/to/my/jdk"
2625
private String httpProxy
27-
private String versionCache
26+
private String scriptVersion
27+
private String nativeVersion
2828
private boolean debugMode = true
2929

3030
Map config = [
@@ -84,13 +84,13 @@ class SdkmanBashEnvBuilder {
8484
this
8585
}
8686

87-
SdkmanBashEnvBuilder withVersionCache(String version) {
88-
this.versionCache = version
87+
SdkmanBashEnvBuilder withScriptVersion(String version) {
88+
this.scriptVersion = version
8989
this
9090
}
9191

92-
SdkmanBashEnvBuilder withSdkmanVersion(String version) {
93-
this.sdkmanVersion = version
92+
SdkmanBashEnvBuilder withNativeVersion(String version) {
93+
this.nativeVersion = version
9494
this
9595
}
9696

@@ -117,7 +117,8 @@ class SdkmanBashEnvBuilder {
117117
initializeCandidates(sdkmanCandidatesDir, candidates)
118118
initializeCandidatesCache(sdkmanVarDir, candidates)
119119
initializeConfiguration(sdkmanEtcDir, config)
120-
initializeVersionCache(sdkmanVarDir, versionCache)
120+
initializeScriptVersionFile(sdkmanVarDir, scriptVersion)
121+
initializeNativeVersionFile(sdkmanVarDir, nativeVersion)
121122

122123
primeInitScript(sdkmanBinDir)
123124
primeModuleScripts(sdkmanSrcDir)
@@ -128,7 +129,6 @@ class SdkmanBashEnvBuilder {
128129
SDKMAN_CANDIDATES_DIR: sdkmanCandidatesDir.absolutePath,
129130
SDKMAN_OFFLINE_MODE : "$offlineMode",
130131
SDKMAN_CANDIDATES_API: candidatesApi,
131-
SDKMAN_VERSION : sdkmanVersion,
132132
sdkman_debug_mode : Boolean.toString(debugMode),
133133
JAVA_HOME : jdkHome
134134
]
@@ -146,13 +146,18 @@ class SdkmanBashEnvBuilder {
146146
directory
147147
}
148148

149-
private initializeVersionCache(File folder, String version) {
149+
private initializeScriptVersionFile(File folder, String version) {
150150
if (version) {
151151
new File(folder, "version") << version
152152
}
153153
}
154154

155-
155+
private initializeNativeVersionFile(File folder, String version) {
156+
if (version) {
157+
new File(folder, "version_native") << version
158+
}
159+
}
160+
156161
private initializeCandidates(File folder, List candidates) {
157162
candidates.each { candidate ->
158163
new File(folder, candidate).mkdirs()

src/test/groovy/sdkman/specs/ConfigCommandSpec.groovy

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ class ConfigCommandSpec extends SdkmanEnvSpecification {
66
def "it should open the config in the system's default editor"() {
77
given:
88
bash = sdkmanBashEnvBuilder
9-
.withVersionCache("x.y.z")
9+
.withScriptVersion("x.y.z")
1010
.withOfflineMode(true)
1111
.build()
1212

src/test/groovy/sdkman/specs/CurrentCommandSpec.groovy

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ class CurrentCommandSpec extends SdkmanEnvSpecification {
4141

4242
bash = sdkmanBashEnvBuilder
4343
.withOfflineMode(false)
44-
.withVersionCache("5.0.0")
44+
.withScriptVersion("5.0.0")
4545
.withCandidates(installedCandidates.keySet().toList())
4646
.build()
4747

src/test/groovy/sdkman/specs/EnvCommandSpec.groovy

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ class EnvCommandSpec extends SdkmanEnvSpecification {
1919

2020
bash = sdkmanBashEnvBuilder
2121
.withOfflineMode(true)
22-
.withVersionCache("x.y.z")
22+
.withScriptVersion("x.y.z")
2323
.build()
2424

2525
bash.start()
@@ -61,7 +61,7 @@ class EnvCommandSpec extends SdkmanEnvSpecification {
6161
}
6262

6363
bash = sdkmanBashEnvBuilder
64-
.withVersionCache("x.y.z")
64+
.withScriptVersion("x.y.z")
6565
.withOfflineMode(true)
6666
.build()
6767

@@ -98,7 +98,7 @@ class EnvCommandSpec extends SdkmanEnvSpecification {
9898
}
9999

100100
bash = sdkmanBashEnvBuilder
101-
.withVersionCache("x.y.z")
101+
.withScriptVersion("x.y.z")
102102
.withOfflineMode(true)
103103
.withConfiguration("sdkman_auto_env", sdkmanAutoEnv)
104104
.build()
@@ -133,7 +133,7 @@ class EnvCommandSpec extends SdkmanEnvSpecification {
133133
}
134134

135135
bash = sdkmanBashEnvBuilder
136-
.withVersionCache("x.y.z")
136+
.withScriptVersion("x.y.z")
137137
.withOfflineMode(true)
138138
.withConfiguration("sdkman_auto_env", "true")
139139
.build()
@@ -164,7 +164,7 @@ class EnvCommandSpec extends SdkmanEnvSpecification {
164164
}
165165

166166
bash = sdkmanBashEnvBuilder
167-
.withVersionCache("x.y.z")
167+
.withScriptVersion("x.y.z")
168168
.withOfflineMode(true)
169169
.withConfiguration("sdkman_auto_env", "true")
170170
.build()
@@ -191,7 +191,7 @@ class EnvCommandSpec extends SdkmanEnvSpecification {
191191
}
192192

193193
bash = sdkmanBashEnvBuilder
194-
.withVersionCache("x.y.z")
194+
.withScriptVersion("x.y.z")
195195
.withOfflineMode(true)
196196
.withConfiguration("sdkman_auto_env", "true")
197197
.build()
@@ -225,7 +225,7 @@ class EnvCommandSpec extends SdkmanEnvSpecification {
225225
createSymbolicLink(Paths.get("$candidatesDirectory/groovy/current"), Paths.get("$candidatesDirectory/groovy/2.4.6"))
226226

227227
bash = sdkmanBashEnvBuilder
228-
.withVersionCache("x.y.z")
228+
.withScriptVersion("x.y.z")
229229
.withOfflineMode(true)
230230
.withConfiguration("sdkman_auto_env", "true")
231231
.build()
@@ -264,7 +264,7 @@ class EnvCommandSpec extends SdkmanEnvSpecification {
264264
createSymbolicLink(Paths.get("$candidatesDirectory/ant/current"), Paths.get("$candidatesDirectory/ant/1.10.8"))
265265

266266
bash = sdkmanBashEnvBuilder
267-
.withVersionCache("x.y.z")
267+
.withScriptVersion("x.y.z")
268268
.withOfflineMode(true)
269269
.withConfiguration("sdkman_auto_env", "true")
270270
.build()
@@ -312,7 +312,7 @@ class EnvCommandSpec extends SdkmanEnvSpecification {
312312
}
313313

314314
bash = sdkmanBashEnvBuilder
315-
.withVersionCache("x.y.z")
315+
.withScriptVersion("x.y.z")
316316
.withOfflineMode(true)
317317
.withConfiguration("sdkman_auto_env", "true")
318318
.build()
@@ -338,7 +338,7 @@ class EnvCommandSpec extends SdkmanEnvSpecification {
338338
def "should issue an error if .sdkmanrc contains a malformed candidate version"() {
339339
given:
340340
bash = sdkmanBashEnvBuilder
341-
.withVersionCache("x.y.z")
341+
.withScriptVersion("x.y.z")
342342
.withOfflineMode(true)
343343
.build()
344344

@@ -389,7 +389,7 @@ class EnvCommandSpec extends SdkmanEnvSpecification {
389389
}
390390

391391
bash = sdkmanBashEnvBuilder
392-
.withVersionCache("x.y.z")
392+
.withScriptVersion("x.y.z")
393393
.withOfflineMode(true)
394394
.build()
395395

src/test/groovy/sdkman/specs/InitialisationSpec.groovy

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ class InitialisationSpec extends SdkmanEnvSpecification {
1515
def setup() {
1616
bash = sdkmanBashEnvBuilder
1717
.withCandidates(allCandidates)
18-
.withVersionCache("x.y.z")
18+
.withScriptVersion("x.y.z")
1919
.build()
2020
prepareCandidateDirectories(allCandidates)
2121
}

src/test/groovy/sdkman/specs/SdkCompatibilitySpec.groovy

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ class SdkCompatibilitySpec extends SdkmanEnvSpecification {
1212
def setup() {
1313
bash = sdkmanBashEnvBuilder
1414
.withCandidates(allCandidates)
15-
.withVersionCache("x.y.z")
15+
.withScriptVersion("x.y.z")
1616
.build()
1717
}
1818

src/test/groovy/sdkman/steps/env.groovy

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ counter = "${(Math.random() * 10000).toInteger()}".padLeft(4, "0")
1919

2020
localGroovyCandidate = "/tmp/groovy-core" as File
2121

22-
sdkmanVersion = "5.0.0"
23-
sdkmanVersionOutdated = "4.0.0"
22+
sdkmanScriptVersion = "5.0.0"
23+
sdkmanNativeVersion = "0.0.1"
2424

2525
sdkmanBaseEnv = FilesystemUtils.prepareBaseDir().absolutePath
2626
sdkmanBaseDir = sdkmanBaseEnv as File

src/test/groovy/sdkman/steps/initialisation_steps.groovy

Lines changed: 14 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,12 @@ And(~'^the archive for candidate "([^"]*)" version "([^"]*)" is removed$') { Str
3232
assert !archive.exists()
3333
}
3434

35+
And(~'^the sdkman (.*) version "(.*)" is available for download$') { format, version ->
36+
primeEndpointWithString("/broker/version/sdkman/${format}/stable", version)
37+
}
38+
3539
And(~'^the internet is reachable$') { ->
3640
primeEndpointWithString("/healthcheck", "12345")
37-
primeEndpointWithString("/broker/version/sdkman/script/stable", sdkmanVersion)
3841
primeSelfupdate()
3942

4043
offlineMode = false
@@ -50,7 +53,6 @@ And(~'^the internet is not reachable$') { ->
5053

5154
And(~'^offline mode is disabled with reachable internet$') { ->
5255
primeEndpointWithString("/healthcheck", "12345")
53-
primeEndpointWithString("/broker/version/sdkman/script/stable", sdkmanVersion)
5456

5557
offlineMode = false
5658
serviceUrlEnv = SERVICE_UP_URL
@@ -59,7 +61,6 @@ And(~'^offline mode is disabled with reachable internet$') { ->
5961

6062
And(~'^offline mode is enabled with reachable internet$') { ->
6163
primeEndpointWithString("/healthcheck", "12345")
62-
primeEndpointWithString("/broker/version/sdkman/script/stable", sdkmanVersion)
6364

6465
offlineMode = true
6566
serviceUrlEnv = SERVICE_UP_URL
@@ -86,9 +87,9 @@ And(~'^an initialised environment$') { ->
8687
.withCandidatesApi(serviceUrlEnv)
8788
.withJdkHome(javaHome)
8889
.withHttpProxy(HTTP_PROXY)
89-
.withVersionCache(sdkmanVersion)
90+
.withScriptVersion(sdkmanScriptVersion)
91+
.withNativeVersion(sdkmanNativeVersion)
9092
.withCandidates(localCandidates)
91-
.withSdkmanVersion(sdkmanVersion)
9293
.build()
9394
}
9495

@@ -98,36 +99,13 @@ And(~'^an initialised environment without debug prints$') { ->
9899
.withCandidatesApi(serviceUrlEnv)
99100
.withJdkHome(javaHome)
100101
.withHttpProxy(HTTP_PROXY)
101-
.withVersionCache(sdkmanVersion)
102+
.withScriptVersion(sdkmanScriptVersion)
103+
.withNativeVersion(sdkmanNativeVersion)
102104
.withCandidates(localCandidates)
103-
.withSdkmanVersion(sdkmanVersion)
104105
.withDebugMode(false)
105106
.build()
106107
}
107108

108-
And(~'^an outdated initialised environment$') { ->
109-
bash = SdkmanBashEnvBuilder.create(sdkmanBaseDir)
110-
.withOfflineMode(offlineMode)
111-
.withCandidatesApi(serviceUrlEnv)
112-
.withJdkHome(javaHome)
113-
.withHttpProxy(HTTP_PROXY)
114-
.withVersionCache(sdkmanVersionOutdated)
115-
.withSdkmanVersion(sdkmanVersionOutdated)
116-
.build()
117-
118-
def twoDaysAgoInMillis = System.currentTimeMillis() - 172800000
119-
120-
def upgradeFile = "$sdkmanDir/var/delay_upgrade" as File
121-
upgradeFile.createNewFile()
122-
upgradeFile.setLastModified(twoDaysAgoInMillis)
123-
124-
def versionFile = "$sdkmanDir/var/version" as File
125-
versionFile.setLastModified(twoDaysAgoInMillis)
126-
127-
def initFile = "$sdkmanDir/bin/sdkman-init.sh" as File
128-
initFile.text = initFile.text.replace(sdkmanVersion, sdkmanVersionOutdated)
129-
}
130-
131109
And(~'^the system is bootstrapped$') { ->
132110
bash.start()
133111
bash.execute("source $sdkmanDirEnv/bin/sdkman-init.sh")
@@ -137,8 +115,12 @@ And(~'^the system is bootstrapped again$') { ->
137115
bash.execute("source $sdkmanDirEnv/bin/sdkman-init.sh")
138116
}
139117

140-
And(~/^the sdkman version is "([^"]*)"$/) { String version ->
141-
sdkmanVersion = version
118+
And(~/^the sdkman scripts version is "([^"]*)"$/) { String version ->
119+
sdkmanScriptVersion = version
120+
}
121+
122+
And(~/^the sdkman native version is "([^"]*)"$/) { String version ->
123+
sdkmanNativeVersion = version
142124
}
143125

144126
And(~/^the candidates cache is initialised with "(.*)"$/) { String candidate ->

src/test/groovy/sdkman/steps/stub_steps.groovy

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ And(~'^the default "([^"]*)" version is "([^"]*)"$') { String candidate, String
1616
primeEndpointWithString("/hooks/post/${candidate}/${version}/${UnixUtils.inferPlatform()}", postInstallationHookSuccess())
1717
}
1818

19-
And(~'^an available selfupdate$') { ->
19+
And(~'^an available selfupdate endpoint$') { ->
2020
primeEndpointWithString("/selfupdate/stable/${UnixUtils.inferPlatform()}", 'echo "Successfully upgraded SDKMAN."')
2121
primeEndpointWithString("/selfupdate/beta/${UnixUtils.inferPlatform()}", 'echo "Successfully upgraded SDKMAN."')
2222
}

0 commit comments

Comments
 (0)