JdkDownloader: add ability to download specific jdk number

Needed to be able to quickly avoid JBR-7276 and not to wait until next week with randomly failing rdct tests

GitOrigin-RevId: 26ec5543e6f0070b55a55ae791bac062beea3671
This commit is contained in:
Anastasia Katsman
2024-06-11 13:53:34 +02:00
committed by intellij-monorepo-bot
parent 1693fd94b9
commit ebfa882c5d
5 changed files with 20 additions and 16 deletions

View File

@@ -27,7 +27,7 @@ interface PathsProvider {
get() = launcherFolder.resolve("system")
val javaHomeFolder: File
get() = JdkDownloader.getJdkHome(BuildDependenciesCommunityRoot(communityRootFolder.toPath())).normalize().toFile()
get() = JdkDownloader.getJdkHome(BuildDependenciesCommunityRoot(communityRootFolder.toPath()), jdkBuildNumber = "17.0.11b1301.1").normalize().toFile()
val mavenRepositoryFolder: File
get() = File(System.getProperty("user.home")).resolve(".m2/repository")

View File

@@ -13,27 +13,27 @@ import java.util.logging.Logger
* Provides a current JBR SDK
*/
object JdkDownloader {
fun blockingGetJdkHome(communityRoot: BuildDependenciesCommunityRoot, infoLog: (String) -> Unit): Path {
fun blockingGetJdkHome(communityRoot: BuildDependenciesCommunityRoot, jdkBuildNumber: String? = null, infoLog: (String) -> Unit): Path {
return runBlocking(Dispatchers.IO) {
getJdkHome(communityRoot, infoLog)
getJdkHome(communityRoot, jdkBuildNumber, infoLog)
}
}
suspend fun getJdkHome(communityRoot: BuildDependenciesCommunityRoot, infoLog: (String) -> Unit): Path {
suspend fun getJdkHome(communityRoot: BuildDependenciesCommunityRoot, jdkBuildNumber: String? = null, infoLog: (String) -> Unit): Path {
val os = OS.current
val arch = Arch.current
return getJdkHome(communityRoot = communityRoot, os = os, arch = arch, infoLog = infoLog)
return getJdkHome(communityRoot = communityRoot, os = os, arch = arch, infoLog = infoLog, jdkBuildNumber = jdkBuildNumber)
}
@JvmStatic
fun getJdkHome(communityRoot: BuildDependenciesCommunityRoot): Path {
return blockingGetJdkHome(communityRoot) {
fun getJdkHome(communityRoot: BuildDependenciesCommunityRoot, jdkBuildNumber: String? = null): Path {
return blockingGetJdkHome(communityRoot, jdkBuildNumber) {
Logger.getLogger(JdkDownloader::class.java.name).info(it)
}
}
suspend fun getJdkHome(communityRoot: BuildDependenciesCommunityRoot, os: OS, arch: Arch, infoLog: (String) -> Unit): Path {
val jdkUrl = getUrl(communityRoot = communityRoot, os = os, arch = arch)
suspend fun getJdkHome(communityRoot: BuildDependenciesCommunityRoot, os: OS, arch: Arch, jdkBuildNumber: String? = null, infoLog: (String) -> Unit): Path {
val jdkUrl = getUrl(communityRoot = communityRoot, os = os, arch = arch, jdkBuildNumber = jdkBuildNumber)
val jdkArchive = downloadFileToCacheLocation(url = jdkUrl.toString(), communityRoot = communityRoot)
val jdkExtracted = BuildDependenciesDownloader.extractFileToCacheLocation(communityRoot = communityRoot,
archiveFile = jdkArchive,
@@ -54,7 +54,7 @@ object JdkDownloader {
throw IllegalStateException("No java executables were found under $jdkHome")
}
private fun getUrl(communityRoot: BuildDependenciesCommunityRoot, os: OS, arch: Arch): URI {
private fun getUrl(communityRoot: BuildDependenciesCommunityRoot, os: OS, arch: Arch, jdkBuildNumber: String? = null): URI {
val ext = ".tar.gz"
val osString: String = when (os) {
OS.WINDOWS -> "windows"
@@ -66,8 +66,12 @@ object JdkDownloader {
Arch.ARM64 -> "aarch64"
}
val dependencyProperties = BuildDependenciesDownloader.getDependencyProperties(communityRoot)
val jdkBuild = dependencyProperties.property("jdkBuild")
val jdkBuild = if (jdkBuildNumber == null) {
val dependencyProperties = BuildDependenciesDownloader.getDependencyProperties(communityRoot)
dependencyProperties.property("jdkBuild")
} else {
jdkBuildNumber
}
val jdkBuildSplit = jdkBuild.split("b".toRegex()).dropLastWhile { it.isEmpty() }
check(jdkBuildSplit.size == 2) { "Malformed jdkBuild property: $jdkBuild" }
val version = jdkBuildSplit[0]

View File

@@ -91,7 +91,7 @@ class GradleRunner(
command.addAll(tasks)
val gradleCall = {
val processBuilder = ProcessBuilder(command).directory(gradleProjectDir.toFile())
processBuilder.environment().put("JAVA_HOME", JdkDownloader.blockingGetJdkHome(communityRoot, Span.current()::addEvent).toString())
processBuilder.environment().put("JAVA_HOME", JdkDownloader.blockingGetJdkHome(communityRoot, infoLog = Span.current()::addEvent).toString())
processBuilder.inheritIO()
synchronized(gradleProjectDir.toString().intern()) {
processBuilder.start().waitFor() == 0

View File

@@ -128,7 +128,7 @@ class CompilationContextImpl private constructor(
override suspend fun getStableJdkHome(): Path {
var jdkHome = cachedJdkHome
if (jdkHome == null) {
jdkHome = JdkDownloader.getJdkHome(COMMUNITY_ROOT, Span.current()::addEvent)
jdkHome = JdkDownloader.getJdkHome(COMMUNITY_ROOT, infoLog = Span.current()::addEvent)
cachedJdkHome = jdkHome
}
return jdkHome
@@ -138,7 +138,7 @@ class CompilationContextImpl private constructor(
var jdkHome = cachedJdkHome
if (jdkHome == null) {
// blocking doesn't matter, getStableJdkHome is mostly always called before
jdkHome = JdkDownloader.blockingGetJdkHome(COMMUNITY_ROOT, Span.current()::addEvent)
jdkHome = JdkDownloader.blockingGetJdkHome(COMMUNITY_ROOT, infoLog = Span.current()::addEvent)
cachedJdkHome = jdkHome
}
JdkDownloader.getJavaExecutable(jdkHome)

View File

@@ -78,7 +78,7 @@ abstract class GroovyCompilerTestCase extends JavaCodeInsightFixtureTestCase imp
ModuleGroupTestsKt.renameModule(module, "mainModule")
def communityHomePath = Paths.get(PathManager.getHomePathFor(GroovyCompilerTestCase.class),"community")
def javaHomePath = JdkDownloader.getJdkHome(new BuildDependenciesCommunityRoot(communityHomePath))
def javaHomePath = JdkDownloader.getJdkHome(new BuildDependenciesCommunityRoot(communityHomePath), null)
def javaHome = javaHomePath.toAbsolutePath().toString()
javaHome = StringUtil.trimEnd(StringUtil.trimEnd(javaHome, '/'), '/jre')
VfsRootAccess.allowRootAccess(testRootDisposable, javaHome)