Skip to content

Commit 535e3c9

Browse files
authored
Remove local caching of candidates (#1077)
1 parent 94ccfd0 commit 535e3c9

File tree

12 files changed

+48
-131
lines changed

12 files changed

+48
-131
lines changed

contrib/completion/bash/sdk

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ __sdkman_complete_command() {
4545
candidates=("force")
4646
;;
4747
flush)
48-
candidates=("archives" "temp" "broadcast" "version")
48+
candidates=("temp" "broadcast" "version")
4949
;;
5050
esac
5151

src/jreleaser/distributions/sdkman-cli/brew/formula.rb.tpl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ class {{brewFormulaName}} < Formula
99
def install
1010
libexec.install Dir["*"]
1111

12-
%w[tmp ext etc var archives candidates].each { |dir| mkdir libexec/dir }
12+
%w[tmp ext etc var candidates].each { |dir| mkdir libexec/dir }
1313

1414
system "curl", "-s", "https://api.sdkman.io/2/candidates/all", "-o", libexec/"var/candidates"
1515

src/main/bash/sdkman-flush.sh

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,6 @@ function __sdk_flush() {
2929
__sdkman_echo_green "Version file has been flushed."
3030
fi
3131
;;
32-
archives)
33-
__sdkman_cleanup_folder "archives"
34-
;;
3532
temp)
3633
__sdkman_cleanup_folder "tmp"
3734
;;
@@ -42,7 +39,6 @@ function __sdk_flush() {
4239
__sdkman_cleanup_folder "var/metadata"
4340
;;
4441
*)
45-
__sdkman_cleanup_folder "archives"
4642
__sdkman_cleanup_folder "tmp"
4743
__sdkman_cleanup_folder "var/metadata"
4844
;;

src/main/bash/sdkman-help.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ function __sdk_help() {
4242
fi
4343

4444
__sdkman_echo_no_colour " update"
45-
__sdkman_echo_no_colour " flush [archives|tmp|broadcast|metadata|version]"
45+
__sdkman_echo_no_colour " flush [tmp|broadcast|metadata|version]"
4646
__sdkman_echo_no_colour ""
4747
__sdkman_echo_no_colour " candidate : the SDK to install: groovy, scala, grails, gradle, kotlin, etc."
4848
__sdkman_echo_no_colour " use list command for comprehensive list of candidates"

src/main/bash/sdkman-install.sh

Lines changed: 42 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ function __sdkman_install_candidate_version() {
7070
mkdir -p "${SDKMAN_CANDIDATES_DIR}/${candidate}"
7171

7272
rm -rf "${SDKMAN_DIR}/tmp/out"
73-
unzip -oq "${SDKMAN_DIR}/archives/${candidate}-${version}.zip" -d "${SDKMAN_DIR}/tmp/out"
73+
unzip -oq "${SDKMAN_DIR}/tmp/${candidate}-${version}.zip" -d "${SDKMAN_DIR}/tmp/out"
7474
mv -f "$SDKMAN_DIR"/tmp/out/* "${SDKMAN_CANDIDATES_DIR}/${candidate}/${version}"
7575
__sdkman_echo_green "Done installing!"
7676
echo ""
@@ -114,65 +114,56 @@ function __sdkman_install_local_version() {
114114
}
115115

116116
function __sdkman_download() {
117-
local candidate version archives_folder
117+
local candidate version
118118

119119
candidate="$1"
120120
version="$2"
121121

122-
archives_folder="${SDKMAN_DIR}/archives"
123122
metadata_folder="${SDKMAN_DIR}/var/metadata"
124123
mkdir -p ${metadata_folder}
125124

126-
if [ ! -f "${archives_folder}/${candidate}-${version}.zip" ]; then
127-
local platform_parameter="$(echo $SDKMAN_PLATFORM | tr '[:upper:]' '[:lower:]')"
128-
local download_url="${SDKMAN_CANDIDATES_API}/broker/download/${candidate}/${version}/${platform_parameter}"
129-
local base_name="${candidate}-${version}"
130-
local zip_archive_target="${SDKMAN_DIR}/archives/${base_name}.zip"
131-
local tmp_headers_file="${SDKMAN_DIR}/tmp/${base_name}.headers.tmp"
132-
local headers_file="${metadata_folder}/${base_name}.headers"
133-
134-
# pre-installation hook: implements function __sdkman_pre_installation_hook
135-
local pre_installation_hook="${SDKMAN_DIR}/tmp/hook_pre_${candidate}_${version}.sh"
136-
__sdkman_echo_debug "Get pre-installation hook: ${SDKMAN_CANDIDATES_API}/hooks/pre/${candidate}/${version}/${platform_parameter}"
137-
__sdkman_secure_curl "${SDKMAN_CANDIDATES_API}/hooks/pre/${candidate}/${version}/${platform_parameter}" >| "$pre_installation_hook"
138-
__sdkman_echo_debug "Copy remote pre-installation hook: $pre_installation_hook"
139-
source "$pre_installation_hook"
140-
__sdkman_pre_installation_hook || return 1
141-
__sdkman_echo_debug "Completed pre-installation hook..."
142-
143-
export local binary_input="${SDKMAN_DIR}/tmp/${base_name}.bin"
144-
export local zip_output="${SDKMAN_DIR}/tmp/$base_name.zip"
125+
local platform_parameter="$(echo $SDKMAN_PLATFORM | tr '[:upper:]' '[:lower:]')"
126+
local download_url="${SDKMAN_CANDIDATES_API}/broker/download/${candidate}/${version}/${platform_parameter}"
127+
local base_name="${candidate}-${version}"
128+
local tmp_headers_file="${SDKMAN_DIR}/tmp/${base_name}.headers.tmp"
129+
local headers_file="${metadata_folder}/${base_name}.headers"
130+
131+
# pre-installation hook: implements function __sdkman_pre_installation_hook
132+
local pre_installation_hook="${SDKMAN_DIR}/tmp/hook_pre_${candidate}_${version}.sh"
133+
__sdkman_echo_debug "Get pre-installation hook: ${SDKMAN_CANDIDATES_API}/hooks/pre/${candidate}/${version}/${platform_parameter}"
134+
__sdkman_secure_curl "${SDKMAN_CANDIDATES_API}/hooks/pre/${candidate}/${version}/${platform_parameter}" >| "$pre_installation_hook"
135+
__sdkman_echo_debug "Copy remote pre-installation hook: $pre_installation_hook"
136+
source "$pre_installation_hook"
137+
__sdkman_pre_installation_hook || return 1
138+
__sdkman_echo_debug "Completed pre-installation hook..."
139+
140+
export local binary_input="${SDKMAN_DIR}/tmp/${base_name}.bin"
141+
export local zip_output="${SDKMAN_DIR}/tmp/${base_name}.zip"
145142

146-
echo ""
147-
__sdkman_echo_no_colour "Downloading: ${candidate} ${version}"
148-
echo ""
149-
__sdkman_echo_no_colour "In progress..."
150-
echo ""
143+
echo ""
144+
__sdkman_echo_no_colour "Downloading: ${candidate} ${version}"
145+
echo ""
146+
__sdkman_echo_no_colour "In progress..."
147+
echo ""
151148

152-
# download binary
153-
__sdkman_secure_curl_download "${download_url}" --output "${binary_input}" --dump-header "${tmp_headers_file}"
154-
grep '^X-Sdkman' "${tmp_headers_file}" > "${headers_file}"
155-
__sdkman_echo_debug "Downloaded binary to: ${binary_input} (HTTP headers written to: ${headers_file})"
156-
157-
# post-installation hook: implements function __sdkman_post_installation_hook
158-
# responsible for taking `binary_input` and producing `zip_output`
159-
local post_installation_hook="${SDKMAN_DIR}/tmp/hook_post_${candidate}_${version}.sh"
160-
__sdkman_echo_debug "Get post-installation hook: ${SDKMAN_CANDIDATES_API}/hooks/post/${candidate}/${version}/${platform_parameter}"
161-
__sdkman_secure_curl "${SDKMAN_CANDIDATES_API}/hooks/post/${candidate}/${version}/${platform_parameter}" >| "$post_installation_hook"
162-
__sdkman_echo_debug "Copy remote post-installation hook: ${post_installation_hook}"
163-
source "$post_installation_hook"
164-
__sdkman_post_installation_hook || return 1
165-
__sdkman_echo_debug "Processed binary as: $zip_output"
166-
__sdkman_echo_debug "Completed post-installation hook..."
167-
168-
mv -f "$zip_output" "$zip_archive_target"
169-
__sdkman_echo_debug "Moved to archive folder: $zip_archive_target"
170-
else
171-
echo ""
172-
__sdkman_echo_no_colour "Found a previously downloaded ${candidate} ${version} archive. Not downloading it again..."
173-
fi
174-
__sdkman_validate_zip "${archives_folder}/${candidate}-${version}.zip" || return 1
175-
__sdkman_checksum_zip "${archives_folder}/${candidate}-${version}.zip" "${headers_file}" || return 1
149+
# download binary
150+
__sdkman_secure_curl_download "${download_url}" --output "${binary_input}" --dump-header "${tmp_headers_file}"
151+
grep '^X-Sdkman' "${tmp_headers_file}" > "${headers_file}"
152+
__sdkman_echo_debug "Downloaded binary to: ${binary_input} (HTTP headers written to: ${headers_file})"
153+
154+
# post-installation hook: implements function __sdkman_post_installation_hook
155+
# responsible for taking `binary_input` and producing `zip_output`
156+
local post_installation_hook="${SDKMAN_DIR}/tmp/hook_post_${candidate}_${version}.sh"
157+
__sdkman_echo_debug "Get post-installation hook: ${SDKMAN_CANDIDATES_API}/hooks/post/${candidate}/${version}/${platform_parameter}"
158+
__sdkman_secure_curl "${SDKMAN_CANDIDATES_API}/hooks/post/${candidate}/${version}/${platform_parameter}" >| "$post_installation_hook"
159+
__sdkman_echo_debug "Copy remote post-installation hook: ${post_installation_hook}"
160+
source "$post_installation_hook"
161+
__sdkman_post_installation_hook || return 1
162+
__sdkman_echo_debug "Processed binary as: $zip_output"
163+
__sdkman_echo_debug "Completed post-installation hook..."
164+
165+
__sdkman_validate_zip "${zip_output}" || return 1
166+
__sdkman_checksum_zip "${zip_output}" "${headers_file}" || return 1
176167
echo ""
177168
}
178169

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ class SdkmanBashEnvBuilder {
3434
sdkman_selfupdate_feature: 'true'
3535
]
3636

37-
File sdkmanDir, sdkmanBinDir, sdkmanVarDir, sdkmanSrcDir, sdkmanEtcDir, sdkmanExtDir, sdkmanArchivesDir,
37+
File sdkmanDir, sdkmanBinDir, sdkmanVarDir, sdkmanSrcDir, sdkmanEtcDir, sdkmanExtDir,
3838
sdkmanTmpDir, sdkmanCandidatesDir, sdkmanMetadataDir, sdkmanContribDir
3939

4040
static SdkmanBashEnvBuilder create(File baseFolder) {
@@ -112,7 +112,6 @@ class SdkmanBashEnvBuilder {
112112
sdkmanSrcDir = prepareDirectory(sdkmanDir, "src")
113113
sdkmanEtcDir = prepareDirectory(sdkmanDir, "etc")
114114
sdkmanExtDir = prepareDirectory(sdkmanDir, "ext")
115-
sdkmanArchivesDir = prepareDirectory(sdkmanDir, "archives")
116115
sdkmanTmpDir = prepareDirectory(sdkmanDir, "tmp")
117116
sdkmanCandidatesDir = prepareDirectory(sdkmanDir, "candidates")
118117
sdkmanMetadataDir = prepareDirectory(sdkmanVarDir, "metadata")

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ varDir = "${sdkmanDirEnv}/var" as File
3434
metadataDir = "${varDir}/metadata" as File
3535
etcDir = "${sdkmanDirEnv}/etc" as File
3636
extDir = "${sdkmanDirEnv}/ext" as File
37-
archiveDir = "${sdkmanDirEnv}/archives" as File
3837
tmpDir = "${sdkmanDir}/tmp" as File
3938

4039
broadcastFile = new File(varDir, "broadcast")

src/test/groovy/sdkman/steps/flush_steps.groovy

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
package sdkman.steps
22

3-
import java.nio.file.Files
4-
import java.nio.file.Paths
5-
63
import static cucumber.api.groovy.EN.And
74

85
And(~'^the candidate "([^"]*)" is known locally$') { String candidate ->
@@ -13,16 +10,6 @@ And(~'^no candidates are know locally$') { ->
1310
assert !candidatesFile.exists()
1411
}
1512

16-
And(~'^the archive "([^"]*)" has been cached$') { String archive ->
17-
Files.copy(
18-
Paths.get("src/test/resources/__files", archive),
19-
Paths.get(archiveDir.getAbsolutePath(), archive))
20-
}
21-
22-
And(~'^no archives are cached$') { ->
23-
assert !archiveDir.listFiles()
24-
}
25-
2613
And(~'^the file "([^"]*)" in temporary storage$') { String fileName ->
2714
new File(tmpDir, fileName).createNewFile()
2815
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ And(~'^the archive for candidate "([^"]*)" version "([^"]*)" is corrupt$') { Str
3030
}
3131

3232
And(~'^the archive for candidate "([^"]*)" version "([^"]*)" is removed$') { String candidate, String version ->
33-
def archive = new File("${sdkmanDir}/archives/${candidate}-${version}.zip")
33+
def archive = new File("${sdkmanDir}/tmp/${candidate}-${version}.zip")
3434
assert !archive.exists()
3535
}
3636

src/test/resources/features/checksum_verification.feature

Lines changed: 0 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -32,42 +32,6 @@ Feature: Verify checksums
3232
And the response headers file is created for candidate "grails" and version "1.3.9"
3333
And the exit code is 0
3434

35-
Scenario: Install an already downloaded Candidate with a valid MD5 checksum and no local headers file
36-
Given the system is bootstrapped
37-
And the candidate "grails" version "1.3.9" is available for download
38-
And the archive "grails-1.3.9.zip" has been cached
39-
When I enter "sdk install grails 1.3.9"
40-
Then I see "Found a previously downloaded grails 1.3.9 archive. Not downloading it again..."
41-
And I see "Done installing!"
42-
And I see "Skipping checksum for cached artifact"
43-
And I do not see "Downloading: grails 1.3.9"
44-
And the candidate "grails" version "1.3.9" is installed
45-
And the exit code is 0
46-
47-
Scenario: Install an already downloaded Candidate with a valid MD5 checksum
48-
Given the system is bootstrapped
49-
And the candidate "grails" version "1.3.9" is available for download
50-
And the archive "grails-1.3.9.zip" has been cached
51-
And a headers file "grails-1.3.9.headers" in metadata directory with checksum "1e87a7d982a2f41da96fdec289908552" using algorithm "MD5"
52-
When I enter "sdk install grails 1.3.9"
53-
Then I see "Found a previously downloaded grails 1.3.9 archive. Not downloading it again..."
54-
And I see "Done installing!"
55-
And I do not see "Downloading: grails 1.3.9"
56-
And the candidate "grails" version "1.3.9" is installed
57-
And the exit code is 0
58-
59-
Scenario: Install an already downloaded Candidate with a valid SHA1 checksum
60-
Given the system is bootstrapped
61-
And the candidate "grails" version "1.3.9" is available for download
62-
And the archive "grails-1.3.9.zip" has been cached
63-
And a headers file "grails-1.3.9.headers" in metadata directory with checksum "c68e386a6deec9fc4c1e18df21f92739ba2ab36e" using algorithm "SHA1"
64-
When I enter "sdk install grails 1.3.9"
65-
Then I see "Found a previously downloaded grails 1.3.9 archive. Not downloading it again..."
66-
And I see "Done installing!"
67-
And I do not see "Downloading: grails 1.3.9"
68-
And the candidate "grails" version "1.3.9" is installed
69-
And the exit code is 0
70-
7135
Scenario: Do not fail if an unknown algorithm is used
7236
Given the system is bootstrapped
7337
And the candidate "grails" version "1.3.9" is available for download with checksum "abc-checksum-00000" using algorithm "ABC"

0 commit comments

Comments
 (0)