Last active
April 22, 2018 18:01
-
-
Save tomkoptel/bb7e1488de84bd6c36f71f836d0cf593 to your computer and use it in GitHub Desktop.
Helper functions that introduce some sugar DSL around TestVariant and ApkVariantOutput instances.
This file contains hidden or 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
/** | |
* Yields all available variants of type [TestVariant]. | |
*/ | |
internal fun DomainObjectCollection<out BaseVariant>.forEachTestVariant(block: (TestVariant) -> Unit) { | |
all { variant -> | |
when (variant) { | |
is ApplicationVariant -> variant.testVariant?.let(block) | |
is TestVariant -> block(variant) | |
is LibraryVariant -> variant.testVariant?.let(block) | |
} | |
} | |
} | |
/** | |
* Yields packaging output for the [TestVariant]. | |
*/ | |
internal fun TestVariant.forEachApkOutput(block: (ApkVariantOutput) -> Unit) { | |
outputs.all { output -> | |
if (output is ApkVariantOutput) { | |
block(output) | |
} else { | |
throw IllegalArgumentException("Unexpected output type for variant $name: ${output::class.java}") | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment