From e0e317a0964f3d936e0154a0bd9b52aeee7bc295 Mon Sep 17 00:00:00 2001 From: Maxime MICHEL Date: Wed, 28 Aug 2024 13:23:31 +0200 Subject: [PATCH 1/2] :bug: Fix available symbol for version catalog On some fonts, the arrow symbol was only 1 character wide instead of 2. Using a classic character negates this issue --- .../core/internal/VersionsCatalogUpdater.kt | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/plugins/core/src/main/kotlin/de/fayard/refreshVersions/core/internal/VersionsCatalogUpdater.kt b/plugins/core/src/main/kotlin/de/fayard/refreshVersions/core/internal/VersionsCatalogUpdater.kt index 444cecd8d..802cfaadd 100644 --- a/plugins/core/src/main/kotlin/de/fayard/refreshVersions/core/internal/VersionsCatalogUpdater.kt +++ b/plugins/core/src/main/kotlin/de/fayard/refreshVersions/core/internal/VersionsCatalogUpdater.kt @@ -40,6 +40,7 @@ internal class VersionsCatalogUpdater( Version -> { linesForUpdates(line, findLineReferencing(line)) } + Libs, Plugin -> { val updates = dependenciesUpdates.firstOrNull { it.moduleId.name == line.name && it.moduleId.group == line.group @@ -71,7 +72,7 @@ internal class VersionsCatalogUpdater( val isObject = initialLine.unparsedValue.endsWith("}") val commentPrefix = "##" - val availableSymbol = "⬆" + val availableSymbol = "^" val versionPrefix = when { isObject || initialLine.section == TomlSection.Versions -> """= """" else -> """:""" @@ -86,14 +87,13 @@ internal class VersionsCatalogUpdater( yield(commentPrefix) yield(availableSymbol) yield(versionPrefix) - }.sumOf { it.length }.let { - it + 1 // Because the length of availableSymbol (⬆) is 1, but it takes the width of 2 chars in the IDE. - }.let { - val indexOfCurrentVersion = initialLine.text.indexOf(currentVersion) - val gap = indexOfCurrentVersion - it - leadingSpace = " ".repeat((gap - 1).coerceAtLeast(0)) - trailingSpace = if (gap > 0 && versionPrefix.endsWith(' ').not()) " " else "" - } + }.sumOf { it.length } + .let { + val indexOfCurrentVersion = initialLine.text.indexOf(currentVersion) + val gap = indexOfCurrentVersion - it + leadingSpace = " ".repeat((gap - 1).coerceAtLeast(0)) + trailingSpace = if (gap > 0 && versionPrefix.endsWith(' ').not()) " " else "" + } return availableUpdates.mapTo(mutableListOf(initialLine)) { versionCandidate: MavenVersion -> val version = versionCandidate.value TomlLine( From f13d3c212a4cff9ab745e437362bb7791b7304ac Mon Sep 17 00:00:00 2001 From: Maxime MICHEL Date: Wed, 28 Aug 2024 13:28:53 +0200 Subject: [PATCH 2/2] :bug: Fix VersionCatalog section ordering The sections are now ordered as described in the gradle documentation: https://docs.gradle.org/current/userguide/platforms.html#sub::toml-dependencies-format --- .../de/fayard/refreshVersions/core/internal/TomlSection.kt | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/plugins/core/src/main/kotlin/de/fayard/refreshVersions/core/internal/TomlSection.kt b/plugins/core/src/main/kotlin/de/fayard/refreshVersions/core/internal/TomlSection.kt index be2563920..6fb0bc1dd 100644 --- a/plugins/core/src/main/kotlin/de/fayard/refreshVersions/core/internal/TomlSection.kt +++ b/plugins/core/src/main/kotlin/de/fayard/refreshVersions/core/internal/TomlSection.kt @@ -6,13 +6,13 @@ internal sealed class TomlSection(open val name: String) { object Root: TomlSection("root") object Versions: TomlSection("versions") - object Plugins: TomlSection("plugins") - object Bundles: TomlSection("bundles") object Libraries: TomlSection("libraries") + object Bundles: TomlSection("bundles") + object Plugins: TomlSection("plugins") data class Custom(override val name: String) : TomlSection(name) companion object { - val orderedSections = listOf(Root, Bundles, Plugins, Versions, Libraries) + val orderedSections = listOf(Root, Versions, Libraries, Bundles, Plugins) fun from(name: String): TomlSection = orderedSections.firstOrNull { it.name == name } ?: Custom(name) }