Scripting, KT-61727: Make it possible to resolve multiple artifacts at once

For MavenDependenciesResolver it improves performance drastically
depending on how strong transitive dependencies of the roots interfere

^KT-61727 Fixed
This commit is contained in:
Ilya Muradyan
2023-09-01 01:30:33 +02:00
committed by Space Team
parent 0d628c9e59
commit 841cc8eb43
7 changed files with 153 additions and 45 deletions
@@ -308,3 +308,37 @@ fun <R> ResultWithDiagnostics<R>.valueOrThrow(): R = valueOr {
)
}
class IterableResultsCollector<T> {
private val diagnostics = mutableListOf<ScriptDiagnostic>()
private val values = mutableListOf<T>()
fun add(result: ResultWithDiagnostics<Iterable<T>>) {
diagnostics.addAll(result.reports)
if (result is ResultWithDiagnostics.Success) {
values.addAll(result.value)
}
}
fun addValue(value: T) {
values.add(value)
}
fun addDiagnostic(diagnostic: ScriptDiagnostic) {
diagnostics.add(diagnostic)
}
fun getResult(): ResultWithDiagnostics<List<T>> {
return if (values.isEmpty()) {
ResultWithDiagnostics.Failure(diagnostics)
} else {
ResultWithDiagnostics.Success(values, diagnostics)
}
}
}
fun <T> Iterable<ResultWithDiagnostics<Iterable<T>>>.asSuccessIfAny(): ResultWithDiagnostics<List<T>> {
return IterableResultsCollector<T>().run {
forEach { add(it) }
getResult()
}
}