Skip to content

Commit 6d028ef

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 6d028ef

File tree

1 file changed

+17
-11
lines changed

1 file changed

+17
-11
lines changed

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

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -131,21 +131,27 @@ object JavaBootstrapper {
131131
return Result.failure(it)
132132
}
133133

134-
val installDir = (ortToolsDirectory / "jdks" / pkg.distribution / pkg.distributionVersion)
135-
.apply {
136-
if (isDirectory) {
137-
logger.info { "Not downloading the JDK again as the directory '$this' already exists." }
138-
return Result.success(singleContainedDirectoryOrThis())
139-
}
140-
141-
safeMkdirs()
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)
142+
.apply {
143+
if (isDirectory) {
144+
logger.info { "Not downloading the JDK again as the directory '$this' already exists." }
145+
return Result.success(singleContainedDirectoryOrThis())
142146
}
143147

144-
val url = pkg.links.pkgDownloadRedirect
145-
logger.info { "Downloading the JDK package from $url..." }
148+
safeMkdirs()
149+
}
150+
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)