From 82d28b6dbf17977fea00a75633aa516a257c71e1 Mon Sep 17 00:00:00 2001 From: Pavel Punegov Date: Mon, 26 Sep 2022 17:59:27 +0200 Subject: [PATCH] [K/N][gradle][test] Tests KGP ability to download artifacts from maven --- .../kotlin/gradle/native/NativeDownloadIT.kt | 123 ++++++++++++++++++ .../native-download-maven/build.gradle.kts | 26 ++++ .../native-download-maven/gradle.properties | 1 + .../src/nativeMain/kotlin/main.kt | 10 ++ 4 files changed, 160 insertions(+) create mode 100644 libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/kotlin/org/jetbrains/kotlin/gradle/native/NativeDownloadIT.kt create mode 100644 libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/native-download-maven/build.gradle.kts create mode 100644 libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/native-download-maven/gradle.properties create mode 100644 libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/native-download-maven/src/nativeMain/kotlin/main.kt diff --git a/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/kotlin/org/jetbrains/kotlin/gradle/native/NativeDownloadIT.kt b/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/kotlin/org/jetbrains/kotlin/gradle/native/NativeDownloadIT.kt new file mode 100644 index 00000000000..beee8575d21 --- /dev/null +++ b/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/kotlin/org/jetbrains/kotlin/gradle/native/NativeDownloadIT.kt @@ -0,0 +1,123 @@ +/* + * Copyright 2010-2022 JetBrains s.r.o. and Kotlin Programming Language contributors. + * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. + */ + +package org.jetbrains.kotlin.gradle.native + +import org.jetbrains.kotlin.gradle.BaseGradleIT +import org.jetbrains.kotlin.gradle.GradleVersionRequired +import org.jetbrains.kotlin.gradle.utils.NativeCompilerDownloader +import org.jetbrains.kotlin.konan.MetaVersion +import org.jetbrains.kotlin.konan.target.HostManager +import org.jetbrains.kotlin.konan.util.DependencyDirectories + +import kotlin.test.BeforeTest +import kotlin.test.Test + +class NativeDownloadIT : BaseGradleIT() { + override val defaultGradleVersion = GradleVersionRequired.FOR_MPP_SUPPORT + + private val currentCompilerVersion = NativeCompilerDownloader.DEFAULT_KONAN_VERSION + + companion object { + private const val KOTLIN_SPACE_DEV = "https://cache-redirector.jetbrains.com/maven.pkg.jetbrains.space/kotlin/p/kotlin/dev" + private const val MAVEN_CENTRAL = "https://cache-redirector.jetbrains.com/maven-central" + } + + private fun mavenUrl(): String = when (currentCompilerVersion.meta) { + MetaVersion.DEV -> KOTLIN_SPACE_DEV + MetaVersion.RELEASE, MetaVersion.RC, MetaVersion("RC2"), MetaVersion.BETA -> MAVEN_CENTRAL + else -> throw IllegalStateException("Not a published version $currentCompilerVersion") + } + + @BeforeTest + fun deleteInstalledDistributions() { + val currentOsName = HostManager.platformName() + val lightDistDir = DependencyDirectories.localKonanDir + .resolve("kotlin-native-$currentOsName-$currentCompilerVersion") + val prebuiltDistDir = DependencyDirectories.localKonanDir + .resolve("kotlin-native-prebuilt-$currentOsName-$currentCompilerVersion") + + listOf(lightDistDir, prebuiltDistDir).forEach { + it.deleteRecursively() + } + } + + @Test + fun `download prebuilt Native bundle with maven`() { + with(transformNativeTestProjectWithPluginDsl("native-download-maven")) { + gradleProperties().appendText( + """ + kotlin.native.distribution.baseDownloadUrl=${mavenUrl()} + kotlin.native.distribution.downloadFromMaven=true + """.trimIndent() + ) + build("assemble") { + assertSuccessful() + assertContains("Unpack Kotlin/Native compiler to ") + assertNotContains("Generate platform libraries for ") + } + } + } + + @Test + fun `download light Native bundle with maven`() { + with(transformNativeTestProjectWithPluginDsl("native-download-maven")) { + gradleProperties().appendText( + """ + kotlin.native.distribution.baseDownloadUrl=${mavenUrl()} + kotlin.native.distribution.downloadFromMaven=true + """.trimIndent() + ) + build("assemble", "-Pkotlin.native.distribution.type=light") { + assertSuccessful() + assertContains("Unpack Kotlin/Native compiler to ") + assertContains("Generate platform libraries for ") + } + } + } + + @Test + fun `download from maven specified in the build`() { + with(transformNativeTestProjectWithPluginDsl("native-download-maven")) { + gradleProperties().appendText( + """ + kotlin.native.distribution.downloadFromMaven=true + """.trimIndent() + ) + gradleBuildScript().let { + val text = it.readText() + .replaceFirst( + "mavenLocal()", + """ + mavenLocal() + maven("${mavenUrl()}") + """.trimIndent() + ) + it.writeText(text) + } + + build("assemble") { + assertSuccessful() + assertContains("Unpack Kotlin/Native compiler to ") + } + } + } + + @Test + fun `download from maven should fall if there is no such build in the default repos`() { + with(transformNativeTestProjectWithPluginDsl("native-download-maven")) { + gradleProperties().appendText( + """ + kotlin.native.version=1.8.0-dev-1234 + kotlin.native.distribution.downloadFromMaven=true + """.trimIndent() + ) + build("assemble") { + assertContains("Could not find org.jetbrains.kotlin:kotlin-native") + assertFailed() + } + } + } +} \ No newline at end of file diff --git a/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/native-download-maven/build.gradle.kts b/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/native-download-maven/build.gradle.kts new file mode 100644 index 00000000000..0a0d7f04710 --- /dev/null +++ b/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/native-download-maven/build.gradle.kts @@ -0,0 +1,26 @@ +import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeTarget + +plugins { + kotlin("multiplatform").version("") +} + +repositories { + mavenLocal() + mavenCentral() +} + +kotlin { + val nativeMain by sourceSets.creating { + dependsOn(sourceSets["commonMain"]) + } + + targets.withType(KotlinNativeTarget::class.java).all { + compilations["main"].defaultSourceSet.dependsOn(nativeMain) + } + + ("host") { + binaries { + executable() + } + } +} \ No newline at end of file diff --git a/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/native-download-maven/gradle.properties b/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/native-download-maven/gradle.properties new file mode 100644 index 00000000000..72c70cc086e --- /dev/null +++ b/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/native-download-maven/gradle.properties @@ -0,0 +1 @@ +kotlin.native.cacheKind=none \ No newline at end of file diff --git a/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/native-download-maven/src/nativeMain/kotlin/main.kt b/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/native-download-maven/src/nativeMain/kotlin/main.kt new file mode 100644 index 00000000000..043d37542ad --- /dev/null +++ b/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/native-download-maven/src/nativeMain/kotlin/main.kt @@ -0,0 +1,10 @@ +/* + * Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors. + * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. + */ + +import platform.posix.* + +fun main() { + printf("Hello world %d", 42) +} \ No newline at end of file