add config extension
This commit is contained in:
@@ -1,9 +1,11 @@
|
||||
package ltd.lulz.plugin
|
||||
|
||||
import ltd.lulz.plugin.extension.ConfigExtension
|
||||
import ltd.lulz.plugin.extension.GitExtension
|
||||
import ltd.lulz.plugin.extension.InfoExtension
|
||||
import org.gradle.api.Plugin
|
||||
import org.gradle.api.Project
|
||||
import ltd.lulz.plugin.extension.ConfigExtension.Companion.PLUGIN_NAME as CONFIG_PLUGIN_NAME
|
||||
import ltd.lulz.plugin.extension.GitExtension.Companion.PLUGIN_NAME as GIT_PLUGIN_NAME
|
||||
import ltd.lulz.plugin.extension.InfoExtension.Companion.PLUGIN_NAME as INFO_PLUGIN_NAME
|
||||
|
||||
@@ -18,8 +20,14 @@ class CorePlugin : Plugin<Project> {
|
||||
) {
|
||||
gitExtension(project)
|
||||
infoExtension(project)
|
||||
configExtension(project)
|
||||
}
|
||||
|
||||
private fun configExtension(
|
||||
project: Project,
|
||||
): ConfigExtension = project.extensions
|
||||
.create(CONFIG_PLUGIN_NAME, ConfigExtension::class.java, project)
|
||||
|
||||
private fun infoExtension(
|
||||
project: Project,
|
||||
): InfoExtension = project.extensions
|
||||
|
||||
31
src/main/kotlin/ltd/lulz/plugin/extension/ConfigExtension.kt
Normal file
31
src/main/kotlin/ltd/lulz/plugin/extension/ConfigExtension.kt
Normal file
@@ -0,0 +1,31 @@
|
||||
package ltd.lulz.plugin.extension
|
||||
|
||||
import java.lang.System.getenv
|
||||
import org.gradle.api.Project
|
||||
|
||||
abstract class ConfigExtension(private val project: Project) {
|
||||
|
||||
companion object {
|
||||
const val PLUGIN_NAME = "config"
|
||||
const val EMPTY = ""
|
||||
}
|
||||
|
||||
fun find(
|
||||
property: String,
|
||||
environment: String,
|
||||
): String? = findProperty(property) ?: findEnvironment(environment)
|
||||
|
||||
fun findOrDefault(
|
||||
property: String,
|
||||
environment: String,
|
||||
default: String = EMPTY,
|
||||
): String = findProperty(property) ?: findEnvironment(environment) ?: default
|
||||
|
||||
private fun findProperty(
|
||||
property: String,
|
||||
) = project.findProperty(property)?.toString()
|
||||
|
||||
private fun findEnvironment(
|
||||
environment: String,
|
||||
): String? = getenv(environment)
|
||||
}
|
||||
Reference in New Issue
Block a user