Skip to content

Commit

Permalink
[gradle] Allow to have equal named xml values files in different sour…
Browse files Browse the repository at this point in the history
…ce sets for the same target

All strings.xml will be packed in the same directory. Hence, we need to add an original source set name to the converted CVR file.
  • Loading branch information
terrakok committed Apr 8, 2024
1 parent 54277ba commit 645256f
Show file tree
Hide file tree
Showing 11 changed files with 50 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ internal fun Project.registerPrepareComposeResourcesTask(
"convertXmlValueResourcesFor${sourceSet.name.uppercaseFirstChar()}",
XmlValuesConverterTask::class.java
) { task ->
task.fileSuffix.set(sourceSet.name)
task.originalResourcesDir.set(userComposeResourcesDir)
task.outputDir.set(preparedComposeResourcesDir)
}
Expand Down Expand Up @@ -137,6 +138,9 @@ internal abstract class XmlValuesConverterTask : DefaultTask() {
private const val FORMAT_VERSION = 0
}

@get:Input
abstract val fileSuffix: Property<String>

@get:Internal
abstract val originalResourcesDir: DirectoryProperty

Expand All @@ -151,20 +155,22 @@ internal abstract class XmlValuesConverterTask : DefaultTask() {

@get:OutputFiles
val realOutputFiles = outputDir.map { dir ->
dir.asFileTree.matching { it.include("values*/*.$CONVERTED_RESOURCE_EXT") }
val suffix = fileSuffix.get()
dir.asFileTree.matching { it.include("values*/*.$suffix.$CONVERTED_RESOURCE_EXT") }
}

@TaskAction
fun run() {
val outDir = outputDir.get().asFile
val suffix = fileSuffix.get()
realOutputFiles.get().forEach { f -> f.delete() }
originalResourcesDir.get().asFile.listNotHiddenFiles().forEach { valuesDir ->
if (valuesDir.isDirectory && valuesDir.name.startsWith("values")) {
valuesDir.listNotHiddenFiles().forEach { f ->
if (f.extension.equals("xml", true)) {
val output = outDir
.resolve(f.parentFile.name)
.resolve(f.nameWithoutExtension + ".$CONVERTED_RESOURCE_EXT")
.resolve(f.nameWithoutExtension + ".$suffix.$CONVERTED_RESOURCE_EXT")
output.parentFile.mkdirs()
convert(f, output)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -382,7 +382,8 @@ class ResourcesTest : GradlePluginTestBase() {
file.parentFile.name.startsWith("value") &&
file.extension.equals("xml", true)
) {
file.parentFile.resolve(file.nameWithoutExtension + "." + XmlValuesConverterTask.CONVERTED_RESOURCE_EXT)
val cvrSuffix = file.parentFile.parentFile.parentFile.name
file.parentFile.resolve("${file.nameWithoutExtension}.$cvrSuffix.${XmlValuesConverterTask.CONVERTED_RESOURCE_EXT}")
} else {
file
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ public val Res.string.android_str: StringResource
private fun init_android_str(): StringResource = org.jetbrains.compose.resources.StringResource(
"string:android_str", "android_str",
setOf(
org.jetbrains.compose.resources.ResourceItem(setOf(), "values/android_strings.cvr", 10, 39),
org.jetbrains.compose.resources.ResourceItem(setOf(), "values/strings.androidMain.cvr", 10,
39),
)
)
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ private fun init_numberOfSongsAvailable(): PluralStringResource =
org.jetbrains.compose.resources.PluralStringResource(
"plurals:numberOfSongsAvailable", "numberOfSongsAvailable",
setOf(
org.jetbrains.compose.resources.ResourceItem(setOf(), "values/strings.cvr", 10, 124),
org.jetbrains.compose.resources.ResourceItem(setOf(), "values/strings.commonMain.cvr", 10,
124),
)
)
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ public val Res.string.PascalCase: StringResource
private fun init_PascalCase(): StringResource = org.jetbrains.compose.resources.StringResource(
"string:PascalCase", "PascalCase",
setOf(
org.jetbrains.compose.resources.ResourceItem(setOf(), "values/strings.cvr", 172, 34),
org.jetbrains.compose.resources.ResourceItem(setOf(), "values/strings.commonMain.cvr", 172,
34),
)
)

Expand All @@ -50,7 +51,8 @@ public val Res.string._1_kebab_case: StringResource
private fun init__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.cvr", 135, 36),
org.jetbrains.compose.resources.ResourceItem(setOf(), "values/strings.commonMain.cvr", 135,
36),
)
)

Expand All @@ -62,7 +64,8 @@ public val Res.string.app_name: StringResource
private fun init_app_name(): StringResource = org.jetbrains.compose.resources.StringResource(
"string:app_name", "app_name",
setOf(
org.jetbrains.compose.resources.ResourceItem(setOf(), "values/strings.cvr", 207, 44),
org.jetbrains.compose.resources.ResourceItem(setOf(), "values/strings.commonMain.cvr", 207,
44),
)
)

Expand All @@ -74,7 +77,8 @@ public val Res.string.camelCase: StringResource
private fun init_camelCase(): StringResource = org.jetbrains.compose.resources.StringResource(
"string:camelCase", "camelCase",
setOf(
org.jetbrains.compose.resources.ResourceItem(setOf(), "values/strings.cvr", 252, 29),
org.jetbrains.compose.resources.ResourceItem(setOf(), "values/strings.commonMain.cvr", 252,
29),
)
)

Expand All @@ -86,7 +90,8 @@ public val Res.string.hello: StringResource
private fun init_hello(): StringResource = org.jetbrains.compose.resources.StringResource(
"string:hello", "hello",
setOf(
org.jetbrains.compose.resources.ResourceItem(setOf(), "values/strings.cvr", 282, 37),
org.jetbrains.compose.resources.ResourceItem(setOf(), "values/strings.commonMain.cvr", 282,
37),
)
)

Expand All @@ -98,7 +103,8 @@ public val Res.string.multi_line: StringResource
private fun init_multi_line(): StringResource = org.jetbrains.compose.resources.StringResource(
"string:multi_line", "multi_line",
setOf(
org.jetbrains.compose.resources.ResourceItem(setOf(), "values/strings.cvr", 320, 178),
org.jetbrains.compose.resources.ResourceItem(setOf(), "values/strings.commonMain.cvr", 320,
178),
)
)

Expand All @@ -110,6 +116,7 @@ public val Res.string.str_template: StringResource
private fun init_str_template(): StringResource = org.jetbrains.compose.resources.StringResource(
"string:str_template", "str_template",
setOf(
org.jetbrains.compose.resources.ResourceItem(setOf(), "values/strings.cvr", 499, 76),
org.jetbrains.compose.resources.ResourceItem(setOf(), "values/strings.commonMain.cvr", 499,
76),
)
)
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ public val Res.string.desktop_str: StringResource
private fun init_desktop_str(): StringResource = org.jetbrains.compose.resources.StringResource(
"string:desktop_str", "desktop_str",
setOf(
org.jetbrains.compose.resources.ResourceItem(setOf(), "values/desktop_strings.cvr", 10, 39),
org.jetbrains.compose.resources.ResourceItem(setOf(),
"values/desktop_strings.desktopMain.cvr", 10, 39),
)
)
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ internal val Res.string.android_str: StringResource
private fun init_android_str(): StringResource = org.jetbrains.compose.resources.StringResource(
"string:android_str", "android_str",
setOf(
org.jetbrains.compose.resources.ResourceItem(setOf(), "values/android_strings.cvr", 10, 39),
org.jetbrains.compose.resources.ResourceItem(setOf(), "values/strings.androidMain.cvr", 10,
39),
)
)
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ private fun init_numberOfSongsAvailable(): PluralStringResource =
org.jetbrains.compose.resources.PluralStringResource(
"plurals:numberOfSongsAvailable", "numberOfSongsAvailable",
setOf(
org.jetbrains.compose.resources.ResourceItem(setOf(), "values/strings.cvr", 10, 124),
org.jetbrains.compose.resources.ResourceItem(setOf(), "values/strings.commonMain.cvr", 10,
124),
)
)
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ internal val Res.string.PascalCase: StringResource
private fun init_PascalCase(): StringResource = org.jetbrains.compose.resources.StringResource(
"string:PascalCase", "PascalCase",
setOf(
org.jetbrains.compose.resources.ResourceItem(setOf(), "values/strings.cvr", 172, 34),
org.jetbrains.compose.resources.ResourceItem(setOf(), "values/strings.commonMain.cvr", 172,
34),
)
)

Expand All @@ -50,7 +51,8 @@ internal val Res.string._1_kebab_case: StringResource
private fun init__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.cvr", 135, 36),
org.jetbrains.compose.resources.ResourceItem(setOf(), "values/strings.commonMain.cvr", 135,
36),
)
)

Expand All @@ -62,7 +64,8 @@ internal val Res.string.app_name: StringResource
private fun init_app_name(): StringResource = org.jetbrains.compose.resources.StringResource(
"string:app_name", "app_name",
setOf(
org.jetbrains.compose.resources.ResourceItem(setOf(), "values/strings.cvr", 207, 44),
org.jetbrains.compose.resources.ResourceItem(setOf(), "values/strings.commonMain.cvr", 207,
44),
)
)

Expand All @@ -74,7 +77,8 @@ internal val Res.string.camelCase: StringResource
private fun init_camelCase(): StringResource = org.jetbrains.compose.resources.StringResource(
"string:camelCase", "camelCase",
setOf(
org.jetbrains.compose.resources.ResourceItem(setOf(), "values/strings.cvr", 252, 29),
org.jetbrains.compose.resources.ResourceItem(setOf(), "values/strings.commonMain.cvr", 252,
29),
)
)

Expand All @@ -86,7 +90,8 @@ internal val Res.string.hello: StringResource
private fun init_hello(): StringResource = org.jetbrains.compose.resources.StringResource(
"string:hello", "hello",
setOf(
org.jetbrains.compose.resources.ResourceItem(setOf(), "values/strings.cvr", 282, 37),
org.jetbrains.compose.resources.ResourceItem(setOf(), "values/strings.commonMain.cvr", 282,
37),
)
)

Expand All @@ -98,7 +103,8 @@ internal val Res.string.multi_line: StringResource
private fun init_multi_line(): StringResource = org.jetbrains.compose.resources.StringResource(
"string:multi_line", "multi_line",
setOf(
org.jetbrains.compose.resources.ResourceItem(setOf(), "values/strings.cvr", 320, 178),
org.jetbrains.compose.resources.ResourceItem(setOf(), "values/strings.commonMain.cvr", 320,
178),
)
)

Expand All @@ -110,6 +116,7 @@ internal val Res.string.str_template: StringResource
private fun init_str_template(): StringResource = org.jetbrains.compose.resources.StringResource(
"string:str_template", "str_template",
setOf(
org.jetbrains.compose.resources.ResourceItem(setOf(), "values/strings.cvr", 499, 76),
org.jetbrains.compose.resources.ResourceItem(setOf(), "values/strings.commonMain.cvr", 499,
76),
)
)
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ internal val Res.string.desktop_str: StringResource
private fun init_desktop_str(): StringResource = org.jetbrains.compose.resources.StringResource(
"string:desktop_str", "desktop_str",
setOf(
org.jetbrains.compose.resources.ResourceItem(setOf(), "values/desktop_strings.cvr", 10, 39),
org.jetbrains.compose.resources.ResourceItem(setOf(),
"values/desktop_strings.desktopMain.cvr", 10, 39),
)
)

0 comments on commit 645256f

Please sign in to comment.