From 425e6688302687d0bead2784e0909981fa16c90d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20G=C3=B3ral?= <60390247+jan-gogo@users.noreply.github.com> Date: Mon, 12 Oct 2020 16:19:57 +0200 Subject: [PATCH] Fix resolveArtifacts (#1232) --- .../testartifacts/core/ResolveArtifacts.kt | 41 +++++++------------ 1 file changed, 14 insertions(+), 27 deletions(-) diff --git a/flank-scripts/src/main/kotlin/flank/scripts/testartifacts/core/ResolveArtifacts.kt b/flank-scripts/src/main/kotlin/flank/scripts/testartifacts/core/ResolveArtifacts.kt index b8b11b3db2..579f890e38 100644 --- a/flank-scripts/src/main/kotlin/flank/scripts/testartifacts/core/ResolveArtifacts.kt +++ b/flank-scripts/src/main/kotlin/flank/scripts/testartifacts/core/ResolveArtifacts.kt @@ -1,38 +1,25 @@ package flank.scripts.testartifacts.core import com.jcabi.github.Repo -import java.io.File -fun Context.resolveArtifacts(repo: Repo = testArtifactsRepo()) { - resolveRemotelyOrFallback( - repo = repo, - fallback = { resolveFallback(repo) } - ) -} - -private fun Context.resolveRemotelyOrFallback(repo: Repo, fallback: () -> Unit) { +fun Context.resolveArtifacts( + repo: Repo = testArtifactsRepo() +) { if (isNewVersionAvailable(repo)) { downloadFixtures() unzipTestArtifacts() linkArtifacts() - } else fallback() -} - -private fun Context.resolveFallback(repo: Repo) { - projectRoot.testArtifacts(branch).run { + } else projectRoot.testArtifacts(branch).run { if (exists()) println("* Resolved test artifacts for branch $branch under $absolutePath") - else tryResolveForMaster(repo) + else copy(branch = "master").run { + if (isNewVersionAvailable(repo)) { + downloadFixtures() + unzipTestArtifacts() + linkArtifacts() + } else projectRoot.testArtifacts(branch).run { + if (exists()) println("* Resolved test artifacts for branch $branch under $absolutePath") + else throw Exception("Cannot resolve test artifacts") + } + } } } - -private fun Context.tryResolveForMaster(repo: Repo) { - copy(branch = "master").resolveRemotelyOrFallback( - repo = repo, - fallback = { projectRoot.testArtifacts(branch).resolveLocallyOrThrow(branch) } - ) -} - -private fun File.resolveLocallyOrThrow(branch: String) { - if (exists()) println("* Resolved test artifacts for branch $branch under $absolutePath") - else throw Exception("Cannot resolve test artifacts") -}