Skip to content

Commit 4fc4d1e

Browse files
committed
Property value toBooleanStrict
1 parent a647688 commit 4fc4d1e

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

atomicfu-gradle-plugin/src/main/kotlin/kotlinx/atomicfu/plugin/gradle/AtomicFUGradlePlugin.kt

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ open class AtomicFUGradlePlugin : Plugin<Project> {
3434
val pluginVersion = rootProject.buildscript.configurations.findByName("classpath")
3535
?.allDependencies?.find { it.name == "atomicfu-gradle-plugin" }?.version
3636
extensions.add(EXTENSION_NAME, AtomicFUPluginExtension(pluginVersion))
37-
if (rootProject.findProperty(ENABLE_IR_TRANSFORMATION).toString().toBoolean()) {
37+
if (rootProject.getBooleanProperty(ENABLE_IR_TRANSFORMATION)) {
3838
plugins.apply(AtomicfuKotlinGradleSubplugin::class.java)
3939
}
4040
configureDependencies()
@@ -86,6 +86,15 @@ private fun Project.configureTasks() {
8686
}
8787
}
8888

89+
private fun Project.getBooleanProperty(name: String) =
90+
rootProject.findProperty(name)?.toString()?.toBooleanStrict() ?: false
91+
92+
private fun String.toBooleanStrict(): Boolean = when (this) {
93+
"true" -> true
94+
"false" -> false
95+
else -> throw IllegalArgumentException("The string doesn't represent a boolean value: $this")
96+
}
97+
8998
private fun Project.needsJsIrTransformation(target: KotlinTarget): Boolean =
9099
config.transformJs && target.isJsIrTarget()
91100

@@ -264,7 +273,7 @@ fun Project.sourceSetsByCompilation(): Map<KotlinSourceSet, List<KotlinCompilati
264273
}
265274

266275
fun Project.configureMultiplatformPluginDependencies(version: String) {
267-
if (rootProject.findProperty("kotlin.mpp.enableGranularSourceSetsMetadata").toString().toBoolean()) {
276+
if (rootProject.getBooleanProperty("kotlin.mpp.enableGranularSourceSetsMetadata")) {
268277
addCompilerPluginDependency()
269278
val mainConfigurationName = project.extensions.getByType(KotlinMultiplatformExtension::class.java).sourceSets
270279
.getByName(KotlinSourceSet.COMMON_MAIN_SOURCE_SET_NAME)

0 commit comments

Comments
 (0)