Add an IT for publication of multiplatform resources in a jvm target
^KT-65540
This commit is contained in:
committed by
Space Team
parent
370799b4e3
commit
7e9e064748
+14
-5
@@ -46,7 +46,12 @@ import java.util.zip.GZIPInputStream
|
||||
// Set this to true if you want to dump all bytecode (test will fail in this case)
|
||||
private val DUMP_ALL = System.getProperty("comparison.dump.all") == "true"
|
||||
|
||||
fun assertEqualDirectories(expected: File, actual: File, forgiveExtraFiles: Boolean) {
|
||||
fun assertEqualDirectories(
|
||||
expected: File,
|
||||
actual: File,
|
||||
forgiveExtraFiles: Boolean,
|
||||
filter: (File) -> (Boolean) = { true },
|
||||
) {
|
||||
val pathsInExpected = getAllRelativePaths(expected)
|
||||
val pathsInActual = getAllRelativePaths(actual)
|
||||
|
||||
@@ -55,8 +60,8 @@ fun assertEqualDirectories(expected: File, actual: File, forgiveExtraFiles: Bool
|
||||
.filter { DUMP_ALL || !Arrays.equals(File(expected, it).readBytes(), File(actual, it).readBytes()) }
|
||||
.sorted()
|
||||
|
||||
val expectedString = getDirectoryString(expected, changedPaths)
|
||||
val actualString = getDirectoryString(actual, changedPaths)
|
||||
val expectedString = getDirectoryString(expected, changedPaths, filter)
|
||||
val actualString = getDirectoryString(actual, changedPaths, filter)
|
||||
|
||||
if (DUMP_ALL) {
|
||||
Assert.assertEquals(expectedString, actualString + " ")
|
||||
@@ -92,7 +97,11 @@ private fun File.checksumString(): String {
|
||||
|
||||
private const val DIR_ROOT_PLACEHOLDER = "<DIR_ROOT_PLACEHOLDER>"
|
||||
|
||||
private fun getDirectoryString(dir: File, interestingPaths: List<String>): String {
|
||||
private fun getDirectoryString(
|
||||
dir: File,
|
||||
interestingPaths: List<String>,
|
||||
predicate: (File) -> (Boolean),
|
||||
): String {
|
||||
val buf = StringBuilder()
|
||||
val p = Printer(buf)
|
||||
|
||||
@@ -100,7 +109,7 @@ private fun getDirectoryString(dir: File, interestingPaths: List<String>): Strin
|
||||
fun addDirContent(dir: File) {
|
||||
p.pushIndent()
|
||||
|
||||
val listFiles = dir.listFiles()
|
||||
val listFiles = dir.listFiles()?.filter(predicate)
|
||||
assertNotNull("$dir does not exist", listFiles)
|
||||
|
||||
val children = listFiles!!.sortedWith(compareBy({ it.isDirectory }, { it.name }))
|
||||
|
||||
+108
@@ -0,0 +1,108 @@
|
||||
package org.jetbrains.kotlin.gradle.mpp.resources
|
||||
|
||||
import java.nio.file.Files
|
||||
import java.nio.file.Paths
|
||||
import java.nio.file.StandardCopyOption
|
||||
import org.gradle.util.GradleVersion
|
||||
import org.jetbrains.kotlin.gradle.testbase.*
|
||||
import org.jetbrains.kotlin.gradle.util.capitalize
|
||||
import org.jetbrains.kotlin.incremental.testingUtils.assertEqualDirectories
|
||||
import org.junit.jupiter.api.DisplayName
|
||||
import java.nio.file.Path
|
||||
import java.util.zip.ZipFile
|
||||
|
||||
@MppGradlePluginTests
|
||||
@DisplayName("Test multiplatform resources publication")
|
||||
class MultiplatformResourcesPublicationIT : KGPBaseTest() {
|
||||
|
||||
@DisplayName("Multiplatform resources publication for jvm target")
|
||||
@GradleAndroidTest
|
||||
fun testJvmResourcesPublication(
|
||||
gradleVersion: GradleVersion,
|
||||
androidVersion: String,
|
||||
providedJdk: JdkVersions.ProvidedJdk,
|
||||
) {
|
||||
testEmbeddedResources(
|
||||
gradleVersion,
|
||||
androidVersion,
|
||||
providedJdk,
|
||||
publicationTask = ":publishJvmPublicationToMavenRepository",
|
||||
publishedArchive = "build/repo/test/publication-jvm/1.0/publication-jvm-1.0.jar",
|
||||
reference = "jvm",
|
||||
)
|
||||
}
|
||||
|
||||
private fun testEmbeddedResources(
|
||||
gradleVersion: GradleVersion,
|
||||
androidVersion: String,
|
||||
providedJdk: JdkVersions.ProvidedJdk,
|
||||
publicationTask: String,
|
||||
publishedArchive: String,
|
||||
reference: String,
|
||||
) {
|
||||
project(
|
||||
"multiplatformResources/publication",
|
||||
gradleVersion,
|
||||
buildJdk = providedJdk.location,
|
||||
) {
|
||||
buildWithAGPVersion(
|
||||
publicationTask,
|
||||
androidVersion,
|
||||
)
|
||||
compareEmbeddedResources(
|
||||
publishedArchive,
|
||||
reference
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
private fun TestProject.buildWithAGPVersion(
|
||||
task: String,
|
||||
androidVersion: String,
|
||||
) {
|
||||
build(
|
||||
task,
|
||||
buildOptions = defaultBuildOptions.copy(androidVersion = androidVersion)
|
||||
)
|
||||
}
|
||||
|
||||
private fun TestProject.compareEmbeddedResources(
|
||||
inputZip: String,
|
||||
reference: String,
|
||||
) {
|
||||
val publishedResources = projectPath.resolve("published/${reference}")
|
||||
unzip(
|
||||
inputZip = inputZip,
|
||||
outputDir = publishedResources,
|
||||
filesStartingWith = "embed",
|
||||
)
|
||||
val referenceResources = projectPath.resolve("reference/$reference")
|
||||
assertDirectoryExists(publishedResources)
|
||||
assertDirectoryExists(referenceResources)
|
||||
assertEqualDirectories(
|
||||
publishedResources.toFile(),
|
||||
referenceResources.toFile(),
|
||||
forgiveExtraFiles = false,
|
||||
filter = { !it.name.startsWith(".") }
|
||||
)
|
||||
}
|
||||
|
||||
private fun TestProject.unzip(
|
||||
inputZip: String,
|
||||
outputDir: Path,
|
||||
filesStartingWith: String,
|
||||
) {
|
||||
ZipFile(projectPath.resolve(inputZip).toFile()).use {
|
||||
it.entries().asSequence().filter { it.name.startsWith(filesStartingWith) && !it.isDirectory }.forEach { entry ->
|
||||
val outputFile = outputDir.resolve(Paths.get(entry.name))
|
||||
if (!outputFile.parent.toFile().exists())
|
||||
Files.createDirectories(outputFile.parent)
|
||||
|
||||
it.getInputStream(entry).use { input ->
|
||||
Files.copy(input, outputFile, StandardCopyOption.REPLACE_EXISTING)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
+40
@@ -0,0 +1,40 @@
|
||||
@file:OptIn(ComposeKotlinGradlePluginApi::class)
|
||||
|
||||
import org.jetbrains.kotlin.gradle.ComposeKotlinGradlePluginApi
|
||||
import org.jetbrains.kotlin.gradle.plugin.mpp.resources.KotlinTargetResourcesPublication
|
||||
|
||||
group = "test"
|
||||
version = "1.0"
|
||||
|
||||
plugins {
|
||||
kotlin("multiplatform")
|
||||
`maven-publish`
|
||||
}
|
||||
|
||||
kotlin {
|
||||
val publication = project.ext.get(
|
||||
KotlinTargetResourcesPublication.EXTENSION_NAME
|
||||
) as KotlinTargetResourcesPublication
|
||||
|
||||
listOf(
|
||||
jvm(),
|
||||
).forEach { target ->
|
||||
publication.publishResourcesAsKotlinComponent(
|
||||
target,
|
||||
{ sourceSet ->
|
||||
KotlinTargetResourcesPublication.ResourceRoot(
|
||||
resourcesBaseDirectory = project.provider { project.file("src/${sourceSet.name}/multiplatformResources") },
|
||||
includes = emptyList(),
|
||||
excludes = emptyList()
|
||||
)
|
||||
},
|
||||
provider { File("embed/inside") }
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
publishing {
|
||||
repositories {
|
||||
maven("${buildDir}/repo")
|
||||
}
|
||||
}
|
||||
+1
@@ -0,0 +1 @@
|
||||
inCommon
|
||||
+1
@@ -0,0 +1 @@
|
||||
jvmOverride
|
||||
+1
@@ -0,0 +1 @@
|
||||
onlyInJvm
|
||||
+1
@@ -0,0 +1 @@
|
||||
package test
|
||||
+1
@@ -0,0 +1 @@
|
||||
inCommon
|
||||
+1
@@ -0,0 +1 @@
|
||||
platformOverride
|
||||
+1
@@ -0,0 +1 @@
|
||||
jvmOverride
|
||||
Reference in New Issue
Block a user