|
|
@ -2,15 +2,30 @@ package org.jetbrains.compose.test.tests.integration |
|
|
|
|
|
|
|
|
|
|
|
import org.gradle.util.GradleVersion |
|
|
|
import org.gradle.util.GradleVersion |
|
|
|
import org.jetbrains.compose.desktop.application.internal.ComposeProperties |
|
|
|
import org.jetbrains.compose.desktop.application.internal.ComposeProperties |
|
|
|
import org.jetbrains.compose.internal.utils.* |
|
|
|
import org.jetbrains.compose.internal.utils.Arch |
|
|
|
|
|
|
|
import org.jetbrains.compose.internal.utils.OS |
|
|
|
|
|
|
|
import org.jetbrains.compose.internal.utils.currentArch |
|
|
|
|
|
|
|
import org.jetbrains.compose.internal.utils.currentOS |
|
|
|
import org.jetbrains.compose.resources.XmlValuesConverterTask |
|
|
|
import org.jetbrains.compose.resources.XmlValuesConverterTask |
|
|
|
import org.jetbrains.compose.test.utils.* |
|
|
|
import org.jetbrains.compose.test.utils.GradlePluginTestBase |
|
|
|
|
|
|
|
import org.jetbrains.compose.test.utils.TestProject |
|
|
|
|
|
|
|
import org.jetbrains.compose.test.utils.assertEqualTextFiles |
|
|
|
|
|
|
|
import org.jetbrains.compose.test.utils.assertNotEqualTextFiles |
|
|
|
|
|
|
|
import org.jetbrains.compose.test.utils.checkExists |
|
|
|
|
|
|
|
import org.jetbrains.compose.test.utils.checks |
|
|
|
|
|
|
|
import org.jetbrains.compose.test.utils.modify |
|
|
|
import org.junit.jupiter.api.Assumptions |
|
|
|
import org.junit.jupiter.api.Assumptions |
|
|
|
import org.junit.jupiter.api.Test |
|
|
|
import org.junit.jupiter.api.Test |
|
|
|
import java.io.File |
|
|
|
import java.io.File |
|
|
|
import java.util.zip.ZipFile |
|
|
|
import java.util.zip.ZipFile |
|
|
|
|
|
|
|
import kotlin.io.path.Path |
|
|
|
|
|
|
|
import kotlin.io.path.invariantSeparatorsPathString |
|
|
|
import kotlin.io.path.relativeTo |
|
|
|
import kotlin.io.path.relativeTo |
|
|
|
import kotlin.test.* |
|
|
|
import kotlin.test.assertEquals |
|
|
|
|
|
|
|
import kotlin.test.assertFalse |
|
|
|
|
|
|
|
import kotlin.test.assertNotNull |
|
|
|
|
|
|
|
import kotlin.test.assertNull |
|
|
|
|
|
|
|
import kotlin.test.assertTrue |
|
|
|
|
|
|
|
|
|
|
|
class ResourcesTest : GradlePluginTestBase() { |
|
|
|
class ResourcesTest : GradlePluginTestBase() { |
|
|
|
@Test |
|
|
|
@Test |
|
|
@ -244,38 +259,31 @@ class ResourcesTest : GradlePluginTestBase() { |
|
|
|
val resDir = file("cmplib/src/commonMain/composeResources") |
|
|
|
val resDir = file("cmplib/src/commonMain/composeResources") |
|
|
|
val resourcesFiles = resDir.walkTopDown() |
|
|
|
val resourcesFiles = resDir.walkTopDown() |
|
|
|
.filter { !it.isDirectory && !it.isHidden } |
|
|
|
.filter { !it.isDirectory && !it.isHidden } |
|
|
|
.getConvertedResources(resDir) |
|
|
|
.getConvertedResources(resDir, "composeResources/me.sample.library.resources") |
|
|
|
val subdir = "me.sample.library.resources" |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
fun libpath(target: String, ext: String) = |
|
|
|
fun libpath(target: String, ext: String) = |
|
|
|
"my-mvn/me/sample/library/cmplib-$target/1.0/cmplib-$target-1.0$ext" |
|
|
|
"my-mvn/me/sample/library/cmplib-$target/1.0/cmplib-$target-1.0$ext" |
|
|
|
|
|
|
|
|
|
|
|
val aar = file(libpath("android", ".aar")) |
|
|
|
val aar = file(libpath("android", ".aar")) |
|
|
|
assertTrue(aar.exists(), "File not found: " + aar.path) |
|
|
|
checkResourcesZip(aar, resourcesFiles, true) |
|
|
|
ZipFile(aar).use { zip -> resourcesFiles.forEach { fontRes -> |
|
|
|
|
|
|
|
assertNotNull( |
|
|
|
|
|
|
|
zip.getEntry("assets/composeResources/$subdir/$fontRes"), |
|
|
|
|
|
|
|
"Resource not found: '$fontRes' in aar '${aar.path}'" |
|
|
|
|
|
|
|
) |
|
|
|
|
|
|
|
} } |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
val jar = file(libpath("jvm", ".jar")) |
|
|
|
val jar = file(libpath("jvm", ".jar")) |
|
|
|
checkResourcesZip(jar, resourcesFiles, subdir) |
|
|
|
checkResourcesZip(jar, resourcesFiles, false) |
|
|
|
|
|
|
|
|
|
|
|
if (currentOS == OS.MacOS) { |
|
|
|
if (currentOS == OS.MacOS) { |
|
|
|
val iosx64ResZip = file(libpath("iosx64", "-kotlin_resources.kotlin_resources.zip")) |
|
|
|
val iosx64ResZip = file(libpath("iosx64", "-kotlin_resources.kotlin_resources.zip")) |
|
|
|
checkResourcesZip(iosx64ResZip, resourcesFiles, subdir) |
|
|
|
checkResourcesZip(iosx64ResZip, resourcesFiles, false) |
|
|
|
val iosarm64ResZip = file(libpath("iosarm64", "-kotlin_resources.kotlin_resources.zip")) |
|
|
|
val iosarm64ResZip = file(libpath("iosarm64", "-kotlin_resources.kotlin_resources.zip")) |
|
|
|
checkResourcesZip(iosarm64ResZip, resourcesFiles, subdir) |
|
|
|
checkResourcesZip(iosarm64ResZip, resourcesFiles, false) |
|
|
|
val iossimulatorarm64ResZip = file( |
|
|
|
val iossimulatorarm64ResZip = file( |
|
|
|
libpath("iossimulatorarm64", "-kotlin_resources.kotlin_resources.zip") |
|
|
|
libpath("iossimulatorarm64", "-kotlin_resources.kotlin_resources.zip") |
|
|
|
) |
|
|
|
) |
|
|
|
checkResourcesZip(iossimulatorarm64ResZip, resourcesFiles, subdir) |
|
|
|
checkResourcesZip(iossimulatorarm64ResZip, resourcesFiles, false) |
|
|
|
} |
|
|
|
} |
|
|
|
val jsResZip = file(libpath("js", "-kotlin_resources.kotlin_resources.zip")) |
|
|
|
val jsResZip = file(libpath("js", "-kotlin_resources.kotlin_resources.zip")) |
|
|
|
checkResourcesZip(jsResZip, resourcesFiles, subdir) |
|
|
|
checkResourcesZip(jsResZip, resourcesFiles, false) |
|
|
|
val wasmjsResZip = file(libpath("wasm-js", "-kotlin_resources.kotlin_resources.zip")) |
|
|
|
val wasmjsResZip = file(libpath("wasm-js", "-kotlin_resources.kotlin_resources.zip")) |
|
|
|
checkResourcesZip(wasmjsResZip, resourcesFiles, subdir) |
|
|
|
checkResourcesZip(wasmjsResZip, resourcesFiles, false) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
file("settings.gradle.kts").modify { content -> |
|
|
|
file("settings.gradle.kts").modify { content -> |
|
|
@ -323,14 +331,19 @@ class ResourcesTest : GradlePluginTestBase() { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private fun checkResourcesZip(zipFile: File, resourcesFiles: Sequence<String>, subdir: String) { |
|
|
|
private fun checkResourcesZip(zipFile: File, resourcesFiles: Sequence<String>, isAndroid: Boolean) { |
|
|
|
|
|
|
|
println("check ZIP: '${zipFile.path}'") |
|
|
|
assertTrue(zipFile.exists(), "File not found: " + zipFile.path) |
|
|
|
assertTrue(zipFile.exists(), "File not found: " + zipFile.path) |
|
|
|
ZipFile(zipFile).use { zip -> |
|
|
|
ZipFile(zipFile).use { zip -> |
|
|
|
resourcesFiles.forEach { res -> |
|
|
|
resourcesFiles.forEach { res -> |
|
|
|
assertNotNull( |
|
|
|
println("check '$res' file") |
|
|
|
zip.getEntry("composeResources/$subdir/$res"), |
|
|
|
if (isAndroid) { |
|
|
|
"Resource not found: '$res' in zip '${zipFile.path}'" |
|
|
|
//android resources should be only in assets |
|
|
|
) |
|
|
|
assertNull(zip.getEntry(res), "file = '$res'") |
|
|
|
|
|
|
|
assertNotNull(zip.getEntry("assets/$res"), "file = 'assets/$res'") |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
assertNotNull(zip.getEntry(res), "file = '$res'") |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
@ -369,50 +382,51 @@ class ResourcesTest : GradlePluginTestBase() { |
|
|
|
file("src/jsMain/composeResources/files/platform.txt").writeNewFile("js") |
|
|
|
file("src/jsMain/composeResources/files/platform.txt").writeNewFile("js") |
|
|
|
|
|
|
|
|
|
|
|
val commonResourcesDir = file("src/commonMain/composeResources") |
|
|
|
val commonResourcesDir = file("src/commonMain/composeResources") |
|
|
|
|
|
|
|
val repackDir = "composeResources/app.group.resources_test.generated.resources" |
|
|
|
val commonResourcesFiles = commonResourcesDir.walkTopDown() |
|
|
|
val commonResourcesFiles = commonResourcesDir.walkTopDown() |
|
|
|
.filter { !it.isDirectory && !it.isHidden } |
|
|
|
.filter { !it.isDirectory && !it.isHidden } |
|
|
|
.getConvertedResources(commonResourcesDir) |
|
|
|
.getConvertedResources(commonResourcesDir, repackDir) |
|
|
|
|
|
|
|
|
|
|
|
gradle("build").checks { |
|
|
|
gradle("build").checks { |
|
|
|
check.taskSuccessful(":copyDemoDebugResourcesToAndroidAssets") |
|
|
|
check.taskSuccessful(":demoDebugAssetsCopyForAGP") |
|
|
|
check.taskSuccessful(":copyDemoReleaseResourcesToAndroidAssets") |
|
|
|
check.taskSuccessful(":demoReleaseAssetsCopyForAGP") |
|
|
|
check.taskSuccessful(":copyFullDebugResourcesToAndroidAssets") |
|
|
|
check.taskSuccessful(":fullDebugAssetsCopyForAGP") |
|
|
|
check.taskSuccessful(":copyFullReleaseResourcesToAndroidAssets") |
|
|
|
check.taskSuccessful(":fullReleaseAssetsCopyForAGP") |
|
|
|
|
|
|
|
|
|
|
|
getAndroidApk("demo", "debug", "Resources-Test").let { apk -> |
|
|
|
getAndroidApk("demo", "debug", "Resources-Test").let { apk -> |
|
|
|
checkResourcesInZip(apk, commonResourcesFiles, true) |
|
|
|
checkResourcesZip(apk, commonResourcesFiles, true) |
|
|
|
assertEquals( |
|
|
|
assertEquals( |
|
|
|
"android demo-debug", |
|
|
|
"android demo-debug", |
|
|
|
readFileInZip(apk, "assets/files/platform.txt").decodeToString() |
|
|
|
readFileInZip(apk, "assets/$repackDir/files/platform.txt").decodeToString() |
|
|
|
) |
|
|
|
) |
|
|
|
} |
|
|
|
} |
|
|
|
getAndroidApk("demo", "release", "Resources-Test").let { apk -> |
|
|
|
getAndroidApk("demo", "release", "Resources-Test").let { apk -> |
|
|
|
checkResourcesInZip(apk, commonResourcesFiles, true) |
|
|
|
checkResourcesZip(apk, commonResourcesFiles, true) |
|
|
|
assertEquals( |
|
|
|
assertEquals( |
|
|
|
"android demo-release", |
|
|
|
"android demo-release", |
|
|
|
readFileInZip(apk, "assets/files/platform.txt").decodeToString() |
|
|
|
readFileInZip(apk, "assets/$repackDir/files/platform.txt").decodeToString() |
|
|
|
) |
|
|
|
) |
|
|
|
} |
|
|
|
} |
|
|
|
getAndroidApk("full", "debug", "Resources-Test").let { apk -> |
|
|
|
getAndroidApk("full", "debug", "Resources-Test").let { apk -> |
|
|
|
checkResourcesInZip(apk, commonResourcesFiles, true) |
|
|
|
checkResourcesZip(apk, commonResourcesFiles, true) |
|
|
|
assertEquals( |
|
|
|
assertEquals( |
|
|
|
"android full-debug", |
|
|
|
"android full-debug", |
|
|
|
readFileInZip(apk, "assets/files/platform.txt").decodeToString() |
|
|
|
readFileInZip(apk, "assets/$repackDir/files/platform.txt").decodeToString() |
|
|
|
) |
|
|
|
) |
|
|
|
} |
|
|
|
} |
|
|
|
getAndroidApk("full", "release", "Resources-Test").let { apk -> |
|
|
|
getAndroidApk("full", "release", "Resources-Test").let { apk -> |
|
|
|
checkResourcesInZip(apk, commonResourcesFiles, true) |
|
|
|
checkResourcesZip(apk, commonResourcesFiles, true) |
|
|
|
assertEquals( |
|
|
|
assertEquals( |
|
|
|
"android full-release", |
|
|
|
"android full-release", |
|
|
|
readFileInZip(apk, "assets/files/platform.txt").decodeToString() |
|
|
|
readFileInZip(apk, "assets/$repackDir/files/platform.txt").decodeToString() |
|
|
|
) |
|
|
|
) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
file("build/libs/Resources-Test-desktop.jar").let { jar -> |
|
|
|
file("build/libs/Resources-Test-desktop.jar").let { jar -> |
|
|
|
checkResourcesInZip(jar, commonResourcesFiles, false) |
|
|
|
checkResourcesZip(jar, commonResourcesFiles, false) |
|
|
|
assertEquals( |
|
|
|
assertEquals( |
|
|
|
"desktop", |
|
|
|
"desktop", |
|
|
|
readFileInZip(jar, "files/platform.txt").decodeToString() |
|
|
|
readFileInZip(jar, "$repackDir/files/platform.txt").decodeToString() |
|
|
|
) |
|
|
|
) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -420,11 +434,11 @@ class ResourcesTest : GradlePluginTestBase() { |
|
|
|
commonResourcesFiles.forEach { res -> |
|
|
|
commonResourcesFiles.forEach { res -> |
|
|
|
assertTrue(jsBuildDir.resolve(res).exists()) |
|
|
|
assertTrue(jsBuildDir.resolve(res).exists()) |
|
|
|
} |
|
|
|
} |
|
|
|
assertEquals("js", jsBuildDir.resolve("files/platform.txt").readText()) |
|
|
|
assertEquals("js", jsBuildDir.resolve("$repackDir/files/platform.txt").readText()) |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private fun Sequence<File>.getConvertedResources(baseDir: File) = map { file -> |
|
|
|
private fun Sequence<File>.getConvertedResources(baseDir: File, repackDir: String) = map { file -> |
|
|
|
val newFile = if ( |
|
|
|
val newFile = if ( |
|
|
|
file.parentFile.name.startsWith("value") && |
|
|
|
file.parentFile.name.startsWith("value") && |
|
|
|
file.extension.equals("xml", true) |
|
|
|
file.extension.equals("xml", true) |
|
|
@ -434,7 +448,7 @@ class ResourcesTest : GradlePluginTestBase() { |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
file |
|
|
|
file |
|
|
|
} |
|
|
|
} |
|
|
|
newFile.relativeTo(baseDir).invariantSeparatorsPath |
|
|
|
Path(repackDir, newFile.relativeTo(baseDir).path).invariantSeparatorsPathString |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private fun File.writeNewFile(text: String) { |
|
|
|
private fun File.writeNewFile(text: String) { |
|
|
@ -451,23 +465,6 @@ class ResourcesTest : GradlePluginTestBase() { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private fun checkResourcesInZip(file: File, commonResourcesFiles: Sequence<String>, isAndroid: Boolean) { |
|
|
|
|
|
|
|
println("check ZIP: '${file.path}'") |
|
|
|
|
|
|
|
assertTrue(file.exists()) |
|
|
|
|
|
|
|
ZipFile(file).use { zip -> |
|
|
|
|
|
|
|
commonResourcesFiles.forEach { res -> |
|
|
|
|
|
|
|
println("check '$res' file") |
|
|
|
|
|
|
|
if (isAndroid) { |
|
|
|
|
|
|
|
//android resources should be only in assets |
|
|
|
|
|
|
|
assertNull(zip.getEntry(res), "file = '$res'") |
|
|
|
|
|
|
|
assertNotNull(zip.getEntry("assets/$res"), "file = 'assets/$res'") |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
assertNotNull(zip.getEntry(res), "file = '$res'") |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private fun readFileInZip(file: File, path: String): ByteArray = ZipFile(file).use { zip -> |
|
|
|
private fun readFileInZip(file: File, path: String): ByteArray = ZipFile(file).use { zip -> |
|
|
|
val platformTxt = zip.getEntry(path) |
|
|
|
val platformTxt = zip.getEntry(path) |
|
|
|
assertNotNull(platformTxt, "file = '$path'") |
|
|
|
assertNotNull(platformTxt, "file = '$path'") |
|
|
@ -654,8 +651,8 @@ class ResourcesTest : GradlePluginTestBase() { |
|
|
|
check.taskNoSource(":prepareComposeResourcesTaskForIosX64Main") |
|
|
|
check.taskNoSource(":prepareComposeResourcesTaskForIosX64Main") |
|
|
|
check.taskSkipped(":generateResourceAccessorsForIosX64Main") |
|
|
|
check.taskSkipped(":generateResourceAccessorsForIosX64Main") |
|
|
|
|
|
|
|
|
|
|
|
file("build/compose/cocoapods/compose-resources/drawable/compose-multiplatform.xml").checkExists() |
|
|
|
file("build/compose/cocoapods/compose-resources/composeResources/iosresources.generated.resources/drawable/compose-multiplatform.xml").checkExists() |
|
|
|
file("build/compose/cocoapods/compose-resources/drawable/icon.xml").checkExists() |
|
|
|
file("build/compose/cocoapods/compose-resources/composeResources/iosresources.generated.resources/drawable/icon.xml").checkExists() |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
gradle(":podspec", "-Pkotlin.native.cocoapods.generate.wrapper=true").checks { |
|
|
|
gradle(":podspec", "-Pkotlin.native.cocoapods.generate.wrapper=true").checks { |
|
|
@ -676,8 +673,8 @@ class ResourcesTest : GradlePluginTestBase() { |
|
|
|
check.taskSkipped(":linkDebugTestIosX64") |
|
|
|
check.taskSkipped(":linkDebugTestIosX64") |
|
|
|
} |
|
|
|
} |
|
|
|
gradle(":copyTestComposeResourcesForIosX64").checks { |
|
|
|
gradle(":copyTestComposeResourcesForIosX64").checks { |
|
|
|
file("build/bin/iosX64/debugTest/compose-resources/drawable/compose-multiplatform.xml").checkExists() |
|
|
|
file("build/bin/iosX64/debugTest/compose-resources/composeResources/iosresources.generated.resources/drawable/compose-multiplatform.xml").checkExists() |
|
|
|
file("build/bin/iosX64/debugTest/compose-resources/drawable/icon.xml").checkExists() |
|
|
|
file("build/bin/iosX64/debugTest/compose-resources/composeResources/iosresources.generated.resources/drawable/icon.xml").checkExists() |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|