Skip to content

Commit

Permalink
Delete .DS_Store files from composeResources dir
Browse files Browse the repository at this point in the history
  • Loading branch information
terrakok committed Jan 23, 2024
1 parent dcf08db commit fc7f065
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ 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 @@ -33,6 +35,13 @@ 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()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import kotlin.io.path.Path

class ResourcesTest : GradlePluginTestBase() {
@Test
fun testGeneratedAccessorsAndCopiedFonts() = with(testProject("misc/commonResources")) {
fun testGeneratedAccessorsAndCopiedFonts(): Unit = with(testProject("misc/commonResources")) {
//check generated resource's accessors
gradle("generateComposeResClass").checks {
assertEqualTextFiles(
Expand Down Expand Up @@ -108,11 +108,27 @@ class ResourcesTest : GradlePluginTestBase() {
file("src/commonMain/composeResources/drawable/vector_3.xml").renameTo(
file("src/commonMain/composeResources/drawable/vector_2.xml")
)
}

@Test
fun testCopyFontsInAndroidApp(): Unit = with(testProject("misc/commonResources")) {
gradle("assembleDebug").checks {
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() }

//TODO: check a real build after a release a new version of the resources library
//because generated accessors depend on classes from the new version
gradle("assembleDebug", "--dry-run").checks {
check.taskSkipped("copyFontsToAndroidAssets")
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")
)
}
}
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
import androidx.compose.foundation.layout.*
import androidx.compose.foundation.Image
import androidx.compose.material.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.text.font.FontFamily
import generated.resources.Res
import androidx.compose.ui.Modifier
import androidx.compose.ui.unit.dp
import app.group.resources_test.generated.resources.Res
import org.jetbrains.compose.resources.*

@OptIn(ExperimentalResourceApi::class)
Expand All @@ -11,10 +14,10 @@ fun App() {
Column {
Image(
modifier = Modifier.size(100.dp),
painter = painterResource(Res.images.vector),
painter = painterResource(Res.drawable.vector),
contentDescription = null
)
Text(getString(Res.strings.app_name))
val font = FontFamily(Font(Res.fonts.emptyfont))
Text(stringResource(Res.string.app_name))
val font = FontFamily(Font(Res.font.emptyfont))
}
}

0 comments on commit fc7f065

Please sign in to comment.