diff --git a/java/debugger/impl/src/com/intellij/debugger/engine/AsyncStacksUtils.java b/java/debugger/impl/src/com/intellij/debugger/engine/AsyncStacksUtils.java index a754a54b7940..3ca2e9269f63 100644 --- a/java/debugger/impl/src/com/intellij/debugger/engine/AsyncStacksUtils.java +++ b/java/debugger/impl/src/com/intellij/debugger/engine/AsyncStacksUtils.java @@ -313,7 +313,7 @@ public final class AsyncStacksUtils { Path communityRoot = Path.of(PathManager.getCommunityHomePath()); Path iml = BuildDependenciesJps.getProjectModule(communityRoot, "intellij.java.debugger.agent.holder"); - Path downloadedAgent = BuildDependenciesJps.getModuleLibrarySingleRoot( + Path downloadedAgent = BuildDependenciesJps.INSTANCE.getModuleLibrarySingleRootSync( iml, "debugger-agent", "https://cache-redirector.jetbrains.com/intellij-dependencies", diff --git a/platform/build-scripts/downloader/src/BuildDependenciesJps.kt b/platform/build-scripts/downloader/src/BuildDependenciesJps.kt index 8741853e3c54..4986002ea2f8 100644 --- a/platform/build-scripts/downloader/src/BuildDependenciesJps.kt +++ b/platform/build-scripts/downloader/src/BuildDependenciesJps.kt @@ -1,12 +1,12 @@ -// Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license. +// Copyright 2000-2025 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license. package org.jetbrains.intellij.build import com.google.common.hash.Funnels import com.google.common.hash.Hashing import com.google.common.io.ByteStreams +import kotlinx.coroutines.runBlocking import org.jetbrains.annotations.ApiStatus import org.jetbrains.intellij.build.dependencies.BuildDependenciesCommunityRoot -import org.jetbrains.intellij.build.dependencies.BuildDependenciesDownloader import org.jetbrains.intellij.build.dependencies.BuildDependenciesDownloader.Credentials import org.jetbrains.intellij.build.dependencies.BuildDependenciesUtil import org.jetbrains.intellij.build.dependencies.BuildDependenciesUtil.asText @@ -16,7 +16,6 @@ import org.jetbrains.intellij.build.dependencies.BuildDependenciesUtil.getLibrar import org.jetbrains.intellij.build.dependencies.BuildDependenciesUtil.getSingleChildElement import org.jetbrains.intellij.build.dependencies.BuildDependenciesUtil.tryGetSingleChildElement import org.w3c.dom.Element -import java.net.URI import java.nio.file.Files import java.nio.file.Path @@ -42,7 +41,7 @@ object BuildDependenciesJps { return modulePath } - private fun getLibraryRoots( + private suspend fun getLibraryRoots( library: Element, mavenRepositoryUrl: String, communityRoot: BuildDependenciesCommunityRoot, @@ -76,8 +75,8 @@ object BuildDependenciesJps { val file = when { Files.isRegularFile(localMavenFile) && Files.size(localMavenFile) > 0 -> localMavenFile - credentialsProvider != null -> BuildDependenciesDownloader.downloadFileToCacheLocation(communityRoot, URI(remoteUrl), credentialsProvider) - else -> BuildDependenciesDownloader.downloadFileToCacheLocation(communityRoot, URI(remoteUrl)) + credentialsProvider != null -> downloadFileToCacheLocation(remoteUrl, communityRoot, credentialsProvider) + else -> downloadFileToCacheLocation(remoteUrl, communityRoot) } // '-SNAPSHOT' versions could be used only locally to test new locally built dependencies @@ -98,46 +97,58 @@ object BuildDependenciesJps { } } - @JvmStatic - fun getModuleLibraryRoots( + suspend fun getModuleLibraryRoots( iml: Path, libraryName: String, mavenRepositoryUrl: String, communityRoot: BuildDependenciesCommunityRoot, credentialsProvider: (() -> Credentials)? - ): List = try { - val root = BuildDependenciesUtil.createDocumentBuilder().parse(iml.toFile()).documentElement + ): List { + return try { + val root = BuildDependenciesUtil.createDocumentBuilder().parse(iml.toFile()).documentElement - val library = root.getLibraryElement(libraryName, iml) - val roots = getLibraryRoots(library, mavenRepositoryUrl, communityRoot, credentialsProvider) + val library = root.getLibraryElement(libraryName, iml) + val roots = getLibraryRoots(library, mavenRepositoryUrl, communityRoot, credentialsProvider) - if (roots.isEmpty()) { - error("No library roots for library '$libraryName' in the following iml file at '$iml':\n${Files.readString(iml)}") + if (roots.isEmpty()) { + error("No library roots for library '$libraryName' in the following iml file at '$iml':\n${Files.readString(iml)}") + } + + roots + } + catch (t: Throwable) { + throw IllegalStateException("Unable to find module library '$libraryName' in '$iml'", t) } - - roots - } - catch (t: Throwable) { - throw IllegalStateException("Unable to find module library '$libraryName' in '$iml'", t) } - @JvmStatic - fun getModuleLibrarySingleRoot( + @Deprecated("Use getModuleLibraryRoots instead", ReplaceWith("getModuleLibraryRoots(iml, libraryName, mavenRepositoryUrl, communityRoot, null)"), level = DeprecationLevel.ERROR) + fun getModuleLibrarySingleRootSync( iml: Path, libraryName: String, mavenRepositoryUrl: String, - communityRoot: BuildDependenciesCommunityRoot - ) = getModuleLibrarySingleRoot(iml, libraryName, mavenRepositoryUrl, communityRoot, null) + communityRoot: BuildDependenciesCommunityRoot, + ): Path { + return runBlocking { + getModuleLibrarySingleRoot(iml = iml, libraryName = libraryName, mavenRepositoryUrl = mavenRepositoryUrl, communityRoot = communityRoot) + } + } - @JvmStatic - fun getModuleLibrarySingleRoot( + suspend fun getModuleLibrarySingleRoot( + iml: Path, + libraryName: String, + mavenRepositoryUrl: String, + communityRoot: BuildDependenciesCommunityRoot, + ): Path { + return getModuleLibrarySingleRoot(iml = iml, libraryName = libraryName, mavenRepositoryUrl = mavenRepositoryUrl, communityRoot = communityRoot, credentialsProvider = null) + } + + suspend fun getModuleLibrarySingleRoot( iml: Path, libraryName: String, mavenRepositoryUrl: String, communityRoot: BuildDependenciesCommunityRoot, credentialsProvider: (() -> Credentials)? ): Path { - val roots = getModuleLibraryRoots(iml, libraryName, mavenRepositoryUrl, communityRoot, credentialsProvider) if (roots.size != 1) { error("Expected one and only one library '$libraryName' root in '$iml', but got ${roots.size}: ${roots.joinToString()}") @@ -146,7 +157,7 @@ object BuildDependenciesJps { return roots.single() } - fun getProjectLibraryRoots( + suspend fun getProjectLibraryRoots( libraryXml: Path, libraryName: String, mavenRepositoryUrl: String, diff --git a/platform/build-scripts/tests/testSrc/org/jetbrains/intellij/build/dependencies/BuildDependenciesJpsTest.kt b/platform/build-scripts/tests/testSrc/org/jetbrains/intellij/build/dependencies/BuildDependenciesJpsTest.kt index 5191ff9d0067..5558bc95b416 100644 --- a/platform/build-scripts/tests/testSrc/org/jetbrains/intellij/build/dependencies/BuildDependenciesJpsTest.kt +++ b/platform/build-scripts/tests/testSrc/org/jetbrains/intellij/build/dependencies/BuildDependenciesJpsTest.kt @@ -1,6 +1,7 @@ -// Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license. +// Copyright 2000-2025 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license. package org.jetbrains.intellij.build.dependencies +import kotlinx.coroutines.runBlocking import org.jetbrains.intellij.build.BuildDependenciesJps import org.jetbrains.intellij.build.IdeaProjectLoaderUtil import org.junit.Assert.assertEquals @@ -8,12 +9,18 @@ import org.junit.Assert.assertTrue import org.junit.Test import org.junit.jupiter.api.assertThrows import java.nio.file.Path -import kotlin.io.path.* +import kotlin.io.path.ExperimentalPathApi +import kotlin.io.path.createDirectories +import kotlin.io.path.deleteIfExists +import kotlin.io.path.deleteRecursively +import kotlin.io.path.isDirectory +import kotlin.io.path.pathString +import kotlin.io.path.writeText @OptIn(ExperimentalPathApi::class) class BuildDependenciesJpsTest { @Test - fun getModuleLibrarySingleRoot() { + fun getModuleLibrarySingleRoot() = runBlocking { val iml = getTestDataRoot().resolve("jps_library_test_iml.xml") val root = BuildDependenciesJps.getModuleLibrarySingleRoot( iml, @@ -26,7 +33,7 @@ class BuildDependenciesJpsTest { } @Test - fun getModuleLibrarySingleRoot_snapshot_version() { + fun getModuleLibrarySingleRoot_snapshot_version() = runBlocking { val snapshotDir = BuildDependenciesJps.getLocalArtifactRepositoryRoot().resolve("org/jetbrains/intellij/deps/debugger-agent/1.0-SNAPSHOT") snapshotDir.deleteRecursively() @@ -50,7 +57,7 @@ class BuildDependenciesJpsTest { } @Test - fun getModuleLibrarySingleRoot_wrong_checksum() { + fun getModuleLibrarySingleRoot_wrong_checksum() = runBlocking { val iml = getTestDataRoot().resolve("jps_library_test_iml_wrong_checksum.xml") val ex = assertThrows { BuildDependenciesJps.getModuleLibrarySingleRoot( @@ -68,7 +75,7 @@ class BuildDependenciesJpsTest { } @Test - fun getModuleLibrarySingleRoot_missing_checksum() { + fun getModuleLibrarySingleRoot_missing_checksum() = runBlocking { val iml = getTestDataRoot().resolve("jps_library_test_iml_missing_checksum.xml") val ex = assertThrows { BuildDependenciesJps.getModuleLibrarySingleRoot( @@ -83,7 +90,7 @@ class BuildDependenciesJpsTest { } @Test - fun getModuleLibrarySingleRoot_use_local_file() { + fun getModuleLibrarySingleRoot_use_local_file() = runBlocking { val localFile = BuildDependenciesJps.getLocalArtifactRepositoryRoot() .resolve("org/jetbrains/intellij/deps/debugger-agent/1.0/debugger-agent-1.0.jar") localFile.deleteIfExists()