Skip to content

Commit 970ab31

Browse files
hgeraldinomarc0der
authored andcommitted
Save HTTP response headers under ${SDKMAN}/var/metadata
1 parent 14c8659 commit 970ab31

File tree

8 files changed

+50
-5
lines changed

8 files changed

+50
-5
lines changed

src/main/bash/sdkman-flush.sh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,13 @@ function __sdk_flush() {
3838
tmp)
3939
__sdkman_cleanup_folder "tmp"
4040
;;
41+
metadata)
42+
__sdkman_cleanup_folder "var/metadata"
43+
;;
4144
*)
4245
__sdkman_cleanup_folder "archives"
4346
__sdkman_cleanup_folder "tmp"
47+
__sdkman_cleanup_folder "var/metadata"
4448
;;
4549
esac
4650
}

src/main/bash/sdkman-install.sh

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,11 +120,15 @@ function __sdkman_download() {
120120
version="$2"
121121

122122
archives_folder="${SDKMAN_DIR}/archives"
123+
metadata_folder="${SDKMAN_DIR}/var/metadata"
124+
mkdir -p ${metadata_folder}
125+
123126
if [ ! -f "${archives_folder}/${candidate}-${version}.zip" ]; then
124127
local platform_parameter="$(echo $SDKMAN_PLATFORM | tr '[:upper:]' '[:lower:]')"
125128
local download_url="${SDKMAN_CANDIDATES_API}/broker/download/${candidate}/${version}/${platform_parameter}"
126129
local base_name="${candidate}-${version}"
127130
local zip_archive_target="${SDKMAN_DIR}/archives/${candidate}-${version}.zip"
131+
local headers="${metadata_folder}/${base_name}.headers"
128132

129133
# pre-installation hook: implements function __sdkman_pre_installation_hook
130134
local pre_installation_hook="${SDKMAN_DIR}/tmp/hook_pre_${candidate}_${version}.sh"
@@ -145,8 +149,8 @@ function __sdkman_download() {
145149
echo ""
146150

147151
# download binary
148-
__sdkman_secure_curl_download "${download_url}" --output "${binary_input}"
149-
__sdkman_echo_debug "Downloaded binary to: ${binary_input}"
152+
__sdkman_secure_curl_download "${download_url}" --output "${binary_input}" --dump-header "${headers}"
153+
__sdkman_echo_debug "Downloaded binary to: ${binary_input} (HTTP headers written to: ${headers})"
150154

151155
# post-installation hook: implements function __sdkman_post_installation_hook
152156
# responsible for taking `binary_input` and producing `zip_output`

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,9 @@ class SdkmanBashEnvBuilder {
3030
sdkman_beta_channel: 'false'
3131
]
3232

33-
File sdkmanDir, sdkmanBinDir, sdkmanVarDir, sdkmanSrcDir, sdkmanEtcDir, sdkmanExtDir, sdkmanArchivesDir, sdkmanTmpDir, sdkmanCandidatesDir
34-
33+
File sdkmanDir, sdkmanBinDir, sdkmanVarDir, sdkmanSrcDir, sdkmanEtcDir, sdkmanExtDir, sdkmanArchivesDir,
34+
sdkmanTmpDir, sdkmanCandidatesDir, sdkmanMetadataDir
35+
3536
static SdkmanBashEnvBuilder create(File baseFolder) {
3637
new SdkmanBashEnvBuilder(baseFolder)
3738
}
@@ -110,6 +111,7 @@ class SdkmanBashEnvBuilder {
110111
sdkmanArchivesDir = prepareDirectory(sdkmanDir, "archives")
111112
sdkmanTmpDir = prepareDirectory(sdkmanDir, "tmp")
112113
sdkmanCandidatesDir = prepareDirectory(sdkmanDir, "candidates")
114+
sdkmanMetadataDir = prepareDirectory(sdkmanVarDir, "metadata")
113115

114116
curlStub.map { it.build() }
115117
unameStub.map { it.build() }

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ candidatesDir = "${sdkmanDirEnv}/candidates" as File
3131
binDir = "${sdkmanDirEnv}/bin" as File
3232
srcDir = "${sdkmanDirEnv}/src" as File
3333
varDir = "${sdkmanDirEnv}/var" as File
34+
metadataDir = "${varDir}/metadata" as File
3435
etcDir = "${sdkmanDirEnv}/etc" as File
3536
extDir = "${sdkmanDirEnv}/ext" as File
3637
archiveDir = "${sdkmanDirEnv}/archives" as File

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,3 +38,11 @@ And(~'^no version file can be found$') { ->
3838
And(~'^the Remote Version has been flushed$') { ->
3939
assert versionFile.delete()
4040
}
41+
42+
And(~'^a headers file "([^"]*)" in metadata directory$') { String fileName ->
43+
new File(metadataDir, fileName).createNewFile()
44+
}
45+
46+
And(~'^no metadata is cached$') { ->
47+
assert !metadataDir.listFiles()
48+
}

src/test/groovy/sdkman/steps/installation_steps.groovy

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,3 +96,15 @@ And(~'^I have configured "([^"]*)" to "([^"]*)"$') { String configName, String f
9696
And(~/^the exit code is (\d+)$/) { Integer rc ->
9797
assert bash.getStatus() == rc
9898
}
99+
100+
And(~'^the response headers file is created for candidate "([^"]*)" and version "([^"]*)"$') { String candidate, String version ->
101+
def headersFile = "${metadataDir}/${candidate}-${version}.headers" as File
102+
if (!headersFile.exists()) println bash.output
103+
assert headersFile.exists()
104+
}
105+
106+
And(~'^no response headers are written for candidate "([^"]*)" and version "([^"]*)"$') { String candidate, String version ->
107+
def headersFile = "${metadataDir}/${candidate}-${version}.headers" as File
108+
if (headersFile.exists()) println bash.output
109+
assert !headersFile.exists()
110+
}

src/test/resources/features/flush.feature

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,14 @@ Feature: Flush
55
And an initialised environment
66
And the system is bootstrapped
77

8-
Scenario: Clear out the cached archives and the temporary storage
8+
Scenario: Clear out the cached archives, the temporary storage and metadata
99
Given the archive "grails-1.3.9.zip" has been cached
1010
And the file "res-1.2.0.zip" in temporary storage
11+
And a headers file "grails-1.3.9.headers" in metadata directory
1112
When I enter "sdk flush"
1213
Then no archives are cached
1314
And no "res-1.2.0.zip" file is present in temporary storage
15+
And no metadata is cached
1416
And I see "1 archive(s) flushed"
1517
And I see "1 archive(s) flushed"
1618

@@ -42,3 +44,9 @@ Feature: Flush
4244
When I enter "sdk flush temp"
4345
Then no "res-1.2.0.zip" file is present in temporary storage
4446
And I see "1 archive(s) flushed"
47+
48+
Scenario: Clear out the metadata
49+
Given a headers file "grails-1.3.9.headers" in metadata directory
50+
When I enter "sdk flush metadata"
51+
Then no metadata is cached
52+
And I see "1 archive(s) flushed"

src/test/resources/features/install_candidate.feature

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ Feature: Install Candidate
1212
Then I see "Done installing!"
1313
And I do not see "Do you want grails 2.1.0 to be set as default? (Y/n)"
1414
And the candidate "grails" version "2.1.0" is installed
15+
And the response headers file is created for candidate "grails" and version "2.1.0"
1516
And the exit code is 0
1617

1718
Scenario: Install a specific Candidate and set to default
@@ -21,6 +22,7 @@ Feature: Install Candidate
2122
Then I see "Done installing!"
2223
And I do not see "Do you want grails 1.3.9 to be set as default? (Y/n)"
2324
And the candidate "grails" version "1.3.9" is installed
25+
And the response headers file is created for candidate "grails" and version "1.3.9"
2426
And the exit code is 0
2527

2628
Scenario: Install a Candidate version that does not exist
@@ -36,6 +38,7 @@ Feature: Install Candidate
3638
And the candidate "grails" version "1.3.9" is already installed and default
3739
When I enter "sdk install grails 1.3.9"
3840
Then I see "grails 1.3.9 is already installed."
41+
And no response headers are written for candidate "grails" and version "1.3.9"
3942
And the exit code is 0
4043

4144
Scenario: Install a candidate and auto-answer to make it default
@@ -44,6 +47,7 @@ Feature: Install Candidate
4447
And I have configured "sdkman_auto_answer" to "true"
4548
When I enter "sdk install grails 2.1.0"
4649
Then the candidate "grails" version "2.1.0" is installed
50+
And the response headers file is created for candidate "grails" and version "2.1.0"
4751
And I do not see "Do you want grails 2.1.0 to be set as default?"
4852
And I see "Done installing!"
4953
And I see "Setting grails 2.1.0 as default."
@@ -56,6 +60,7 @@ Feature: Install Candidate
5660
And the candidate "grails" version "2.1.0" is available for download
5761
When I enter "sdk install grails 2.1.0" and answer "Y"
5862
Then the candidate "grails" version "2.1.0" is installed
63+
And the response headers file is created for candidate "grails" and version "2.1.0"
5964
And I see "Done installing!"
6065
And I see "Do you want grails 2.1.0 to be set as default? (Y/n)"
6166
And I see "Setting grails 2.1.0 as default."
@@ -69,6 +74,7 @@ Feature: Install Candidate
6974
And the candidate "grails" version "2.1.0" is available for download
7075
When I enter "sdk install grails 2.1.0" and answer "n"
7176
Then the candidate "grails" version "2.1.0" is installed
77+
And the response headers file is created for candidate "grails" and version "2.1.0"
7278
And I see "Done installing!"
7379
And I see "Do you want grails 2.1.0 to be set as default? (Y/n)"
7480
And I do not see "Setting grails 2.1.0 as default."

0 commit comments

Comments
 (0)