Last active
April 11, 2021 14:14
-
-
Save maxirosson/f4aab7a9ce7b21aabc104315550aafcb to your computer and use it in GitHub Desktop.
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
package com.dipien.gradle | |
import com.dipien.gradle.GradleProperty | |
import org.gradle.api.Project | |
class PropertyResolver(private val project: Project) { | |
fun getBooleanProp(gradleProperty: GradleProperty): Boolean { | |
return getBooleanProp(gradleProperty, gradleProperty.defaultValue as Boolean) | |
} | |
fun getBooleanProp(gradleProperty: GradleProperty, defaultValue: Boolean): Boolean { | |
val value = getProp(gradleProperty, null) | |
return if (value != null) { | |
when (value) { | |
"true" -> true | |
"false" -> false | |
else -> throw RuntimeException("The ${gradleProperty.name} gradle property value [$value] is not a valid boolean") | |
} | |
} else { | |
defaultValue | |
} | |
} | |
fun getProp(gradleProperty: GradleProperty, defaultValue: Any?): Any? { | |
return when { | |
project.hasProperty(gradleProperty.name) -> project.property(gradleProperty.name) | |
System.getenv().containsKey(gradleProperty.name) -> System.getenv(gradleProperty.name) | |
else -> defaultValue | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment