From e97eeae87397fc7a0c265f827f9174f5c222252d Mon Sep 17 00:00:00 2001 From: Konstantin Tskhovrebov Date: Tue, 23 Jan 2024 17:41:17 +0100 Subject: [PATCH] Ignore .DS_Store files in composeResources dir --- .../compose/resources/GenerateResClassTask.kt | 17 +++++------------ .../test/tests/integration/ResourcesTest.kt | 18 +++--------------- 2 files changed, 8 insertions(+), 27 deletions(-) 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 d94f7e0e15a..890d0c1b77d 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 @@ -9,8 +9,6 @@ import java.nio.file.Path import javax.xml.parsers.DocumentBuilderFactory import kotlin.io.path.relativeTo -private const val DS_STORE_FILE = ".DS_Store" - /** * This task should be FAST and SAFE! Because it is being run during IDE import. */ @@ -35,15 +33,8 @@ abstract class GenerateResClassTask : DefaultTask() { val rootResDir = resDir.get().asFile logger.info("Generate resources for $rootResDir") - rootResDir.walkTopDown() - .filter { file -> file.name == DS_STORE_FILE } - .forEach { file -> - logger.info("Delete $DS_STORE_FILE: ${file.path}") - file.delete() - } - //get first level dirs - val dirs = rootResDir.listFiles().orEmpty() + val dirs = rootResDir.listFilesWithoutDsStore() dirs.forEach { f -> if (!f.isDirectory) { @@ -54,8 +45,7 @@ abstract class GenerateResClassTask : DefaultTask() { //type -> id -> resource item val resources: Map>> = dirs .flatMap { dir -> - dir.listFiles() - .orEmpty() + dir.listFilesWithoutDsStore() .mapNotNull { it.fileToResourceItems(rootResDir.toPath()) } .flatten() } @@ -114,6 +104,9 @@ abstract class GenerateResClassTask : DefaultTask() { .map { it.attributes.getNamedItem("name").nodeValue } return ids.toSet() } + + private fun File.listFilesWithoutDsStore(): List = + listFiles()?.filter { it.name != ".DS_Store" }.orEmpty() } internal fun String.asUnderscoredIdentifier(): String = diff --git a/gradle-plugins/compose/src/test/kotlin/org/jetbrains/compose/test/tests/integration/ResourcesTest.kt b/gradle-plugins/compose/src/test/kotlin/org/jetbrains/compose/test/tests/integration/ResourcesTest.kt index 58b7e74b627..dcfd765732f 100644 --- a/gradle-plugins/compose/src/test/kotlin/org/jetbrains/compose/test/tests/integration/ResourcesTest.kt +++ b/gradle-plugins/compose/src/test/kotlin/org/jetbrains/compose/test/tests/integration/ResourcesTest.kt @@ -10,6 +10,9 @@ import kotlin.io.path.Path class ResourcesTest : GradlePluginTestBase() { @Test fun testGeneratedAccessorsAndCopiedFonts(): Unit = with(testProject("misc/commonResources")) { + //.DS_Store files should be ignored + file("src/commonMain/composeResources/.DS_Store").createNewFile() + //check generated resource's accessors gradle("generateComposeResClass").checks { assertEqualTextFiles( @@ -116,19 +119,4 @@ class ResourcesTest : GradlePluginTestBase() { check.taskSuccessful(":copyFontsToAndroidAssets") } } - - @Test - fun testCleanDsStoreFilesInResources(): Unit = with(testProject("misc/commonResources")) { - val f1 = file("src/commonMain/composeResources/drawable/.DS_Store").also { it.createNewFile() } - val f2 = file("src/commonMain/composeResources/.DS_Store").also { it.createNewFile() } - - gradle("generateComposeResClass").checks { - assert(!f1.exists()) - assert(!f2.exists()) - assertEqualTextFiles( - file("build/generated/compose/resourceGenerator/kotlin/app/group/resources_test/generated/resources/Res.kt"), - file("expected/Res.kt") - ) - } - } } \ No newline at end of file