From d6b8681b22b24c8ac2f79db7199e09bf8873a577 Mon Sep 17 00:00:00 2001 From: Konstantin Date: Wed, 7 Feb 2024 14:58:51 +0100 Subject: [PATCH] Don't make resource IDs lowercased (#4253) --- .../compose/resources/demo/shared/FontRes.kt | 2 +- .../compose/resources/GenerateResClassTask.kt | 3 +- .../compose/resources/ResourcesGenerator.kt | 2 +- .../misc/commonResources/expected/Res.kt | 45 +++++++++++++++++-- .../drawable/camelCaseName.xml | 36 +++++++++++++++ .../composeResources/values/strings.xml | 3 ++ .../src/commonMain/kotlin/App.kt | 2 +- 7 files changed, 85 insertions(+), 8 deletions(-) create mode 100644 gradle-plugins/compose/src/test/test-projects/misc/commonResources/src/commonMain/composeResources/drawable/camelCaseName.xml diff --git a/components/resources/demo/shared/src/commonMain/kotlin/org/jetbrains/compose/resources/demo/shared/FontRes.kt b/components/resources/demo/shared/src/commonMain/kotlin/org/jetbrains/compose/resources/demo/shared/FontRes.kt index c2a3e4551a..49d39b7a19 100644 --- a/components/resources/demo/shared/src/commonMain/kotlin/org/jetbrains/compose/resources/demo/shared/FontRes.kt +++ b/components/resources/demo/shared/src/commonMain/kotlin/org/jetbrains/compose/resources/demo/shared/FontRes.kt @@ -42,7 +42,7 @@ fun FontRes(paddingValues: PaddingValues) { } Text( modifier = Modifier.padding(16.dp), - fontFamily = FontFamily(Font(Res.font.workbench_regular)), + fontFamily = FontFamily(Font(Res.font.Workbench_Regular)), style = MaterialTheme.typography.headlineLarge, text = "brown fox jumps over the lazy dog" ) 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 130e2a9d71..b3d19ef68f 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 @@ -106,6 +106,5 @@ abstract class GenerateResClassTask : DefaultTask() { } internal fun String.asUnderscoredIdentifier(): String = - lowercase() - .replace('-', '_') + replace('-', '_') .let { if (it.isNotEmpty() && it.first().isDigit()) "_$it" else it } \ No newline at end of file diff --git a/gradle-plugins/compose/src/main/kotlin/org/jetbrains/compose/resources/ResourcesGenerator.kt b/gradle-plugins/compose/src/main/kotlin/org/jetbrains/compose/resources/ResourcesGenerator.kt index b84193f8d4..b0cb6ae8a8 100644 --- a/gradle-plugins/compose/src/main/kotlin/org/jetbrains/compose/resources/ResourcesGenerator.kt +++ b/gradle-plugins/compose/src/main/kotlin/org/jetbrains/compose/resources/ResourcesGenerator.kt @@ -43,7 +43,7 @@ private fun Project.configureResourceGenerator(commonComposeResourcesDir: File, val commonComposeResources = provider { commonComposeResourcesDir } val packageName = provider { buildString { - val group = project.group.toString().asUnderscoredIdentifier() + val group = project.group.toString().lowercase().asUnderscoredIdentifier() append(group) if (group.isNotEmpty()) append(".") append(project.name.lowercase()) 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 b173c6bc2a..7b3a1c23b0 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 @@ -29,14 +29,22 @@ internal object Res { public object drawable { public val _3_strange_name: DrawableResource = get_drawable__3_strange_name() + public val camelCaseName: DrawableResource = get_drawable_camelCaseName() + public val vector: DrawableResource = get_drawable_vector() public val vector_2: DrawableResource = get_drawable_vector_2() } public object string { + public val PascalCase: StringResource = get_string_PascalCase() + + public val _1_kebab_case: StringResource = get_string__1_kebab_case() + public val app_name: StringResource = get_string_app_name() + public val camelCase: StringResource = get_string_camelCase() + public val hello: StringResource = get_string_hello() public val multi_line: StringResource = get_string_multi_line() @@ -47,7 +55,7 @@ internal object Res { } public object font { - public val emptyfont: FontResource = get_font_emptyfont() + public val emptyFont: FontResource = get_font_emptyFont() } } @@ -59,6 +67,14 @@ private fun get_drawable__3_strange_name(): DrawableResource = ) ) +private fun get_drawable_camelCaseName(): DrawableResource = + org.jetbrains.compose.resources.DrawableResource( + "drawable:camelCaseName", + setOf( + org.jetbrains.compose.resources.ResourceItem(setOf(), "drawable/camelCaseName.xml"), + ) + ) + private fun get_drawable_vector(): DrawableResource = org.jetbrains.compose.resources.DrawableResource( "drawable:vector", @@ -84,6 +100,22 @@ private fun get_drawable_vector_2(): DrawableResource = ) ) +private fun get_string_PascalCase(): StringResource = + org.jetbrains.compose.resources.StringResource( + "string:PascalCase", "PascalCase", + setOf( + org.jetbrains.compose.resources.ResourceItem(setOf(), "values/strings.xml"), + ) + ) + +private fun get_string__1_kebab_case(): StringResource = + org.jetbrains.compose.resources.StringResource( + "string:_1_kebab_case", "_1_kebab_case", + setOf( + org.jetbrains.compose.resources.ResourceItem(setOf(), "values/strings.xml"), + ) + ) + private fun get_string_app_name(): StringResource = org.jetbrains.compose.resources.StringResource( "string:app_name", "app_name", setOf( @@ -91,6 +123,13 @@ private fun get_string_app_name(): StringResource = org.jetbrains.compose.resour ) ) +private fun get_string_camelCase(): StringResource = org.jetbrains.compose.resources.StringResource( + "string:camelCase", "camelCase", + setOf( + org.jetbrains.compose.resources.ResourceItem(setOf(), "values/strings.xml"), + ) +) + private fun get_string_hello(): StringResource = org.jetbrains.compose.resources.StringResource( "string:hello", "hello", setOf( @@ -121,8 +160,8 @@ private fun get_string_str_template(): StringResource = ) ) -private fun get_font_emptyfont(): FontResource = org.jetbrains.compose.resources.FontResource( - "font:emptyfont", +private fun get_font_emptyFont(): FontResource = org.jetbrains.compose.resources.FontResource( + "font:emptyFont", setOf( org.jetbrains.compose.resources.ResourceItem(setOf(), "font/emptyFont.otf"), ) diff --git a/gradle-plugins/compose/src/test/test-projects/misc/commonResources/src/commonMain/composeResources/drawable/camelCaseName.xml b/gradle-plugins/compose/src/test/test-projects/misc/commonResources/src/commonMain/composeResources/drawable/camelCaseName.xml new file mode 100644 index 0000000000..d7bf7955f4 --- /dev/null +++ b/gradle-plugins/compose/src/test/test-projects/misc/commonResources/src/commonMain/composeResources/drawable/camelCaseName.xml @@ -0,0 +1,36 @@ + + + + + + + + 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 bdfed65b61..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 @@ -10,4 +10,7 @@ item 2 item 3 + PascalCase + 1-kebab-case + camelCase diff --git a/gradle-plugins/compose/src/test/test-projects/misc/commonResources/src/commonMain/kotlin/App.kt b/gradle-plugins/compose/src/test/test-projects/misc/commonResources/src/commonMain/kotlin/App.kt index 376fe108ba..0f463fd122 100644 --- a/gradle-plugins/compose/src/test/test-projects/misc/commonResources/src/commonMain/kotlin/App.kt +++ b/gradle-plugins/compose/src/test/test-projects/misc/commonResources/src/commonMain/kotlin/App.kt @@ -18,6 +18,6 @@ fun App() { contentDescription = null ) Text(stringResource(Res.string.app_name)) - val font = FontFamily(Font(Res.font.emptyfont)) + val font = FontFamily(Font(Res.font.emptyFont)) } }