[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) 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( localProperties.writeText(
""" """
|${content.addSuffix("\n")} |${content.addSuffix("\n")}
@@ -75,17 +82,18 @@ private fun String.addSuffix(suffix: String): String {
return "$this$suffix" return "$this$suffix"
} }
internal data class PropertyValue( internal sealed class PropertyValue(
val value: String, 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 internal val Map<String, PropertyValue>.asPropertiesLines: String
get() = map { (key, value) -> get() = map { (key, valueWrapper) ->
when (value.isOverridden) { when (valueWrapper) {
true -> """ is PropertyValue.Overridden -> "#$key=${valueWrapper.value} the property is overridden by '${valueWrapper.overridingValue}'"
#$key=${value.value} the property is overridden is PropertyValue.Configured -> "$key=${valueWrapper.value}"
""".trimIndent()
false -> "$key=${value.value}"
} }
}.joinToString("\n") }.joinToString("\n")
@@ -87,8 +87,8 @@ class LocalPropertiesModifierTest {
@DisplayName("sync shouldn't remove any existing properties not managed by the sync") @DisplayName("sync shouldn't remove any existing properties not managed by the sync")
fun testSyncingIntoNonEmptyFile() { fun testSyncingIntoNonEmptyFile() {
val initialContent = mapOf( val initialContent = mapOf(
"oldProperty1" to PropertyValue("oldValue1"), "oldProperty1" to PropertyValue.Configured("oldValue1"),
"oldProperty2" to PropertyValue("oldValue2"), "oldProperty2" to PropertyValue.Configured("oldValue2"),
) )
fillInitialLocalPropertiesFile(initialContent) fillInitialLocalPropertiesFile(initialContent)
@@ -125,9 +125,9 @@ class LocalPropertiesModifierTest {
@DisplayName("sync shouldn't override properties if they already manually set") @DisplayName("sync shouldn't override properties if they already manually set")
fun testSyncingDoesNotOverrideValues() { fun testSyncingDoesNotOverrideValues() {
val initialContent = mapOf( val initialContent = mapOf(
"oldProperty1" to PropertyValue("oldValue1"), "oldProperty1" to PropertyValue.Configured("oldValue1"),
"oldProperty2" to PropertyValue("oldValue2"), "oldProperty2" to PropertyValue.Configured("oldValue2"),
"alreadySetProperty" to PropertyValue("oldValue3"), "alreadySetProperty" to PropertyValue.Configured("oldValue3"),
) )
fillInitialLocalPropertiesFile(initialContent) fillInitialLocalPropertiesFile(initialContent)
@@ -140,6 +140,7 @@ class LocalPropertiesModifierTest {
for ((key, value) in expectedProperties) { for ((key, value) in expectedProperties) {
assertEquals(value, properties[key]) 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") @DisplayName("sync should override automatically set properties")
fun testSyncingOverrideAutomaticallySetValues() { fun testSyncingOverrideAutomaticallySetValues() {
val initialContent = mapOf( val initialContent = mapOf(
"oldProperty1" to PropertyValue("oldValue1"), "oldProperty1" to PropertyValue.Configured("oldValue1"),
"oldProperty2" to PropertyValue("oldValue2"), "oldProperty2" to PropertyValue.Configured("oldValue2"),
"alreadySetProperty" to PropertyValue("oldValue3"), "alreadySetProperty" to PropertyValue.Configured("oldValue3"),
) )
fillInitialLocalPropertiesFile(initialContent) fillInitialLocalPropertiesFile(initialContent)
modifier.applySetup(setupFile) modifier.applySetup(setupFile)
val newProperties = mapOf( val newProperties = mapOf(
"newManualProperty" to PropertyValue("5"), "newManualProperty" to PropertyValue.Configured("5"),
"otherAlreadySetProperty" to PropertyValue("5"), "otherAlreadySetProperty" to PropertyValue.Configured("5"),
) )
fillInitialLocalPropertiesFile(newProperties) fillInitialLocalPropertiesFile(newProperties)