Skip to content

Commit 8ba7ac7

Browse files
terrakokKpotko
authored andcommitted
Fix code generation for the customized Res class name. (#5311)
## Release Notes N/A (cherry picked from commit 23c481b)
1 parent 7eca24b commit 8ba7ac7

File tree

9 files changed

+38
-19
lines changed

9 files changed

+38
-19
lines changed

gradle-plugins/compose/src/main/kotlin/org/jetbrains/compose/resources/ComposeResourcesGeneration.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ private fun Project.configureResClassGeneration(
101101
packagingDir: Provider<File>,
102102
generateModulePath: Boolean
103103
) {
104-
logger.info("Configure Res class generation for ${resClassSourceSet.name}")
104+
logger.info("Configure '$resClassName' class generation for ${resClassSourceSet.name}")
105105

106106
val genTask = tasks.register(
107107
"generateComposeResClass",

gradle-plugins/compose/src/main/kotlin/org/jetbrains/compose/resources/GeneratedResClassSpec.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -301,7 +301,7 @@ private fun getChunkFileSpec(
301301
)
302302
.also { collectFun ->
303303
idToResources.keys.forEach { resName ->
304-
collectFun.addStatement("map.put(%S, %N.%N.%N)", resName, "Res", type.accessorName, resName)
304+
collectFun.addStatement("map.put(%S, %N.%N.%N)", resName, resClassName, type.accessorName, resName)
305305
}
306306
}
307307
.build()

gradle-plugins/compose/src/test/kotlin/org/jetbrains/compose/test/tests/integration/ResourcesTest.kt

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -387,6 +387,25 @@ class ResourcesTest : GradlePluginTestBase() {
387387
}
388388
}
389389

390+
391+
@Test
392+
fun testJvmBuildWithResourcesCustomization(): Unit = with(testProject("misc/commonResources")) {
393+
file("build.gradle.kts").appendText(
394+
"""
395+
compose.resources {
396+
publicResClass = true
397+
packageOfResClass = "io.customized"
398+
nameOfResClass = "CustomName"
399+
}
400+
""".trimIndent()
401+
)
402+
file("src/commonMain/kotlin").deleteRecursively() //empty project
403+
404+
gradle("desktopJar").checks {
405+
check.logContains("Generate CustomName.kt")
406+
}
407+
}
408+
390409
@Test
391410
fun testFinalArtefacts(): Unit = with(testProject("misc/commonResources")) {
392411
//https://developer.android.com/build/build-variants?utm_source=android-studio#product-flavors

gradle-plugins/compose/src/test/test-projects/misc/commonResources/expected-open-res/androidMainResourceAccessors/my/lib/res/String0.androidMain.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,5 +19,5 @@ public val MyRes.string.android_str: StringResource by lazy {
1919

2020
@InternalResourceApi
2121
internal fun _collectAndroidMainString0Resources(map: MutableMap<String, StringResource>) {
22-
map.put("android_str", Res.string.android_str)
22+
map.put("android_str", MyRes.string.android_str)
2323
}

gradle-plugins/compose/src/test/test-projects/misc/commonResources/expected-open-res/commonMainResourceAccessors/my/lib/res/Drawable0.commonMain.kt

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,9 @@ public val MyRes.drawable.vector_2: DrawableResource by lazy {
5050

5151
@InternalResourceApi
5252
internal fun _collectCommonMainDrawable0Resources(map: MutableMap<String, DrawableResource>) {
53-
map.put("_3_strange_name", Res.drawable._3_strange_name)
54-
map.put("camelCaseName", Res.drawable.camelCaseName)
55-
map.put("is", Res.drawable.`is`)
56-
map.put("vector", Res.drawable.vector)
57-
map.put("vector_2", Res.drawable.vector_2)
53+
map.put("_3_strange_name", MyRes.drawable._3_strange_name)
54+
map.put("camelCaseName", MyRes.drawable.camelCaseName)
55+
map.put("is", MyRes.drawable.`is`)
56+
map.put("vector", MyRes.drawable.vector)
57+
map.put("vector_2", MyRes.drawable.vector_2)
5858
}

gradle-plugins/compose/src/test/test-projects/misc/commonResources/expected-open-res/commonMainResourceAccessors/my/lib/res/Font0.commonMain.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,5 +21,5 @@ public val MyRes.font.emptyFont: FontResource by lazy {
2121

2222
@InternalResourceApi
2323
internal fun _collectCommonMainFont0Resources(map: MutableMap<String, FontResource>) {
24-
map.put("emptyFont", Res.font.emptyFont)
24+
map.put("emptyFont", MyRes.font.emptyFont)
2525
}

gradle-plugins/compose/src/test/test-projects/misc/commonResources/expected-open-res/commonMainResourceAccessors/my/lib/res/Plurals0.commonMain.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,5 +19,5 @@ public val MyRes.plurals.numberOfSongsAvailable: PluralStringResource by lazy {
1919

2020
@InternalResourceApi
2121
internal fun _collectCommonMainPlurals0Resources(map: MutableMap<String, PluralStringResource>) {
22-
map.put("numberOfSongsAvailable", Res.plurals.numberOfSongsAvailable)
22+
map.put("numberOfSongsAvailable", MyRes.plurals.numberOfSongsAvailable)
2323
}

gradle-plugins/compose/src/test/test-projects/misc/commonResources/expected-open-res/commonMainResourceAccessors/my/lib/res/String0.commonMain.kt

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -61,12 +61,12 @@ public val MyRes.string.str_template: StringResource by lazy {
6161

6262
@InternalResourceApi
6363
internal fun _collectCommonMainString0Resources(map: MutableMap<String, StringResource>) {
64-
map.put("PascalCase", Res.string.PascalCase)
65-
map.put("_1_kebab_case", Res.string._1_kebab_case)
66-
map.put("app_name", Res.string.app_name)
67-
map.put("camelCase", Res.string.camelCase)
68-
map.put("hello", Res.string.hello)
69-
map.put("info_using_release_${'$'}x", Res.string.`info_using_release_$x`)
70-
map.put("multi_line", Res.string.multi_line)
71-
map.put("str_template", Res.string.str_template)
64+
map.put("PascalCase", MyRes.string.PascalCase)
65+
map.put("_1_kebab_case", MyRes.string._1_kebab_case)
66+
map.put("app_name", MyRes.string.app_name)
67+
map.put("camelCase", MyRes.string.camelCase)
68+
map.put("hello", MyRes.string.hello)
69+
map.put("info_using_release_${'$'}x", MyRes.string.`info_using_release_$x`)
70+
map.put("multi_line", MyRes.string.multi_line)
71+
map.put("str_template", MyRes.string.str_template)
7272
}

gradle-plugins/compose/src/test/test-projects/misc/commonResources/expected-open-res/desktopMainResourceAccessors/my/lib/res/String0.desktopMain.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,5 +19,5 @@ public val MyRes.string.desktop_str: StringResource by lazy {
1919

2020
@InternalResourceApi
2121
internal fun _collectDesktopMainString0Resources(map: MutableMap<String, StringResource>) {
22-
map.put("desktop_str", Res.string.desktop_str)
22+
map.put("desktop_str", MyRes.string.desktop_str)
2323
}

0 commit comments

Comments
 (0)