diff --git a/src/main/bash/sdkman-selfupdate.sh b/src/main/bash/sdkman-selfupdate.sh index ccbb9070..dfc52de8 100644 --- a/src/main/bash/sdkman-selfupdate.sh +++ b/src/main/bash/sdkman-selfupdate.sh @@ -35,12 +35,17 @@ function __sdk_selfupdate() { fi sdkman_remote_script_version=$(__sdkman_secure_curl "$sdkman_script_version_api") + sdkman_remote_native_version=$(__sdkman_secure_curl "$sdkman_native_version_api") + sdkman_local_script_version=$(cat "$SDKMAN_DIR/var/version") + sdkman_local_native_version=$(cat "$SDKMAN_DIR/var/version_native") + __sdkman_echo_debug "Script: local version: $sdkman_local_script_version; remote version: $sdkman_remote_script_version" + __sdkman_echo_debug "Native: local version: $sdkman_local_native_version; remote version: $sdkman_remote_native_version" force_selfupdate="$1" export sdkman_debug_mode - if [[ "$sdkman_local_script_version" == "$sdkman_remote_script_version" && "$force_selfupdate" != "force" ]]; then + if [[ "$sdkman_local_script_version" == "$sdkman_remote_script_version" && "$sdkman_local_native_version" == "$sdkman_remote_native_version" && "$force_selfupdate" != "force" ]]; then echo "No update available at this time." elif [[ "$sdkman_beta_channel" == "true" ]]; then __sdkman_secure_curl "${SDKMAN_CANDIDATES_API}/selfupdate/beta/${SDKMAN_PLATFORM}" | bash diff --git a/src/test/groovy/sdkman/env/SdkmanBashEnvBuilder.groovy b/src/test/groovy/sdkman/env/SdkmanBashEnvBuilder.groovy index e9f65b2f..fbbfbe36 100644 --- a/src/test/groovy/sdkman/env/SdkmanBashEnvBuilder.groovy +++ b/src/test/groovy/sdkman/env/SdkmanBashEnvBuilder.groovy @@ -21,10 +21,10 @@ class SdkmanBashEnvBuilder { private List candidates = ['groovy', 'grails', 'java'] private boolean offlineMode = false private String candidatesApi = "http://localhost:8080/2" - private String sdkmanVersion = "5.0.0" private String jdkHome = "/path/to/my/jdk" private String httpProxy - private String versionCache + private String scriptVersion + private String nativeVersion private boolean debugMode = true Map config = [ @@ -84,13 +84,13 @@ class SdkmanBashEnvBuilder { this } - SdkmanBashEnvBuilder withVersionCache(String version) { - this.versionCache = version + SdkmanBashEnvBuilder withScriptVersion(String version) { + this.scriptVersion = version this } - SdkmanBashEnvBuilder withSdkmanVersion(String version) { - this.sdkmanVersion = version + SdkmanBashEnvBuilder withNativeVersion(String version) { + this.nativeVersion = version this } @@ -117,7 +117,8 @@ class SdkmanBashEnvBuilder { initializeCandidates(sdkmanCandidatesDir, candidates) initializeCandidatesCache(sdkmanVarDir, candidates) initializeConfiguration(sdkmanEtcDir, config) - initializeVersionCache(sdkmanVarDir, versionCache) + initializeScriptVersionFile(sdkmanVarDir, scriptVersion) + initializeNativeVersionFile(sdkmanVarDir, nativeVersion) primeInitScript(sdkmanBinDir) primeModuleScripts(sdkmanSrcDir) @@ -128,7 +129,6 @@ class SdkmanBashEnvBuilder { SDKMAN_CANDIDATES_DIR: sdkmanCandidatesDir.absolutePath, SDKMAN_OFFLINE_MODE : "$offlineMode", SDKMAN_CANDIDATES_API: candidatesApi, - SDKMAN_VERSION : sdkmanVersion, sdkman_debug_mode : Boolean.toString(debugMode), JAVA_HOME : jdkHome ] @@ -146,13 +146,18 @@ class SdkmanBashEnvBuilder { directory } - private initializeVersionCache(File folder, String version) { + private initializeScriptVersionFile(File folder, String version) { if (version) { new File(folder, "version") << version } } - + private initializeNativeVersionFile(File folder, String version) { + if (version) { + new File(folder, "version_native") << version + } + } + private initializeCandidates(File folder, List candidates) { candidates.each { candidate -> new File(folder, candidate).mkdirs() diff --git a/src/test/groovy/sdkman/specs/ConfigCommandSpec.groovy b/src/test/groovy/sdkman/specs/ConfigCommandSpec.groovy index 384c0a11..43b9b312 100644 --- a/src/test/groovy/sdkman/specs/ConfigCommandSpec.groovy +++ b/src/test/groovy/sdkman/specs/ConfigCommandSpec.groovy @@ -6,7 +6,7 @@ class ConfigCommandSpec extends SdkmanEnvSpecification { def "it should open the config in the system's default editor"() { given: bash = sdkmanBashEnvBuilder - .withVersionCache("x.y.z") + .withScriptVersion("x.y.z") .withOfflineMode(true) .build() diff --git a/src/test/groovy/sdkman/specs/CurrentCommandSpec.groovy b/src/test/groovy/sdkman/specs/CurrentCommandSpec.groovy index ea5a296a..f59ec9fd 100644 --- a/src/test/groovy/sdkman/specs/CurrentCommandSpec.groovy +++ b/src/test/groovy/sdkman/specs/CurrentCommandSpec.groovy @@ -41,7 +41,7 @@ class CurrentCommandSpec extends SdkmanEnvSpecification { bash = sdkmanBashEnvBuilder .withOfflineMode(false) - .withVersionCache("5.0.0") + .withScriptVersion("5.0.0") .withCandidates(installedCandidates.keySet().toList()) .build() diff --git a/src/test/groovy/sdkman/specs/EnvCommandSpec.groovy b/src/test/groovy/sdkman/specs/EnvCommandSpec.groovy index f52eb992..13c7c6d2 100644 --- a/src/test/groovy/sdkman/specs/EnvCommandSpec.groovy +++ b/src/test/groovy/sdkman/specs/EnvCommandSpec.groovy @@ -19,7 +19,7 @@ class EnvCommandSpec extends SdkmanEnvSpecification { bash = sdkmanBashEnvBuilder .withOfflineMode(true) - .withVersionCache("x.y.z") + .withScriptVersion("x.y.z") .build() bash.start() @@ -61,7 +61,7 @@ class EnvCommandSpec extends SdkmanEnvSpecification { } bash = sdkmanBashEnvBuilder - .withVersionCache("x.y.z") + .withScriptVersion("x.y.z") .withOfflineMode(true) .build() @@ -98,7 +98,7 @@ class EnvCommandSpec extends SdkmanEnvSpecification { } bash = sdkmanBashEnvBuilder - .withVersionCache("x.y.z") + .withScriptVersion("x.y.z") .withOfflineMode(true) .withConfiguration("sdkman_auto_env", sdkmanAutoEnv) .build() @@ -133,7 +133,7 @@ class EnvCommandSpec extends SdkmanEnvSpecification { } bash = sdkmanBashEnvBuilder - .withVersionCache("x.y.z") + .withScriptVersion("x.y.z") .withOfflineMode(true) .withConfiguration("sdkman_auto_env", "true") .build() @@ -164,7 +164,7 @@ class EnvCommandSpec extends SdkmanEnvSpecification { } bash = sdkmanBashEnvBuilder - .withVersionCache("x.y.z") + .withScriptVersion("x.y.z") .withOfflineMode(true) .withConfiguration("sdkman_auto_env", "true") .build() @@ -191,7 +191,7 @@ class EnvCommandSpec extends SdkmanEnvSpecification { } bash = sdkmanBashEnvBuilder - .withVersionCache("x.y.z") + .withScriptVersion("x.y.z") .withOfflineMode(true) .withConfiguration("sdkman_auto_env", "true") .build() @@ -225,7 +225,7 @@ class EnvCommandSpec extends SdkmanEnvSpecification { createSymbolicLink(Paths.get("$candidatesDirectory/groovy/current"), Paths.get("$candidatesDirectory/groovy/2.4.6")) bash = sdkmanBashEnvBuilder - .withVersionCache("x.y.z") + .withScriptVersion("x.y.z") .withOfflineMode(true) .withConfiguration("sdkman_auto_env", "true") .build() @@ -264,7 +264,7 @@ class EnvCommandSpec extends SdkmanEnvSpecification { createSymbolicLink(Paths.get("$candidatesDirectory/ant/current"), Paths.get("$candidatesDirectory/ant/1.10.8")) bash = sdkmanBashEnvBuilder - .withVersionCache("x.y.z") + .withScriptVersion("x.y.z") .withOfflineMode(true) .withConfiguration("sdkman_auto_env", "true") .build() @@ -312,7 +312,7 @@ class EnvCommandSpec extends SdkmanEnvSpecification { } bash = sdkmanBashEnvBuilder - .withVersionCache("x.y.z") + .withScriptVersion("x.y.z") .withOfflineMode(true) .withConfiguration("sdkman_auto_env", "true") .build() @@ -338,7 +338,7 @@ class EnvCommandSpec extends SdkmanEnvSpecification { def "should issue an error if .sdkmanrc contains a malformed candidate version"() { given: bash = sdkmanBashEnvBuilder - .withVersionCache("x.y.z") + .withScriptVersion("x.y.z") .withOfflineMode(true) .build() @@ -389,7 +389,7 @@ class EnvCommandSpec extends SdkmanEnvSpecification { } bash = sdkmanBashEnvBuilder - .withVersionCache("x.y.z") + .withScriptVersion("x.y.z") .withOfflineMode(true) .build() diff --git a/src/test/groovy/sdkman/specs/InitialisationSpec.groovy b/src/test/groovy/sdkman/specs/InitialisationSpec.groovy index f49b0da8..a52649c0 100644 --- a/src/test/groovy/sdkman/specs/InitialisationSpec.groovy +++ b/src/test/groovy/sdkman/specs/InitialisationSpec.groovy @@ -15,7 +15,7 @@ class InitialisationSpec extends SdkmanEnvSpecification { def setup() { bash = sdkmanBashEnvBuilder .withCandidates(allCandidates) - .withVersionCache("x.y.z") + .withScriptVersion("x.y.z") .build() prepareCandidateDirectories(allCandidates) } diff --git a/src/test/groovy/sdkman/specs/SdkCompatibilitySpec.groovy b/src/test/groovy/sdkman/specs/SdkCompatibilitySpec.groovy index cb5ba7bf..aeb5549d 100644 --- a/src/test/groovy/sdkman/specs/SdkCompatibilitySpec.groovy +++ b/src/test/groovy/sdkman/specs/SdkCompatibilitySpec.groovy @@ -12,7 +12,7 @@ class SdkCompatibilitySpec extends SdkmanEnvSpecification { def setup() { bash = sdkmanBashEnvBuilder .withCandidates(allCandidates) - .withVersionCache("x.y.z") + .withScriptVersion("x.y.z") .build() } diff --git a/src/test/groovy/sdkman/steps/env.groovy b/src/test/groovy/sdkman/steps/env.groovy index aff9e647..5d42daf9 100644 --- a/src/test/groovy/sdkman/steps/env.groovy +++ b/src/test/groovy/sdkman/steps/env.groovy @@ -19,8 +19,8 @@ counter = "${(Math.random() * 10000).toInteger()}".padLeft(4, "0") localGroovyCandidate = "/tmp/groovy-core" as File -sdkmanVersion = "5.0.0" -sdkmanVersionOutdated = "4.0.0" +sdkmanScriptVersion = "5.0.0" +sdkmanNativeVersion = "0.0.1" sdkmanBaseEnv = FilesystemUtils.prepareBaseDir().absolutePath sdkmanBaseDir = sdkmanBaseEnv as File diff --git a/src/test/groovy/sdkman/steps/initialisation_steps.groovy b/src/test/groovy/sdkman/steps/initialisation_steps.groovy index 180fce0e..342e49ae 100644 --- a/src/test/groovy/sdkman/steps/initialisation_steps.groovy +++ b/src/test/groovy/sdkman/steps/initialisation_steps.groovy @@ -32,9 +32,12 @@ And(~'^the archive for candidate "([^"]*)" version "([^"]*)" is removed$') { Str assert !archive.exists() } +And(~'^the sdkman (.*) version "(.*)" is available for download$') { format, version -> + primeEndpointWithString("/broker/version/sdkman/${format}/stable", version) +} + And(~'^the internet is reachable$') { -> primeEndpointWithString("/healthcheck", "12345") - primeEndpointWithString("/broker/version/sdkman/script/stable", sdkmanVersion) primeSelfupdate() offlineMode = false @@ -50,7 +53,6 @@ And(~'^the internet is not reachable$') { -> And(~'^offline mode is disabled with reachable internet$') { -> primeEndpointWithString("/healthcheck", "12345") - primeEndpointWithString("/broker/version/sdkman/script/stable", sdkmanVersion) offlineMode = false serviceUrlEnv = SERVICE_UP_URL @@ -59,7 +61,6 @@ And(~'^offline mode is disabled with reachable internet$') { -> And(~'^offline mode is enabled with reachable internet$') { -> primeEndpointWithString("/healthcheck", "12345") - primeEndpointWithString("/broker/version/sdkman/script/stable", sdkmanVersion) offlineMode = true serviceUrlEnv = SERVICE_UP_URL @@ -86,9 +87,9 @@ And(~'^an initialised environment$') { -> .withCandidatesApi(serviceUrlEnv) .withJdkHome(javaHome) .withHttpProxy(HTTP_PROXY) - .withVersionCache(sdkmanVersion) + .withScriptVersion(sdkmanScriptVersion) + .withNativeVersion(sdkmanNativeVersion) .withCandidates(localCandidates) - .withSdkmanVersion(sdkmanVersion) .build() } @@ -98,36 +99,13 @@ And(~'^an initialised environment without debug prints$') { -> .withCandidatesApi(serviceUrlEnv) .withJdkHome(javaHome) .withHttpProxy(HTTP_PROXY) - .withVersionCache(sdkmanVersion) + .withScriptVersion(sdkmanScriptVersion) + .withNativeVersion(sdkmanNativeVersion) .withCandidates(localCandidates) - .withSdkmanVersion(sdkmanVersion) .withDebugMode(false) .build() } -And(~'^an outdated initialised environment$') { -> - bash = SdkmanBashEnvBuilder.create(sdkmanBaseDir) - .withOfflineMode(offlineMode) - .withCandidatesApi(serviceUrlEnv) - .withJdkHome(javaHome) - .withHttpProxy(HTTP_PROXY) - .withVersionCache(sdkmanVersionOutdated) - .withSdkmanVersion(sdkmanVersionOutdated) - .build() - - def twoDaysAgoInMillis = System.currentTimeMillis() - 172800000 - - def upgradeFile = "$sdkmanDir/var/delay_upgrade" as File - upgradeFile.createNewFile() - upgradeFile.setLastModified(twoDaysAgoInMillis) - - def versionFile = "$sdkmanDir/var/version" as File - versionFile.setLastModified(twoDaysAgoInMillis) - - def initFile = "$sdkmanDir/bin/sdkman-init.sh" as File - initFile.text = initFile.text.replace(sdkmanVersion, sdkmanVersionOutdated) -} - And(~'^the system is bootstrapped$') { -> bash.start() bash.execute("source $sdkmanDirEnv/bin/sdkman-init.sh") @@ -137,8 +115,12 @@ And(~'^the system is bootstrapped again$') { -> bash.execute("source $sdkmanDirEnv/bin/sdkman-init.sh") } -And(~/^the sdkman version is "([^"]*)"$/) { String version -> - sdkmanVersion = version +And(~/^the sdkman scripts version is "([^"]*)"$/) { String version -> + sdkmanScriptVersion = version +} + +And(~/^the sdkman native version is "([^"]*)"$/) { String version -> + sdkmanNativeVersion = version } And(~/^the candidates cache is initialised with "(.*)"$/) { String candidate -> diff --git a/src/test/groovy/sdkman/steps/stub_steps.groovy b/src/test/groovy/sdkman/steps/stub_steps.groovy index b56e80c9..c57edbb7 100644 --- a/src/test/groovy/sdkman/steps/stub_steps.groovy +++ b/src/test/groovy/sdkman/steps/stub_steps.groovy @@ -16,7 +16,7 @@ And(~'^the default "([^"]*)" version is "([^"]*)"$') { String candidate, String primeEndpointWithString("/hooks/post/${candidate}/${version}/${UnixUtils.inferPlatform()}", postInstallationHookSuccess()) } -And(~'^an available selfupdate$') { -> +And(~'^an available selfupdate endpoint$') { -> primeEndpointWithString("/selfupdate/stable/${UnixUtils.inferPlatform()}", 'echo "Successfully upgraded SDKMAN."') primeEndpointWithString("/selfupdate/beta/${UnixUtils.inferPlatform()}", 'echo "Successfully upgraded SDKMAN."') } diff --git a/src/test/resources/features/self_update.feature b/src/test/resources/features/self_update.feature index b962fb6e..1d0ef7bc 100644 --- a/src/test/resources/features/self_update.feature +++ b/src/test/resources/features/self_update.feature @@ -1,17 +1,34 @@ -@manual Feature: Self Update Background: Given the internet is reachable + And the sdkman scripts version is "5.0.0" + And the sdkman native version is "0.0.1" And an initialised environment And the system is bootstrapped - And an available selfupdate + And an available selfupdate endpoint + + Scenario: Attempt Self Update with out dated scripts components + Given the sdkman script version "6.0.0" is available for download + And the sdkman native version "0.0.1" is available for download + When I enter "sdk selfupdate" + Then I see "Successfully upgraded SDKMAN." + + Scenario: Attempt Self Update with out dated native components + Given the sdkman script version "5.0.0" is available for download + And the sdkman native version "0.0.2" is available for download + When I enter "sdk selfupdate" + Then I see "Successfully upgraded SDKMAN." Scenario: Attempt Self Update on an up to date system + Given the sdkman script version "5.0.0" is available for download + And the sdkman native version "0.0.1" is available for download When I enter "sdk selfupdate" Then I see "No update available at this time." Scenario: Force Self Update on an up to date system + Given the sdkman script version "5.0.0" is available for download + And the sdkman native version "0.0.1" is available for download When I enter "sdk selfupdate force" Then I see "Successfully upgraded SDKMAN." \ No newline at end of file diff --git a/src/test/resources/features/version.feature b/src/test/resources/features/version.feature index 00e6617f..1b2529ba 100644 --- a/src/test/resources/features/version.feature +++ b/src/test/resources/features/version.feature @@ -2,7 +2,7 @@ Feature: Version Scenario: Show the current version of sdkman Given the internet is reachable - And the sdkman version is "3.2.1" + And the sdkman scripts version is "3.2.1" And an initialised environment And the system is bootstrapped When I enter "sdk version"