All Downloads are FREE. Search and download functionalities are using the official Maven repository.

nebula.plugin.publishing.environment.kt Maven / Gradle / Ivy

The newest version!
package nebula.plugin.publishing

import org.gradle.api.Project
import org.gradle.api.provider.ProviderFactory

class EnvironmentReader(private val providerFactory: ProviderFactory) {
    fun findPropertyValue(project: Project,
                          envVariableName: String,
                          namespacedPropertyName: String,
                          propertyName: String
    ) : String? {
        val propertyValueFromEnv = readEnvVariable(envVariableName)
        return when {
            propertyValueFromEnv != null -> {
                propertyValueFromEnv
            }
            project.hasProperty(propertyName) -> {
                project.prop(propertyName)
            }
            project.hasProperty(namespacedPropertyName) -> {
                project.prop(namespacedPropertyName)
            }
            else -> null
        }
    }

    private fun readEnvVariable(envVariableName: String) : String? {
        val envVariable = providerFactory.environmentVariable(envVariableName)
        return if(envVariable.isPresent) envVariable.get() else null
    }

    private fun Project.prop(s: String): String? = project.findProperty(s) as String?
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy