From ef8cd58cfeb137255e24fea694d847495d68f885 Mon Sep 17 00:00:00 2001 From: Konstantin Tskhovrebov Date: Mon, 25 Mar 2024 16:53:46 +0100 Subject: [PATCH] [gradle] Temporary revert of gradle changes. Waiting a new dev version of the library --- .../compose/resources/GenerateResClassTask.kt | 20 ++++++-------- .../compose/resources/ResourcesSpec.kt | 4 +-- .../expected-open-res/Plurals0.kt | 26 ------------------- .../commonResources/expected-open-res/Res.kt | 2 -- .../misc/commonResources/expected/Plurals0.kt | 26 ------------------- .../misc/commonResources/expected/Res.kt | 2 -- .../composeResources/values/strings.xml | 10 ------- .../misc/emptyResources/expected/Res.kt | 2 -- .../misc/jvmOnlyResources/expected/Res.kt | 2 -- 9 files changed, 9 insertions(+), 85 deletions(-) delete mode 100644 gradle-plugins/compose/src/test/test-projects/misc/commonResources/expected-open-res/Plurals0.kt delete mode 100644 gradle-plugins/compose/src/test/test-projects/misc/commonResources/expected/Plurals0.kt diff --git a/gradle-plugins/compose/src/main/kotlin/org/jetbrains/compose/resources/GenerateResClassTask.kt b/gradle-plugins/compose/src/main/kotlin/org/jetbrains/compose/resources/GenerateResClassTask.kt index 5e7a234cd3..79410c0971 100644 --- a/gradle-plugins/compose/src/main/kotlin/org/jetbrains/compose/resources/GenerateResClassTask.kt +++ b/gradle-plugins/compose/src/main/kotlin/org/jetbrains/compose/resources/GenerateResClassTask.kt @@ -101,13 +101,9 @@ internal abstract class GenerateResClassTask : DefaultTask() { } if (typeString == "values" && file.name.equals("strings.xml", true)) { - return getStringResources(file).mapNotNull { (typeName, strId) -> - val type = when(typeName) { - "string", "string-array" -> ResourceType.STRING - "plurals" -> ResourceType.PLURAL_STRING - else -> return@mapNotNull null - } - ResourceItem(type, qualifiers, strId.asUnderscoredIdentifier(), path) + val stringIds = getStringIds(file) + return stringIds.map { strId -> + ResourceItem(ResourceType.STRING, qualifiers, strId.asUnderscoredIdentifier(), path) } } @@ -115,14 +111,14 @@ internal abstract class GenerateResClassTask : DefaultTask() { return listOf(ResourceItem(type, qualifiers, file.nameWithoutExtension.asUnderscoredIdentifier(), path)) } - //type -> id - private val stringTypeNames = listOf("string", "string-array", "plurals") - private fun getStringResources(stringsXml: File): List> { + private val stringTypeNames = listOf("string", "string-array") + private fun getStringIds(stringsXml: File): Set { val doc = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(stringsXml) val items = doc.getElementsByTagName("resources").item(0).childNodes - return List(items.length) { items.item(it) } + val ids = List(items.length) { items.item(it) } .filter { it.nodeName in stringTypeNames } - .map { it.nodeName to it.attributes.getNamedItem("name").nodeValue } + .map { it.attributes.getNamedItem("name").nodeValue } + return ids.toSet() } private fun File.listNotHiddenFiles(): List = diff --git a/gradle-plugins/compose/src/main/kotlin/org/jetbrains/compose/resources/ResourcesSpec.kt b/gradle-plugins/compose/src/main/kotlin/org/jetbrains/compose/resources/ResourcesSpec.kt index 87e2d38dbd..6064e1f8c1 100644 --- a/gradle-plugins/compose/src/main/kotlin/org/jetbrains/compose/resources/ResourcesSpec.kt +++ b/gradle-plugins/compose/src/main/kotlin/org/jetbrains/compose/resources/ResourcesSpec.kt @@ -9,7 +9,6 @@ import kotlin.io.path.invariantSeparatorsPathString internal enum class ResourceType(val typeName: String) { DRAWABLE("drawable"), STRING("string"), - PLURAL_STRING("plurals"), FONT("font"); override fun toString(): String = typeName @@ -32,7 +31,6 @@ internal data class ResourceItem( private fun ResourceType.getClassName(): ClassName = when (this) { ResourceType.DRAWABLE -> ClassName("org.jetbrains.compose.resources", "DrawableResource") ResourceType.STRING -> ClassName("org.jetbrains.compose.resources", "StringResource") - ResourceType.PLURAL_STRING -> ClassName("org.jetbrains.compose.resources", "PluralStringResource") ResourceType.FONT -> ClassName("org.jetbrains.compose.resources", "FontResource") } @@ -227,7 +225,7 @@ private fun getChunkFileSpec( CodeBlock.builder() .add("return %T(\n", type.getClassName()).withIndent { add("\"${type}:${resName}\",") - if (type == ResourceType.STRING || type == ResourceType.PLURAL_STRING) add(" \"$resName\",") + if (type == ResourceType.STRING) add(" \"$resName\",") withIndent { add("\nsetOf(\n").withIndent { items.forEach { item -> diff --git a/gradle-plugins/compose/src/test/test-projects/misc/commonResources/expected-open-res/Plurals0.kt b/gradle-plugins/compose/src/test/test-projects/misc/commonResources/expected-open-res/Plurals0.kt deleted file mode 100644 index 31cac7ea1f..0000000000 --- a/gradle-plugins/compose/src/test/test-projects/misc/commonResources/expected-open-res/Plurals0.kt +++ /dev/null @@ -1,26 +0,0 @@ -@file:OptIn(org.jetbrains.compose.resources.InternalResourceApi::class) - -package my.lib.res - -import kotlin.OptIn -import org.jetbrains.compose.resources.ExperimentalResourceApi -import org.jetbrains.compose.resources.PluralStringResource - -@ExperimentalResourceApi -private object Plurals0 { - public val numberOfSongsAvailable: PluralStringResource by - lazy { init_numberOfSongsAvailable() } -} - -@ExperimentalResourceApi -public val Res.plurals.numberOfSongsAvailable: PluralStringResource - get() = Plurals0.numberOfSongsAvailable - -@ExperimentalResourceApi -private fun init_numberOfSongsAvailable(): PluralStringResource = - org.jetbrains.compose.resources.PluralStringResource( - "plurals:numberOfSongsAvailable", "numberOfSongsAvailable", - setOf( - org.jetbrains.compose.resources.ResourceItem(setOf(), "values/strings.xml"), - ) - ) \ No newline at end of file diff --git a/gradle-plugins/compose/src/test/test-projects/misc/commonResources/expected-open-res/Res.kt b/gradle-plugins/compose/src/test/test-projects/misc/commonResources/expected-open-res/Res.kt index 4644d746fe..76964658a9 100644 --- a/gradle-plugins/compose/src/test/test-projects/misc/commonResources/expected-open-res/Res.kt +++ b/gradle-plugins/compose/src/test/test-projects/misc/commonResources/expected-open-res/Res.kt @@ -27,7 +27,5 @@ public object Res { public object string - public object plurals - public object font } diff --git a/gradle-plugins/compose/src/test/test-projects/misc/commonResources/expected/Plurals0.kt b/gradle-plugins/compose/src/test/test-projects/misc/commonResources/expected/Plurals0.kt deleted file mode 100644 index 81148dce1d..0000000000 --- a/gradle-plugins/compose/src/test/test-projects/misc/commonResources/expected/Plurals0.kt +++ /dev/null @@ -1,26 +0,0 @@ -@file:OptIn(org.jetbrains.compose.resources.InternalResourceApi::class) - -package app.group.resources_test.generated.resources - -import kotlin.OptIn -import org.jetbrains.compose.resources.ExperimentalResourceApi -import org.jetbrains.compose.resources.PluralStringResource - -@ExperimentalResourceApi -private object Plurals0 { - public val numberOfSongsAvailable: PluralStringResource by - lazy { init_numberOfSongsAvailable() } -} - -@ExperimentalResourceApi -internal val Res.plurals.numberOfSongsAvailable: PluralStringResource - get() = Plurals0.numberOfSongsAvailable - -@ExperimentalResourceApi -private fun init_numberOfSongsAvailable(): PluralStringResource = - org.jetbrains.compose.resources.PluralStringResource( - "plurals:numberOfSongsAvailable", "numberOfSongsAvailable", - setOf( - org.jetbrains.compose.resources.ResourceItem(setOf(), "values/strings.xml"), - ) - ) \ No newline at end of file diff --git a/gradle-plugins/compose/src/test/test-projects/misc/commonResources/expected/Res.kt b/gradle-plugins/compose/src/test/test-projects/misc/commonResources/expected/Res.kt index 416db64499..3bfdad8113 100644 --- a/gradle-plugins/compose/src/test/test-projects/misc/commonResources/expected/Res.kt +++ b/gradle-plugins/compose/src/test/test-projects/misc/commonResources/expected/Res.kt @@ -27,7 +27,5 @@ internal object Res { public object string - public object plurals - public object font } diff --git a/gradle-plugins/compose/src/test/test-projects/misc/commonResources/src/commonMain/composeResources/values/strings.xml b/gradle-plugins/compose/src/test/test-projects/misc/commonResources/src/commonMain/composeResources/values/strings.xml index 9e537278ba..6fa9a0966b 100644 --- a/gradle-plugins/compose/src/test/test-projects/misc/commonResources/src/commonMain/composeResources/values/strings.xml +++ b/gradle-plugins/compose/src/test/test-projects/misc/commonResources/src/commonMain/composeResources/values/strings.xml @@ -13,14 +13,4 @@ PascalCase 1-kebab-case camelCase - - - %d zero - %d one - %d two - %d few - %d many - %d other - - diff --git a/gradle-plugins/compose/src/test/test-projects/misc/emptyResources/expected/Res.kt b/gradle-plugins/compose/src/test/test-projects/misc/emptyResources/expected/Res.kt index 160bec3ba9..81038d418b 100644 --- a/gradle-plugins/compose/src/test/test-projects/misc/emptyResources/expected/Res.kt +++ b/gradle-plugins/compose/src/test/test-projects/misc/emptyResources/expected/Res.kt @@ -27,7 +27,5 @@ internal object Res { public object string - public object plurals - public object font } \ No newline at end of file diff --git a/gradle-plugins/compose/src/test/test-projects/misc/jvmOnlyResources/expected/Res.kt b/gradle-plugins/compose/src/test/test-projects/misc/jvmOnlyResources/expected/Res.kt index 21484d23c2..be1a2fe52a 100644 --- a/gradle-plugins/compose/src/test/test-projects/misc/jvmOnlyResources/expected/Res.kt +++ b/gradle-plugins/compose/src/test/test-projects/misc/jvmOnlyResources/expected/Res.kt @@ -27,7 +27,5 @@ internal object Res { public object string - public object plurals - public object font }