Skip to content

Commit

Permalink
chore(package-managers): Simplify code to get javaHome a bit
Browse files Browse the repository at this point in the history
Signed-off-by: Sebastian Schuberth <sebastian@doubleopen.org>
  • Loading branch information
sschuberth committed Sep 27, 2024
1 parent 407d287 commit f9a91f9
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -180,16 +180,13 @@ class GradleInspector(
addProgressListener(ProgressListener { logger.debug(it.displayName) })
}

val javaHome = options[OPTION_JAVA_VERSION]?.let {
if (!JavaBootstrapper.isRunningOnJdk(it)) {
val javaHome = options[OPTION_JAVA_VERSION]
?.takeUnless { JavaBootstrapper.isRunningOnJdk(it) }
?.let {
JavaBootstrapper.installJdk("TEMURIN", it)
.onFailure { e ->
issues += createAndLogIssue(managerName, e.collectMessages())
}.getOrNull()
} else {
null
}
} ?: options[OPTION_JAVA_HOME]?.let { File(it) }
.onFailure { e -> issues += createAndLogIssue(managerName, e.collectMessages()) }
.getOrNull()
} ?: options[OPTION_JAVA_HOME]?.let { File(it) }

javaHome?.also {
logger.info { "Setting Java home for project analysis to '$it'." }
Expand Down
15 changes: 6 additions & 9 deletions plugins/package-managers/sbt/src/main/kotlin/Sbt.kt
Original file line number Diff line number Diff line change
Expand Up @@ -125,16 +125,13 @@ class Sbt(

// TODO: Consider auto-detecting the Java version based on the SBT version. See:
// https://docs.scala-lang.org/overviews/jdk-compatibility/overview.html#build-tool-compatibility-table
val javaHome = options[OPTION_JAVA_VERSION]?.let {
if (!JavaBootstrapper.isRunningOnJdk(it)) {
val javaHome = options[OPTION_JAVA_VERSION]
?.takeUnless { JavaBootstrapper.isRunningOnJdk(it) }
?.let {
JavaBootstrapper.installJdk("TEMURIN", it)
.onFailure { e ->
logger.error { "Failed to bootstrap JDK version $it: ${e.collectMessages()}" }
}.getOrNull()
} else {
null
}
} ?: options[OPTION_JAVA_HOME]?.let { File(it) }
.onFailure { e -> logger.error { "Failed to bootstrap JDK version $it: ${e.collectMessages()}" } }
.getOrNull()
} ?: options[OPTION_JAVA_HOME]?.let { File(it) }

javaHome?.also {
logger.info { "Setting Java home for project analysis to '$it'." }
Expand Down

0 comments on commit f9a91f9

Please sign in to comment.