mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
use non-blocking downloadFileToCacheLocation
GitOrigin-RevId: 2a5c5d622564ab7931b2ed4b202346519487b3e5
This commit is contained in:
committed by
intellij-monorepo-bot
parent
99ed5294e4
commit
e65b44c0b4
@@ -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",
|
||||
|
||||
@@ -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<Path> = try {
|
||||
val root = BuildDependenciesUtil.createDocumentBuilder().parse(iml.toFile()).documentElement
|
||||
): List<Path> {
|
||||
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,
|
||||
|
||||
+14
-7
@@ -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<IllegalStateException> {
|
||||
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<IllegalStateException> {
|
||||
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()
|
||||
|
||||
Reference in New Issue
Block a user