-
Notifications
You must be signed in to change notification settings - Fork 119
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into #1201-add-type
- Loading branch information
Showing
1 changed file
with
14 additions
and
27 deletions.
There are no files selected for viewing
41 changes: 14 additions & 27 deletions
41
flank-scripts/src/main/kotlin/flank/scripts/testartifacts/core/ResolveArtifacts.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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") | ||
} |