mirror of
https://github.com/sdkman/sdkman-cli.git
synced 2026-08-02 10:35:52 -04:00
Introduce first pass of multi-platform functionality.
This commit is contained in:
@@ -62,7 +62,11 @@ function __sdkman_determine_version {
|
||||
VERSION=$(__sdkman_secure_curl "${SDKMAN_LEGACY_API}/candidates/${candidate}/default")
|
||||
|
||||
else
|
||||
VERSION_VALID=$(__sdkman_secure_curl "${SDKMAN_LEGACY_API}/candidates/${candidate}/${version}")
|
||||
local validation_url="${SDKMAN_LEGACY_API}/candidates/${candidate}/${version}/$(echo $SDKMAN_PLATFORM | tr '[:upper:]' '[:lower:]')"
|
||||
VERSION_VALID=$(__sdkman_secure_curl "$validation_url")
|
||||
__sdkman_echo_debug "Validate $candidate $version for $SDKMAN_PLATFORM: $VERSION_VALID"
|
||||
__sdkman_echo_debug "Validation URL: $validation_url"
|
||||
|
||||
if [[ "$VERSION_VALID" == 'valid' || "$VERSION_VALID" == 'invalid' && -n "$folder" ]]; then
|
||||
VERSION="$version"
|
||||
|
||||
@@ -74,7 +78,7 @@ function __sdkman_determine_version {
|
||||
|
||||
else
|
||||
echo ""
|
||||
echo "Stop! $version is not a valid ${candidate} version."
|
||||
echo "Stop! $candidate $version is not available on this platform."
|
||||
return 1
|
||||
fi
|
||||
fi
|
||||
|
||||
@@ -106,7 +106,7 @@ function __sdkman_download {
|
||||
echo ""
|
||||
echo "In progress..."
|
||||
echo ""
|
||||
local download_url="${SDKMAN_CURRENT_API}/broker/download/${candidate}/${version}?platform=${SDKMAN_PLATFORM}"
|
||||
local download_url="${SDKMAN_CURRENT_API}/broker/download/${candidate}/${version}/$(echo $SDKMAN_PLATFORM | tr '[:upper:]' '[:lower:]')"
|
||||
|
||||
local download_binary="${SDKMAN_DIR}/tmp/$(cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w 32 | head -n 1).bin"
|
||||
__sdkman_secure_curl_download "$download_url" > "$download_binary"
|
||||
|
||||
@@ -30,4 +30,4 @@ Feature: Default Version
|
||||
Given the candidate "groovy" version "2.9.9" is not available for download
|
||||
And the system is bootstrapped
|
||||
When I enter "sdk default groovy 2.9.9"
|
||||
Then I see "Stop! 2.9.9 is not a valid groovy version."
|
||||
Then I see "Stop! groovy 2.9.9 is not available on this platform."
|
||||
@@ -20,7 +20,7 @@ Feature: Install Candidate
|
||||
Scenario: Install a Candidate version that does not exist
|
||||
Given the candidate "grails" version "1.4.4" is not available for download
|
||||
When I enter "sdk install grails 1.4.4"
|
||||
Then I see "Stop! 1.4.4 is not a valid grails version."
|
||||
Then I see "Stop! grails 1.4.4 is not available on this platform."
|
||||
|
||||
Scenario: Install a Candidate version that is already installed
|
||||
Given the candidate "grails" version "1.3.9" is available for download
|
||||
|
||||
21
src/test/cucumber/multi_platform_binaries.feature
Normal file
21
src/test/cucumber/multi_platform_binaries.feature
Normal file
@@ -0,0 +1,21 @@
|
||||
Feature: Multi Platform Binary Distribution
|
||||
|
||||
Background:
|
||||
Given the internet is reachable
|
||||
And an initialised environment
|
||||
|
||||
Scenario: A compatible binary is installed
|
||||
And a machine with "Mac OSX" installed
|
||||
And the system is bootstrapped
|
||||
And the candidate "java" version "8u101" is available for download on "Mac OSX"
|
||||
When I enter "sdk install java 8u101" and answer "Y"
|
||||
Then I see "Done installing!"
|
||||
And the candidate "java" version "8u101" is installed
|
||||
|
||||
Scenario: Platform is not supported
|
||||
And a machine with "FreeBSD" installed
|
||||
And the system is bootstrapped
|
||||
And the candidate "java" version "8u101" is not available for download on "FreeBSD"
|
||||
When I enter "sdk install java 8u101"
|
||||
Then I see "Stop! java 8u101 is not available on this platform."
|
||||
And the candidate "java" version "8u101" is not installed
|
||||
@@ -39,7 +39,7 @@ Feature: Use Version
|
||||
Given the candidate "groovy" version "1.9.9" is not available for download
|
||||
And the system is bootstrapped
|
||||
When I enter "sdk use groovy 1.9.9"
|
||||
Then I see "Stop! 1.9.9 is not a valid groovy version."
|
||||
Then I see "Stop! groovy 1.9.9 is not available on this platform."
|
||||
|
||||
Scenario: Use a candidate version that only exists locally
|
||||
Given the candidate "grails" version "2.0.0.M1" is not available for download
|
||||
|
||||
@@ -11,7 +11,7 @@ class SdkmanBashEnvBuilder {
|
||||
|
||||
//optional fields with sensible defaults
|
||||
private CurlStub curlStub
|
||||
private List candidates = ['groovy', 'grails']
|
||||
private List candidates = ['groovy', 'grails', 'java']
|
||||
private List availableCandidates = candidates
|
||||
private boolean offlineMode = false
|
||||
private String broadcast = "This is a LIVE broadcast!"
|
||||
|
||||
@@ -9,7 +9,7 @@ import static cucumber.api.groovy.Hooks.After
|
||||
import static cucumber.api.groovy.Hooks.Before
|
||||
|
||||
HTTP_PROXY = System.getProperty("httpProxy") ?: ""
|
||||
PLATFORM = UnixUtils.platform
|
||||
PLATFORM = UnixUtils.platform.toLowerCase()
|
||||
|
||||
FAKE_JDK_PATH = "/path/to/my/openjdk"
|
||||
SERVICE_UP_HOST="localhost"
|
||||
@@ -70,4 +70,4 @@ After(){ scenario ->
|
||||
scenario.write("\nOutput: \n${output}")
|
||||
}
|
||||
bash?.stop()
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,8 @@
|
||||
package sdkman.steps
|
||||
|
||||
import sdkman.stubs.UnameStub
|
||||
import sdkman.support.UnixUtils
|
||||
|
||||
import java.util.zip.ZipException
|
||||
import java.util.zip.ZipFile
|
||||
|
||||
@@ -9,6 +12,8 @@ import static sdkman.stubs.WebServiceStub.primeSelfupdate
|
||||
|
||||
import sdkman.env.SdkmanBashEnvBuilder
|
||||
|
||||
import static sdkman.support.UnixUtils.asUname
|
||||
|
||||
And(~'^the sdkman work folder is created$') { ->
|
||||
assert sdkmanDir.isDirectory(), "The SDKMAN directory does not exist."
|
||||
}
|
||||
@@ -75,6 +80,13 @@ And(~'^offline mode is enabled with unreachable internet$') {->
|
||||
javaHome = FAKE_JDK_PATH
|
||||
}
|
||||
|
||||
And(~'^a machine with "(.*)" installed$') { String platform ->
|
||||
def binFolder = "$sdkmanBaseDir/bin" as File
|
||||
UnameStub.prepareIn(binFolder)
|
||||
.forPlatform(asUname(platform))
|
||||
.build()
|
||||
}
|
||||
|
||||
And(~'^an initialised environment$') {->
|
||||
bash = SdkmanBashEnvBuilder.create(sdkmanBaseDir)
|
||||
.withOfflineMode(offlineMode)
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
package sdkman.steps
|
||||
|
||||
import sdkman.support.UnixUtils
|
||||
|
||||
import static cucumber.api.groovy.EN.And
|
||||
import static sdkman.stubs.WebServiceStub.*
|
||||
import static sdkman.support.FilesystemUtils.readCurrentFromCandidateFolder
|
||||
@@ -15,12 +17,22 @@ And(~'^an available selfupdate$') { ->
|
||||
}
|
||||
|
||||
And(~'^the candidate "([^"]*)" version "([^"]*)" is available for download$') { String candidate, String version ->
|
||||
primeEndpointWithString("/candidates/${candidate}/${version}", "valid")
|
||||
primeEndpointWithString("/candidates/${candidate}/${version}/${PLATFORM}", "valid")
|
||||
primeDownloadFor(SERVICE_UP_URL, candidate, version, PLATFORM)
|
||||
}
|
||||
|
||||
And(~'^the candidate "([^"]*)" version "([^"]*)" is not available for download$') { String candidate, String version ->
|
||||
primeEndpointWithString("/candidates/${candidate}/${version}", "invalid")
|
||||
primeEndpointWithString("/candidates/${candidate}/${version}/${PLATFORM}", "invalid")
|
||||
}
|
||||
|
||||
And(~/^the candidate "(.*?)" version "(.*?)" is available for download on "(.*?)"$/) { String candidate, String version, String platform ->
|
||||
String lowerCaseUname = UnixUtils.asUname(platform).toLowerCase()
|
||||
primeEndpointWithString("/candidates/${candidate}/${version}/${lowerCaseUname}", "valid")
|
||||
primeDownloadFor(SERVICE_UP_URL, candidate, version, lowerCaseUname)
|
||||
}
|
||||
|
||||
And(~/^the candidate "(.*?)" version "(.*?)" is not available for download on "(.*?)"$/) { String candidate, String version, String platform ->
|
||||
primeEndpointWithString("/candidates/${candidate}/${version}/${UnixUtils.asUname(platform).toLowerCase()}", "invalid")
|
||||
}
|
||||
|
||||
And(~'^a "([^"]*)" list view is available for consumption$') { String candidate ->
|
||||
@@ -28,11 +40,11 @@ And(~'^a "([^"]*)" list view is available for consumption$') { String candidate
|
||||
}
|
||||
|
||||
And(~'^the candidate "([^"]*)" version "([^"]*)" is a valid candidate version$') { String candidate, String version ->
|
||||
primeEndpointWithString("/candidates/${candidate}/${version}", "valid")
|
||||
primeEndpointWithString("/candidates/${candidate}/${version}/${PLATFORM}", "valid")
|
||||
}
|
||||
|
||||
And(~'^the candidate "([^"]*)" version "([^"]*)" is not a valid candidate version$') { String candidate, String version ->
|
||||
primeEndpointWithString("/candidates/${candidate}/${version}", "invalid")
|
||||
primeEndpointWithString("/candidates/${candidate}/${version}/${PLATFORM}", "invalid")
|
||||
}
|
||||
|
||||
And(~/^the candidate "(.*?)" has a version list available$/) { String candidate ->
|
||||
|
||||
27
src/test/groovy/sdkman/stubs/UnameStub.groovy
Normal file
27
src/test/groovy/sdkman/stubs/UnameStub.groovy
Normal file
@@ -0,0 +1,27 @@
|
||||
package sdkman.stubs
|
||||
|
||||
class UnameStub {
|
||||
|
||||
private File file
|
||||
private uname
|
||||
|
||||
static UnameStub prepareIn(File folder) {
|
||||
folder.mkdirs()
|
||||
|
||||
def file = new File(folder, "uname")
|
||||
file.createNewFile()
|
||||
file.write "#!/bin/bash\n"
|
||||
file.executable = true
|
||||
|
||||
new UnameStub(file:file)
|
||||
}
|
||||
|
||||
UnameStub forPlatform(String uname) {
|
||||
this.uname = uname
|
||||
this
|
||||
}
|
||||
|
||||
void build(){
|
||||
file << "echo $uname"
|
||||
}
|
||||
}
|
||||
@@ -12,16 +12,9 @@ class WebServiceStub {
|
||||
.withBody(body)))
|
||||
}
|
||||
|
||||
static primeEndpointWithBinary(String endpoint, byte[] body) {
|
||||
stubFor(get(urlEqualTo(endpoint)).willReturn(
|
||||
aResponse()
|
||||
.withStatus(200)
|
||||
.withHeader("Content-Type", "application/octet-stream")
|
||||
.withBody(body)))
|
||||
}
|
||||
|
||||
static primeDownloadFor(String host, String candidate, String version, String platform) {
|
||||
stubFor(get(urlEqualTo("/broker/download/${candidate}/${version}?platform=${platform}")).willReturn(
|
||||
stubFor(get(urlEqualTo("/broker/download/${candidate}/${version}/${platform}")).willReturn(
|
||||
aResponse()
|
||||
.withHeader("Location", "${host}/${candidate}-${version}.zip")
|
||||
.withStatus(302)))
|
||||
|
||||
@@ -2,14 +2,24 @@ package sdkman.support
|
||||
|
||||
class UnixUtils {
|
||||
static getPlatform() {
|
||||
def osName = System.getProperty("os.name")
|
||||
switch (osName) {
|
||||
case "Mac OS X":
|
||||
"Darwin"
|
||||
asUname(System.getProperty("os.name"))
|
||||
}
|
||||
|
||||
static asUname(platform) {
|
||||
def result
|
||||
switch (platform) {
|
||||
case "Mac OSX":
|
||||
result = "Darwin"
|
||||
break
|
||||
case "Linux":
|
||||
result = "Linux"
|
||||
break
|
||||
case "FreeBSD":
|
||||
result = "FreeBSD"
|
||||
break
|
||||
default:
|
||||
osName
|
||||
break
|
||||
result = platform
|
||||
}
|
||||
result
|
||||
}
|
||||
}
|
||||
|
||||
BIN
src/test/resources/__files/java-8u101.zip
Normal file
BIN
src/test/resources/__files/java-8u101.zip
Normal file
Binary file not shown.
Reference in New Issue
Block a user