Skip to content

Commit ba2982c

Browse files
committed
feat(utils): Split installJdk in two functions
Move the download logic to a separate function, allowing direct download of a specific JDK and not depending solely on Foojay Disco results. Signed-off-by: Helio Chissini de Castro <[email protected]>
1 parent 7f4f6c5 commit ba2982c

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

utils/ort/src/main/kotlin/JavaBootstrapper.kt

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,14 @@ object JavaBootstrapper {
131131
return Result.failure(it)
132132
}
133133

134-
val installDir = (ortToolsDirectory / "jdks" / pkg.distribution / pkg.distributionVersion)
134+
return downloadJdk(pkg.links.pkgDownloadRedirect, pkg.distribution, pkg.distributionVersion)
135+
}
136+
137+
/**
138+
* Download the resolved JDK Url and return its directory on success, or an exception on failure.
139+
*/
140+
fun downloadJdk(sdkUrl: String, distribution: String, distributionVersion: String): Result<File> {
141+
val installDir = (ortToolsDirectory / "jdks" / distribution / distributionVersion)
135142
.apply {
136143
if (isDirectory) {
137144
logger.info { "Not downloading the JDK again as the directory '$this' already exists." }
@@ -141,11 +148,10 @@ object JavaBootstrapper {
141148
safeMkdirs()
142149
}
143150

144-
val url = pkg.links.pkgDownloadRedirect
145-
logger.info { "Downloading the JDK package from $url..." }
151+
logger.info { "Downloading the JDK package from $sdkUrl..." }
146152

147153
val (archive, downloadDuration) = measureTimedValue {
148-
okHttpClient.downloadFile(url, installDir).getOrElse {
154+
okHttpClient.downloadFile(sdkUrl, installDir).getOrElse {
149155
return Result.failure(it)
150156
}
151157
}

0 commit comments

Comments
 (0)