[Build, IGS] Specify the used value in the case of a property override

#KTI-1223 In Progress
This commit is contained in:
Alexander.Likhachev
2023-05-10 19:53:35 +02:00
committed by Space Team
parent cf03863b65
commit 2a634ead6f
2 changed files with 29 additions and 20 deletions
@@ -53,7 +53,14 @@ internal class LocalPropertiesModifier(private val localProperties: File) {
load(it)
}
}
val propertiesToSetup = setupFile.properties.mapValues { PropertyValue(it.value, manuallyConfiguredProperties.containsKey(it.key)) }
val propertiesToSetup = setupFile.properties.mapValues {
val overridingValue = manuallyConfiguredProperties[it.key]
if (overridingValue != null) {
PropertyValue.Overridden(it.value, overridingValue.toString())
} else {
PropertyValue.Configured(it.value)
}
}
localProperties.writeText(
"""
|${content.addSuffix("\n")}
@@ -75,17 +82,18 @@ private fun String.addSuffix(suffix: String): String {
return "$this$suffix"
}
internal data class PropertyValue(
internal sealed class PropertyValue(
val value: String,
val isOverridden: Boolean = false,
)
) {
class Configured(value: String) : PropertyValue(value)
class Overridden(value: String, val overridingValue: String) : PropertyValue(value)
}
internal val Map<String, PropertyValue>.asPropertiesLines: String
get() = map { (key, value) ->
when (value.isOverridden) {
true -> """
#$key=${value.value} the property is overridden
""".trimIndent()
false -> "$key=${value.value}"
get() = map { (key, valueWrapper) ->
when (valueWrapper) {
is PropertyValue.Overridden -> "#$key=${valueWrapper.value} the property is overridden by '${valueWrapper.overridingValue}'"
is PropertyValue.Configured -> "$key=${valueWrapper.value}"
}
}.joinToString("\n")
@@ -87,8 +87,8 @@ class LocalPropertiesModifierTest {
@DisplayName("sync shouldn't remove any existing properties not managed by the sync")
fun testSyncingIntoNonEmptyFile() {
val initialContent = mapOf(
"oldProperty1" to PropertyValue("oldValue1"),
"oldProperty2" to PropertyValue("oldValue2"),
"oldProperty1" to PropertyValue.Configured("oldValue1"),
"oldProperty2" to PropertyValue.Configured("oldValue2"),
)
fillInitialLocalPropertiesFile(initialContent)
@@ -125,9 +125,9 @@ class LocalPropertiesModifierTest {
@DisplayName("sync shouldn't override properties if they already manually set")
fun testSyncingDoesNotOverrideValues() {
val initialContent = mapOf(
"oldProperty1" to PropertyValue("oldValue1"),
"oldProperty2" to PropertyValue("oldValue2"),
"alreadySetProperty" to PropertyValue("oldValue3"),
"oldProperty1" to PropertyValue.Configured("oldValue1"),
"oldProperty2" to PropertyValue.Configured("oldValue2"),
"alreadySetProperty" to PropertyValue.Configured("oldValue3"),
)
fillInitialLocalPropertiesFile(initialContent)
@@ -140,6 +140,7 @@ class LocalPropertiesModifierTest {
for ((key, value) in expectedProperties) {
assertEquals(value, properties[key])
}
assertContainsExactTimes(fileContents, "#alreadySetProperty=newValue the property is overridden by 'oldValue3'", 1)
}
}
@@ -169,17 +170,17 @@ class LocalPropertiesModifierTest {
@DisplayName("sync should override automatically set properties")
fun testSyncingOverrideAutomaticallySetValues() {
val initialContent = mapOf(
"oldProperty1" to PropertyValue("oldValue1"),
"oldProperty2" to PropertyValue("oldValue2"),
"alreadySetProperty" to PropertyValue("oldValue3"),
"oldProperty1" to PropertyValue.Configured("oldValue1"),
"oldProperty2" to PropertyValue.Configured("oldValue2"),
"alreadySetProperty" to PropertyValue.Configured("oldValue3"),
)
fillInitialLocalPropertiesFile(initialContent)
modifier.applySetup(setupFile)
val newProperties = mapOf(
"newManualProperty" to PropertyValue("5"),
"otherAlreadySetProperty" to PropertyValue("5"),
"newManualProperty" to PropertyValue.Configured("5"),
"otherAlreadySetProperty" to PropertyValue.Configured("5"),
)
fillInitialLocalPropertiesFile(newProperties)