Skip to content

Commit

Permalink
Ignore .DS_Store files in composeResources dir
Browse files Browse the repository at this point in the history
  • Loading branch information
terrakok committed Jan 23, 2024
1 parent fc7f065 commit e97eeae
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand All @@ -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) {
Expand All @@ -54,8 +45,7 @@ abstract class GenerateResClassTask : DefaultTask() {
//type -> id -> resource item
val resources: Map<ResourceType, Map<String, List<ResourceItem>>> = dirs
.flatMap { dir ->
dir.listFiles()
.orEmpty()
dir.listFilesWithoutDsStore()
.mapNotNull { it.fileToResourceItems(rootResDir.toPath()) }
.flatten()
}
Expand Down Expand Up @@ -114,6 +104,9 @@ abstract class GenerateResClassTask : DefaultTask() {
.map { it.attributes.getNamedItem("name").nodeValue }
return ids.toSet()
}

private fun File.listFilesWithoutDsStore(): List<File> =
listFiles()?.filter { it.name != ".DS_Store" }.orEmpty()
}

internal fun String.asUnderscoredIdentifier(): String =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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")
)
}
}
}

0 comments on commit e97eeae

Please sign in to comment.