mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
[gradle][tooling extension][IDEA-382098] pollAllPendingResults: one faulty task should not break the processing queue
GitOrigin-RevId: 522a247c36d92869d86899d56ba52486c8a06479
This commit is contained in:
committed by
intellij-monorepo-bot
parent
31dff4469d
commit
595f063661
+1
-1
@@ -116,7 +116,7 @@ public class GradleDaemonModelHolder {
|
||||
}
|
||||
|
||||
private @NotNull List<DefaultGradleLightBuild> pollPendingConvertedNestedBuilds() {
|
||||
List<DefaultGradleLightBuild> builds = GradleExecutorServiceUtil.poolPendingResult(myConvertedBuilds);
|
||||
List<DefaultGradleLightBuild> builds = GradleExecutorServiceUtil.firstOrNull(myConvertedBuilds);
|
||||
return builds == null ? Collections.emptyList() : builds;
|
||||
}
|
||||
|
||||
|
||||
+19
-14
@@ -1,7 +1,9 @@
|
||||
// Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
|
||||
package com.intellij.gradle.toolingExtension.impl.util
|
||||
|
||||
import com.intellij.util.ExceptionUtilRt
|
||||
import io.opentelemetry.context.Context
|
||||
import org.jetbrains.plugins.gradle.tooling.Exceptions
|
||||
import java.util.concurrent.*
|
||||
import java.util.function.Function
|
||||
|
||||
@@ -20,7 +22,7 @@ object GradleExecutorServiceUtil {
|
||||
try {
|
||||
executorService.awaitTermination(Long.MAX_VALUE, TimeUnit.SECONDS)
|
||||
}
|
||||
catch (e: InterruptedException) {
|
||||
catch (_: InterruptedException) {
|
||||
Thread.currentThread().interrupt()
|
||||
}
|
||||
}
|
||||
@@ -41,28 +43,31 @@ object GradleExecutorServiceUtil {
|
||||
@JvmStatic
|
||||
fun <T> pollAllPendingResults(queue: BlockingQueue<Future<T>>): MutableList<T> {
|
||||
val results = ArrayList<T>()
|
||||
var result = poolPendingResult(queue)
|
||||
while (result != null) {
|
||||
results.add(result)
|
||||
result = poolPendingResult(queue)
|
||||
var next = drainEntry(queue)
|
||||
while (next != null) {
|
||||
next.onSuccess {
|
||||
results.add(it)
|
||||
}
|
||||
next = drainEntry(queue)
|
||||
}
|
||||
return results
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
fun <T> poolPendingResult(queue: BlockingQueue<Future<T>>): T? {
|
||||
try {
|
||||
fun <T> firstOrNull(queue: BlockingQueue<Future<T>>): T? = drainEntry(queue)?.getOrNull()
|
||||
|
||||
private fun <T> drainEntry(queue: BlockingQueue<Future<T>>): Result<T>? {
|
||||
return runCatching {
|
||||
val future = queue.poll()
|
||||
if (future == null) {
|
||||
return null
|
||||
}
|
||||
return future.get()
|
||||
}
|
||||
catch (ignored: InterruptedException) {
|
||||
return null
|
||||
}
|
||||
catch (ignored: ExecutionException) {
|
||||
return null
|
||||
return@runCatching future.get()
|
||||
}.onFailure {
|
||||
if (it is ExecutionException) {
|
||||
val exception = Exceptions.unwrap(it)
|
||||
System.err.println(ExceptionUtilRt.getThrowableText(exception, "org.jetbrains."))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user