Browse Source

[gradle] Temporary revert of gradle changes.

Waiting a new dev version of the library
pr-4519
Konstantin Tskhovrebov 8 months ago
parent
commit
ef8cd58cfe
  1. 20
      gradle-plugins/compose/src/main/kotlin/org/jetbrains/compose/resources/GenerateResClassTask.kt
  2. 4
      gradle-plugins/compose/src/main/kotlin/org/jetbrains/compose/resources/ResourcesSpec.kt
  3. 26
      gradle-plugins/compose/src/test/test-projects/misc/commonResources/expected-open-res/Plurals0.kt
  4. 2
      gradle-plugins/compose/src/test/test-projects/misc/commonResources/expected-open-res/Res.kt
  5. 26
      gradle-plugins/compose/src/test/test-projects/misc/commonResources/expected/Plurals0.kt
  6. 2
      gradle-plugins/compose/src/test/test-projects/misc/commonResources/expected/Res.kt
  7. 10
      gradle-plugins/compose/src/test/test-projects/misc/commonResources/src/commonMain/composeResources/values/strings.xml
  8. 2
      gradle-plugins/compose/src/test/test-projects/misc/emptyResources/expected/Res.kt
  9. 2
      gradle-plugins/compose/src/test/test-projects/misc/jvmOnlyResources/expected/Res.kt

20
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)) { if (typeString == "values" && file.name.equals("strings.xml", true)) {
return getStringResources(file).mapNotNull { (typeName, strId) -> val stringIds = getStringIds(file)
val type = when(typeName) { return stringIds.map { strId ->
"string", "string-array" -> ResourceType.STRING ResourceItem(ResourceType.STRING, qualifiers, strId.asUnderscoredIdentifier(), path)
"plurals" -> ResourceType.PLURAL_STRING
else -> return@mapNotNull null
}
ResourceItem(type, qualifiers, strId.asUnderscoredIdentifier(), path)
} }
} }
@ -115,14 +111,14 @@ internal abstract class GenerateResClassTask : DefaultTask() {
return listOf(ResourceItem(type, qualifiers, file.nameWithoutExtension.asUnderscoredIdentifier(), path)) return listOf(ResourceItem(type, qualifiers, file.nameWithoutExtension.asUnderscoredIdentifier(), path))
} }
//type -> id private val stringTypeNames = listOf("string", "string-array")
private val stringTypeNames = listOf("string", "string-array", "plurals") private fun getStringIds(stringsXml: File): Set<String> {
private fun getStringResources(stringsXml: File): List<Pair<String, String>> {
val doc = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(stringsXml) val doc = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(stringsXml)
val items = doc.getElementsByTagName("resources").item(0).childNodes 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 } .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<File> = private fun File.listNotHiddenFiles(): List<File> =

4
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) { internal enum class ResourceType(val typeName: String) {
DRAWABLE("drawable"), DRAWABLE("drawable"),
STRING("string"), STRING("string"),
PLURAL_STRING("plurals"),
FONT("font"); FONT("font");
override fun toString(): String = typeName override fun toString(): String = typeName
@ -32,7 +31,6 @@ internal data class ResourceItem(
private fun ResourceType.getClassName(): ClassName = when (this) { private fun ResourceType.getClassName(): ClassName = when (this) {
ResourceType.DRAWABLE -> ClassName("org.jetbrains.compose.resources", "DrawableResource") ResourceType.DRAWABLE -> ClassName("org.jetbrains.compose.resources", "DrawableResource")
ResourceType.STRING -> ClassName("org.jetbrains.compose.resources", "StringResource") 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") ResourceType.FONT -> ClassName("org.jetbrains.compose.resources", "FontResource")
} }
@ -227,7 +225,7 @@ private fun getChunkFileSpec(
CodeBlock.builder() CodeBlock.builder()
.add("return %T(\n", type.getClassName()).withIndent { .add("return %T(\n", type.getClassName()).withIndent {
add("\"${type}:${resName}\",") add("\"${type}:${resName}\",")
if (type == ResourceType.STRING || type == ResourceType.PLURAL_STRING) add(" \"$resName\",") if (type == ResourceType.STRING) add(" \"$resName\",")
withIndent { withIndent {
add("\nsetOf(\n").withIndent { add("\nsetOf(\n").withIndent {
items.forEach { item -> items.forEach { item ->

26
gradle-plugins/compose/src/test/test-projects/misc/commonResources/expected-open-res/Plurals0.kt

@ -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"),
)
)

2
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 string
public object plurals
public object font public object font
} }

26
gradle-plugins/compose/src/test/test-projects/misc/commonResources/expected/Plurals0.kt

@ -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"),
)
)

2
gradle-plugins/compose/src/test/test-projects/misc/commonResources/expected/Res.kt

@ -27,7 +27,5 @@ internal object Res {
public object string public object string
public object plurals
public object font public object font
} }

10
gradle-plugins/compose/src/test/test-projects/misc/commonResources/src/commonMain/composeResources/values/strings.xml

@ -13,14 +13,4 @@
<string name="PascalCase">PascalCase</string> <string name="PascalCase">PascalCase</string>
<string name="1-kebab-case">1-kebab-case</string> <string name="1-kebab-case">1-kebab-case</string>
<string name="camelCase">camelCase</string> <string name="camelCase">camelCase</string>
<plurals name="numberOfSongsAvailable">
<item quantity="zero">%d zero</item>
<item quantity="one">%d one</item>
<item quantity="two">%d two</item>
<item quantity="few">%d few</item>
<item quantity="many">%d many</item>
<item quantity="other">%d other</item>
</plurals>
</resources> </resources>

2
gradle-plugins/compose/src/test/test-projects/misc/emptyResources/expected/Res.kt

@ -27,7 +27,5 @@ internal object Res {
public object string public object string
public object plurals
public object font public object font
} }

2
gradle-plugins/compose/src/test/test-projects/misc/jvmOnlyResources/expected/Res.kt

@ -27,7 +27,5 @@ internal object Res {
public object string public object string
public object plurals
public object font public object font
} }

Loading…
Cancel
Save