[Gradle] Add/update tests about Sources Publication in MPP
^KT-48839
This commit is contained in:
committed by
Space Team
parent
1fd779e7f4
commit
42cda2633d
+100
-4
@@ -20,6 +20,7 @@ import org.jetbrains.kotlin.gradle.testbase.*
|
|||||||
import org.jetbrains.kotlin.gradle.util.checkedReplace
|
import org.jetbrains.kotlin.gradle.util.checkedReplace
|
||||||
import org.jetbrains.kotlin.gradle.util.modify
|
import org.jetbrains.kotlin.gradle.util.modify
|
||||||
import org.junit.jupiter.api.DisplayName
|
import org.junit.jupiter.api.DisplayName
|
||||||
|
import org.junit.jupiter.api.condition.OS
|
||||||
import org.junit.jupiter.api.io.TempDir
|
import org.junit.jupiter.api.io.TempDir
|
||||||
import java.io.File
|
import java.io.File
|
||||||
import java.nio.file.Path
|
import java.nio.file.Path
|
||||||
@@ -357,11 +358,11 @@ class HierarchicalMppIT : KGPBaseTest() {
|
|||||||
"com/example/foo/my-lib-foo/1.0/my-lib-foo-1.0-sources.jar"
|
"com/example/foo/my-lib-foo/1.0/my-lib-foo-1.0-sources.jar"
|
||||||
)
|
)
|
||||||
).use { publishedSourcesJar ->
|
).use { publishedSourcesJar ->
|
||||||
publishedSourcesJar.checkAllEntryNamesArePresent(
|
publishedSourcesJar.checkExactEntries(
|
||||||
|
"META-INF/MANIFEST.MF",
|
||||||
"commonMain/Foo.kt",
|
"commonMain/Foo.kt",
|
||||||
"jvmAndJsMain/FooJvmAndJs.kt",
|
"jvmAndJsMain/FooJvmAndJs.kt",
|
||||||
"linuxAndJsMain/FooLinuxAndJs.kt",
|
"linuxAndJsMain/FooLinuxAndJs.kt",
|
||||||
"linuxX64Main/FooLinux.kt"
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -407,11 +408,11 @@ class HierarchicalMppIT : KGPBaseTest() {
|
|||||||
"com/example/bar/my-lib-bar/1.0/my-lib-bar-1.0-sources.jar"
|
"com/example/bar/my-lib-bar/1.0/my-lib-bar-1.0-sources.jar"
|
||||||
)
|
)
|
||||||
).use { publishedSourcesJar ->
|
).use { publishedSourcesJar ->
|
||||||
publishedSourcesJar.checkAllEntryNamesArePresent(
|
publishedSourcesJar.checkExactEntries(
|
||||||
|
"META-INF/MANIFEST.MF",
|
||||||
"commonMain/Bar.kt",
|
"commonMain/Bar.kt",
|
||||||
"jvmAndJsMain/BarJvmAndJs.kt",
|
"jvmAndJsMain/BarJvmAndJs.kt",
|
||||||
"linuxAndJsMain/BarLinuxAndJs.kt",
|
"linuxAndJsMain/BarLinuxAndJs.kt",
|
||||||
"linuxX64Main/BarLinux.kt"
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -583,6 +584,26 @@ class HierarchicalMppIT : KGPBaseTest() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun ZipFile.checkExactEntries(vararg expectedEntryNames: String, ignoreDirectories: Boolean = true) {
|
||||||
|
val entryNamesSet = entries()
|
||||||
|
.asSequence()
|
||||||
|
.map { it.name }
|
||||||
|
.run { if (ignoreDirectories) filterNot { it.endsWith("/") } else this }
|
||||||
|
.sorted()
|
||||||
|
.joinToString("\n")
|
||||||
|
val expectedEntryNamesSet = expectedEntryNames.toList().sorted().joinToString("\n")
|
||||||
|
assertEquals(expectedEntryNamesSet, entryNamesSet)
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun ZipFile.sourceSetDirectories(): List<String> {
|
||||||
|
return entries()
|
||||||
|
.asSequence()
|
||||||
|
.map { it.name.split("/").first() }
|
||||||
|
.toSet()
|
||||||
|
.minus("META-INF")
|
||||||
|
.toList()
|
||||||
|
}
|
||||||
|
|
||||||
private fun ZipFile.getProjectStructureMetadata(): KotlinProjectStructureMetadata {
|
private fun ZipFile.getProjectStructureMetadata(): KotlinProjectStructureMetadata {
|
||||||
val json = getInputStream(getEntry("META-INF/$MULTIPLATFORM_PROJECT_METADATA_JSON_FILE_NAME")).reader().readText()
|
val json = getInputStream(getEntry("META-INF/$MULTIPLATFORM_PROJECT_METADATA_JSON_FILE_NAME")).reader().readText()
|
||||||
return checkNotNull(parseKotlinSourceSetMetadataFromJson(json))
|
return checkNotNull(parseKotlinSourceSetMetadataFromJson(json))
|
||||||
@@ -689,6 +710,81 @@ class HierarchicalMppIT : KGPBaseTest() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@GradleTest
|
||||||
|
@OsCondition(enabledOnCI = [OS.LINUX, OS.MAC, OS.WINDOWS])
|
||||||
|
@DisplayName("Test sources publication of a multiplatform library")
|
||||||
|
fun testSourcesPublication(gradleVersion: GradleVersion, @TempDir tempDir: Path) {
|
||||||
|
project(
|
||||||
|
"mpp-sources-publication",
|
||||||
|
gradleVersion = gradleVersion,
|
||||||
|
localRepoDir = tempDir
|
||||||
|
).run {
|
||||||
|
build("publish")
|
||||||
|
|
||||||
|
fun macOnly(code: () -> List<String>): List<String> = if (OS.MAC.isCurrentOs) code() else emptyList()
|
||||||
|
|
||||||
|
val rootModuleSources = listOf("test/lib/1.0/lib-1.0-sources.jar")
|
||||||
|
val jvmModuleSources = listOf("test/lib-jvm/1.0/lib-jvm-1.0-sources.jar")
|
||||||
|
val jvm2ModuleSources = listOf("test/lib-jvm2/1.0/lib-jvm2-1.0-sources.jar")
|
||||||
|
val linuxX64ModuleSources = listOf("test/lib-linuxx64/1.0/lib-linuxx64-1.0-sources.jar")
|
||||||
|
val linuxArm64ModuleSources = listOf("test/lib-linuxarm64/1.0/lib-linuxarm64-1.0-sources.jar")
|
||||||
|
val iosX64ModuleSources = macOnly { listOf("test/lib-iosx64/1.0/lib-iosx64-1.0-sources.jar") }
|
||||||
|
val iosArm64ModuleSources = macOnly { listOf("test/lib-iosarm64/1.0/lib-iosarm64-1.0-sources.jar") }
|
||||||
|
val allPublishedSources = rootModuleSources +
|
||||||
|
jvmModuleSources + jvm2ModuleSources +
|
||||||
|
linuxX64ModuleSources + linuxArm64ModuleSources +
|
||||||
|
iosX64ModuleSources + iosArm64ModuleSources
|
||||||
|
|
||||||
|
infix fun Pair<String, List<String>>.and(that: List<String>) = first to (second + that)
|
||||||
|
|
||||||
|
// Here mentioned only source sets that should be published
|
||||||
|
val expectedSourcePublicationLayout = listOf(
|
||||||
|
"commonMain" to rootModuleSources
|
||||||
|
and jvmModuleSources and jvm2ModuleSources
|
||||||
|
and iosX64ModuleSources and iosArm64ModuleSources
|
||||||
|
and linuxArm64ModuleSources and linuxX64ModuleSources,
|
||||||
|
"linuxMain" to rootModuleSources and linuxArm64ModuleSources and linuxX64ModuleSources,
|
||||||
|
"jvmMain" to jvmModuleSources,
|
||||||
|
"jvm2Main" to jvm2ModuleSources,
|
||||||
|
// since commonJvmMain is compiled to JVM only, it doesn't appear it metadata variant,
|
||||||
|
// it should be published only to jvm variants
|
||||||
|
"commonJvmMain" to jvmModuleSources and jvm2ModuleSources,
|
||||||
|
// iosMain is a host-specific sourceset and even though it isn't present in common metadata artifact
|
||||||
|
// it should be published in common sources. more details: KT-54413
|
||||||
|
"iosMain" to rootModuleSources and iosX64ModuleSources and iosArm64ModuleSources,
|
||||||
|
"iosX64Main" to iosX64ModuleSources,
|
||||||
|
"iosArm64Main" to iosArm64ModuleSources,
|
||||||
|
"linuxX64Main" to linuxX64ModuleSources,
|
||||||
|
"linuxArm64Main" to linuxArm64ModuleSources,
|
||||||
|
)
|
||||||
|
|
||||||
|
val expectedSourcePublicationLayoutBySourcesFile: Map<String, List<String>> = expectedSourcePublicationLayout
|
||||||
|
.flatMap { (sourceSet, sources) -> sources.map { sourceSet to it } }
|
||||||
|
.groupBy(
|
||||||
|
keySelector = { it.second },
|
||||||
|
valueTransform = { it.first }
|
||||||
|
)
|
||||||
|
|
||||||
|
val actualSourcePublicationLayoutBySourcesFile: Map<String, List<String>> = allPublishedSources
|
||||||
|
.associateWith { jarPath ->
|
||||||
|
tempDir
|
||||||
|
.resolve(jarPath)
|
||||||
|
.toFile()
|
||||||
|
.let(::ZipFile)
|
||||||
|
.use { it.sourceSetDirectories() }
|
||||||
|
}
|
||||||
|
|
||||||
|
fun Map<String, List<String>>.stringifyForBeautifulDiff() = entries
|
||||||
|
.sortedBy { it.key }
|
||||||
|
.joinToString("\n") { "${it.key} => ${it.value.sorted()}" }
|
||||||
|
|
||||||
|
assertEquals(
|
||||||
|
expectedSourcePublicationLayoutBySourcesFile.stringifyForBeautifulDiff(),
|
||||||
|
actualSourcePublicationLayoutBySourcesFile.stringifyForBeautifulDiff()
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@GradleTest
|
@GradleTest
|
||||||
@DisplayName("KT-44845: all external dependencies is unresolved in IDE with kotlin.mpp.enableGranularSourceSetsMetadata=true")
|
@DisplayName("KT-44845: all external dependencies is unresolved in IDE with kotlin.mpp.enableGranularSourceSetsMetadata=true")
|
||||||
fun testMixedScopesFilesExistKt44845(gradleVersion: GradleVersion, @TempDir tempDir: Path) {
|
fun testMixedScopesFilesExistKt44845(gradleVersion: GradleVersion, @TempDir tempDir: Path) {
|
||||||
|
|||||||
+67
@@ -0,0 +1,67 @@
|
|||||||
|
plugins {
|
||||||
|
kotlin("multiplatform")
|
||||||
|
`maven-publish`
|
||||||
|
}
|
||||||
|
|
||||||
|
repositories {
|
||||||
|
mavenLocal()
|
||||||
|
mavenCentral()
|
||||||
|
}
|
||||||
|
|
||||||
|
group = "test"
|
||||||
|
version = "1.0"
|
||||||
|
|
||||||
|
kotlin {
|
||||||
|
val disambiguationAttribute = Attribute.of("disambiguationAttribute", String::class.java)
|
||||||
|
targets.all { attributes { attribute(disambiguationAttribute, targetName) } }
|
||||||
|
|
||||||
|
jvm {}
|
||||||
|
jvm("jvm2") {}
|
||||||
|
linuxX64 {}
|
||||||
|
linuxArm64 {}
|
||||||
|
ios()
|
||||||
|
|
||||||
|
sourceSets {
|
||||||
|
val commonMain by getting
|
||||||
|
val jvmMain by getting
|
||||||
|
val jvm2Main by getting
|
||||||
|
val linuxX64Main by getting
|
||||||
|
val linuxArm64Main by getting
|
||||||
|
|
||||||
|
val commonTest by getting
|
||||||
|
val jvmTest by getting
|
||||||
|
val jvm2Test by getting
|
||||||
|
val linuxX64Test by getting
|
||||||
|
val linuxArm64Test by getting
|
||||||
|
|
||||||
|
val linuxMain by creating {
|
||||||
|
dependsOn(commonMain)
|
||||||
|
linuxX64Main.dependsOn(this)
|
||||||
|
linuxArm64Main.dependsOn(this)
|
||||||
|
}
|
||||||
|
|
||||||
|
val linuxTest by creating {
|
||||||
|
dependsOn(commonTest)
|
||||||
|
linuxX64Test.dependsOn(this)
|
||||||
|
linuxArm64Test.dependsOn(this)
|
||||||
|
}
|
||||||
|
|
||||||
|
val commonJvmMain by creating {
|
||||||
|
dependsOn(commonMain)
|
||||||
|
jvmMain.dependsOn(this)
|
||||||
|
jvm2Main.dependsOn(this)
|
||||||
|
}
|
||||||
|
|
||||||
|
val commonJvmTest by creating {
|
||||||
|
dependsOn(commonTest)
|
||||||
|
jvmTest.dependsOn(this)
|
||||||
|
jvm2Test.dependsOn(this)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
publishing {
|
||||||
|
repositories {
|
||||||
|
maven("<localRepo>")
|
||||||
|
}
|
||||||
|
}
|
||||||
+14
@@ -0,0 +1,14 @@
|
|||||||
|
pluginManagement {
|
||||||
|
repositories {
|
||||||
|
mavenLocal()
|
||||||
|
gradlePluginPortal()
|
||||||
|
}
|
||||||
|
plugins {
|
||||||
|
val kotlin_version: String by settings
|
||||||
|
val test_fixes_version: String by settings
|
||||||
|
kotlin("multiplatform").version(kotlin_version)
|
||||||
|
id("org.jetbrains.kotlin.test.fixes.android") version test_fixes_version
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
rootProject.name = "lib"
|
||||||
+3
@@ -0,0 +1,3 @@
|
|||||||
|
package app
|
||||||
|
|
||||||
|
fun commonJvmMain() {}
|
||||||
+3
@@ -0,0 +1,3 @@
|
|||||||
|
package app
|
||||||
|
|
||||||
|
fun commonJvmTest() = "test"
|
||||||
+3
@@ -0,0 +1,3 @@
|
|||||||
|
package app
|
||||||
|
|
||||||
|
fun common() {}
|
||||||
+3
@@ -0,0 +1,3 @@
|
|||||||
|
package app
|
||||||
|
|
||||||
|
fun commonTest() {}
|
||||||
+3
@@ -0,0 +1,3 @@
|
|||||||
|
package app
|
||||||
|
|
||||||
|
fun iosArm64() {}
|
||||||
+3
@@ -0,0 +1,3 @@
|
|||||||
|
package app
|
||||||
|
|
||||||
|
fun iosArm64Test() = "test"
|
||||||
+3
@@ -0,0 +1,3 @@
|
|||||||
|
package app
|
||||||
|
|
||||||
|
fun ios() {}
|
||||||
+3
@@ -0,0 +1,3 @@
|
|||||||
|
package app
|
||||||
|
|
||||||
|
fun iosTest() = "test"
|
||||||
+3
@@ -0,0 +1,3 @@
|
|||||||
|
package app
|
||||||
|
|
||||||
|
fun iosX64() {}
|
||||||
+3
@@ -0,0 +1,3 @@
|
|||||||
|
package app
|
||||||
|
|
||||||
|
fun iosX64Test() = "test"
|
||||||
+3
@@ -0,0 +1,3 @@
|
|||||||
|
package app
|
||||||
|
|
||||||
|
fun jvm2Main() {}
|
||||||
+3
@@ -0,0 +1,3 @@
|
|||||||
|
package app
|
||||||
|
|
||||||
|
fun jvm2Test() = "test"
|
||||||
+3
@@ -0,0 +1,3 @@
|
|||||||
|
package app
|
||||||
|
|
||||||
|
fun jvmMain() {}
|
||||||
+3
@@ -0,0 +1,3 @@
|
|||||||
|
package app
|
||||||
|
|
||||||
|
fun jvmTest() = "test"
|
||||||
+3
@@ -0,0 +1,3 @@
|
|||||||
|
package app
|
||||||
|
|
||||||
|
fun linuxArm64Main() {}
|
||||||
+3
@@ -0,0 +1,3 @@
|
|||||||
|
package app
|
||||||
|
|
||||||
|
fun linuxArm64Test() = "test"
|
||||||
+3
@@ -0,0 +1,3 @@
|
|||||||
|
package app
|
||||||
|
|
||||||
|
fun linuxMain() {}
|
||||||
+3
@@ -0,0 +1,3 @@
|
|||||||
|
package app
|
||||||
|
|
||||||
|
fun linuxTest() = "test"
|
||||||
+3
@@ -0,0 +1,3 @@
|
|||||||
|
package app
|
||||||
|
|
||||||
|
fun linuxX64Main() {}
|
||||||
+11
@@ -0,0 +1,11 @@
|
|||||||
|
package app
|
||||||
|
|
||||||
|
import kotlin.test.Test
|
||||||
|
import kotlin.test.assertEquals
|
||||||
|
|
||||||
|
class LinuxX64Text {
|
||||||
|
@Test
|
||||||
|
fun test1() {
|
||||||
|
assertEquals(cinterop.dummy.foo_linux(), 42)
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user