Skip to content

Commit a57105b

Browse files
heliocastrosschuberth
authored andcommitted
refactor(ort-utils): Split out downloading the JDK from installJdk
Move the download logic to a separate function, in the future allowing direct download of a specific JDK and not depending solely on Foojay Disco results. Signed-off-by: Helio Chissini de Castro <[email protected]> Signed-off-by: Sebastian Schuberth <[email protected]>
1 parent 53c2023 commit a57105b

File tree

1 file changed

+17
-9
lines changed

1 file changed

+17
-9
lines changed

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

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -131,17 +131,25 @@ 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(
135+
pkg.links.pkgDownloadRedirect,
136+
ortToolsDirectory / "jdks" / pkg.distribution / pkg.distributionVersion
137+
)
138+
}
139+
140+
/**
141+
* Download a JDK from [url] and unpack it to [installDir]. Return a result with the actual installation directory.
142+
*/
143+
fun downloadJdk(url: String, installDir: File): Result<File> {
144+
with(installDir) {
145+
if (isDirectory) {
146+
logger.info { "Not downloading the JDK again as the directory '$this' already exists." }
147+
return Result.success(singleContainedDirectoryOrThis())
142148
}
143149

144-
val url = pkg.links.pkgDownloadRedirect
150+
safeMkdirs()
151+
}
152+
145153
logger.info { "Downloading the JDK package from $url..." }
146154

147155
val (archive, downloadDuration) = measureTimedValue {

0 commit comments

Comments
 (0)