Skip to content

Commit

Permalink
Add function to get toolchain JDK home location
Browse files Browse the repository at this point in the history
  • Loading branch information
Badya authored and qodana-bot committed Apr 27, 2023
1 parent 08c22c3 commit e7989ee
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 8 deletions.
7 changes: 7 additions & 0 deletions buildSrc/src/main/kotlin/JvmToolchain.kt
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
@file:JvmName("JvmToolchain")

import org.gradle.api.Project
import org.gradle.api.plugins.JavaPluginExtension
import org.gradle.api.provider.Provider
Expand Down Expand Up @@ -195,6 +196,12 @@ fun Project.getToolchainLauncherFor(
}
}

fun Project.getToolchainJdkHomeFor(jdkVersion: JdkMajorVersion): Provider<String> {
return getToolchainLauncherFor(jdkVersion).map {
it.metadata.installationPath.asFile.absolutePath
}
}


fun Project.getJdkVersionWithOverride(jdkVersion: JdkMajorVersion): JdkMajorVersion {
return if (project.shouldOverrideObsoleteJdk(jdkVersion)) {
Expand Down
4 changes: 2 additions & 2 deletions buildSrc/src/main/kotlin/tasks.kt
Original file line number Diff line number Diff line change
Expand Up @@ -258,8 +258,8 @@ fun Project.projectTest(
}

defineJDKEnvVariables.forEach { version ->
val javaLauncher = project.getToolchainLauncherFor(version).orNull ?: error("Can't find toolchain for $version")
environment(version.envName, javaLauncher.metadata.installationPath.asFile.absolutePath)
val jdkHome = project.getToolchainJdkHomeFor(version).orNull ?: error("Can't find toolchain for $version")
environment(version.envName, jdkHome)
}
}.apply { configure(body) }
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -347,12 +347,12 @@ tasks.withType<Test> {
systemProperty("installCocoapods", installCocoapods)
}

val jdk8Provider = project.getToolchainLauncherFor(JdkMajorVersion.JDK_1_8).map { it.metadata.installationPath.asFile.absolutePath }
val jdk9Provider = project.getToolchainLauncherFor(JdkMajorVersion.JDK_9_0).map { it.metadata.installationPath.asFile.absolutePath }
val jdk10Provider = project.getToolchainLauncherFor(JdkMajorVersion.JDK_10_0).map { it.metadata.installationPath.asFile.absolutePath }
val jdk11Provider = project.getToolchainLauncherFor(JdkMajorVersion.JDK_11_0).map { it.metadata.installationPath.asFile.absolutePath }
val jdk16Provider = project.getToolchainLauncherFor(JdkMajorVersion.JDK_16_0).map { it.metadata.installationPath.asFile.absolutePath }
val jdk17Provider = project.getToolchainLauncherFor(JdkMajorVersion.JDK_17_0).map { it.metadata.installationPath.asFile.absolutePath }
val jdk8Provider = project.getToolchainJdkHomeFor(JdkMajorVersion.JDK_1_8)
val jdk9Provider = project.getToolchainJdkHomeFor(JdkMajorVersion.JDK_9_0)
val jdk10Provider = project.getToolchainJdkHomeFor(JdkMajorVersion.JDK_10_0)
val jdk11Provider = project.getToolchainJdkHomeFor(JdkMajorVersion.JDK_11_0)
val jdk16Provider = project.getToolchainJdkHomeFor(JdkMajorVersion.JDK_16_0)
val jdk17Provider = project.getToolchainJdkHomeFor(JdkMajorVersion.JDK_17_0)
val mavenLocalRepo = project.providers.systemProperty("maven.repo.local").forUseAtConfigurationTime().orNull

// Query required JDKs paths only on execution phase to avoid triggering auto-download on project configuration phase
Expand Down

0 comments on commit e7989ee

Please sign in to comment.