Cache PropertiesProvider, read the local.properties file lazily
Issue #KT-33980 Fixed
This commit is contained in:
+19
-8
@@ -42,14 +42,14 @@ internal fun PropertiesProvider.mapKotlinTaskProperties(task: AbstractKotlinComp
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
internal class PropertiesProvider(private val project: Project) {
|
internal class PropertiesProvider private constructor(private val project: Project) {
|
||||||
private val localProperties = Properties()
|
private val localProperties: Properties by lazy {
|
||||||
|
Properties().apply {
|
||||||
init {
|
val localPropertiesFile = project.rootProject.file("local.properties")
|
||||||
val localPropertiesFile = project.rootProject.file("local.properties")
|
if (localPropertiesFile.isFile) {
|
||||||
if (localPropertiesFile.isFile) {
|
localPropertiesFile.inputStream().use {
|
||||||
localPropertiesFile.inputStream().use {
|
load(it)
|
||||||
localProperties.load(it)
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -172,5 +172,16 @@ internal class PropertiesProvider(private val project: Project) {
|
|||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
internal const val KOTLIN_NATIVE_HOME = "kotlin.native.home"
|
internal const val KOTLIN_NATIVE_HOME = "kotlin.native.home"
|
||||||
|
|
||||||
|
private const val CACHED_PROVIDER_EXT_NAME = "kotlin.properties.provider"
|
||||||
|
|
||||||
|
operator fun invoke(project: Project): PropertiesProvider =
|
||||||
|
with(project.extensions.extraProperties) {
|
||||||
|
if (!has(CACHED_PROVIDER_EXT_NAME)) {
|
||||||
|
set(CACHED_PROVIDER_EXT_NAME, PropertiesProvider(project))
|
||||||
|
}
|
||||||
|
return get(CACHED_PROVIDER_EXT_NAME) as? PropertiesProvider
|
||||||
|
?: PropertiesProvider(project) // Fallback if multiple class loaders are involved
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user