[Build] Fix deprecation warnings in KGP integration tests

This commit is contained in:
Alexander Likhachev
2022-04-19 20:50:43 +03:00
committed by Space
parent 19a76fa16d
commit 41daf39000
12 changed files with 121 additions and 41 deletions
@@ -18,6 +18,7 @@ import org.junit.rules.TemporaryFolder
import org.junit.runner.RunWith
import org.junit.runners.Parameterized
import java.io.File
import java.util.*
import kotlin.test.assertTrue
import java.lang.Boolean as RefBoolean
@@ -253,8 +254,13 @@ abstract class AndroidAndJavaConsumeMppLibIT : BaseGradleIT() {
"debugApiElements$variantNamePublishedSuffix"
else "releaseApiElements$variantNamePublishedSuffix"
@Suppress("DEPRECATION")
fun nameWithFlavorIfNeeded(name: String) = if (useFlavors) "flavor1${name.capitalize()}" else name
fun nameWithFlavorIfNeeded(name: String) = if (useFlavors) "flavor1${
name.replaceFirstChar {
if (it.isLowerCase()) it.titlecase(
Locale.getDefault()
) else it.toString()
}
}" else name
val configurationToExpectedVariant = listOf(
nameWithFlavorIfNeeded("debugCompileClasspath") to nameWithFlavorIfNeeded("debugApiElements$variantNamePublishedSuffix"),
@@ -28,8 +28,10 @@ import org.junit.Before
import org.junit.runner.RunWith
import java.io.File
import java.nio.file.Files
import java.util.*
import java.util.regex.Pattern
import javax.xml.parsers.DocumentBuilderFactory
import kotlin.collections.HashSet
import kotlin.io.path.isDirectory
import kotlin.test.*
@@ -489,7 +491,7 @@ abstract class BaseGradleIT {
}
fun CompiledProject.assertClassFilesNotContain(dir: File, vararg strings: String) {
val classFiles = dir.walk().filter { it.isFile && it.extension.toLowerCase() == "class" }
val classFiles = dir.walk().filter { it.isFile && it.extension.lowercase(Locale.getDefault()) == "class" }
for (cf in classFiles) {
checkBytecodeNotContains(cf, strings.toList())
@@ -853,7 +855,7 @@ Finished executing task ':$taskName'|
// see https://docs.gradle.org/current/userguide/logging.html#sec:choosing_a_log_level
LogLevel.LIFECYCLE -> Unit
//Command line option for other log levels
else -> add("--${minLogLevel.name.toLowerCase()}")
else -> add("--${minLogLevel.name.lowercase(Locale.getDefault())}")
}
if (options.daemonOptionSupported) {
add(if (options.withDaemon) "--daemon" else "--no-daemon")
@@ -931,7 +933,7 @@ Finished executing task ':$taskName'|
}
add("-Dorg.gradle.unsafe.configuration-cache=${options.configurationCache}")
add("-Dorg.gradle.unsafe.configuration-cache-problems=${options.configurationCacheProblems.name.toLowerCase()}")
add("-Dorg.gradle.unsafe.configuration-cache-problems=${options.configurationCacheProblems.name.lowercase(Locale.getDefault())}")
// Workaround: override a console type set in the user machine gradle.properties (since Gradle 4.3):
add("--console=plain")
@@ -943,7 +945,7 @@ Finished executing task ':$taskName'|
val notUsingAgpWithWarnings =
options.androidGradlePluginVersion == null || options.androidGradlePluginVersion > AGPVersion.v3_6_0
if (supportFailingBuildOnWarning && notUsingAgpWithWarnings && options.warningMode == WarningMode.Fail) {
add("--warning-mode=${WarningMode.Fail.name.toLowerCase()}")
add("--warning-mode=${WarningMode.Fail.name.lowercase(Locale.getDefault())}")
}
addAll(options.freeCommandLineArgs)
}
@@ -8,6 +8,7 @@ package org.jetbrains.kotlin.gradle
import org.jetbrains.kotlin.gradle.util.modify
import org.jetbrains.kotlin.konan.target.HostManager
import java.io.File
import java.util.*
import java.util.zip.ZipFile
import kotlin.test.Test
import kotlin.test.assertFalse
@@ -88,7 +89,7 @@ class KlibBasedMppIT : BaseGradleIT() {
// The consumer should correctly receive the klibs of the host-specific source sets
checkTaskCompileClasspath(
"compile${hostSpecificSourceSet.capitalize()}KotlinMetadata",
"compile${hostSpecificSourceSet.replaceFirstChar { if (it.isLowerCase()) it.titlecase(Locale.getDefault()) else it.toString() }}KotlinMetadata",
listOf(
"published-producer-$hostSpecificSourceSet.klib",
"published-producer-commonMain.klib",
@@ -163,7 +164,7 @@ class KlibBasedMppIT : BaseGradleIT() {
val tasksToExecute = listOf(
":compileJvmAndJsMainKotlinMetadata",
":compileLinuxMainKotlinMetadata",
":compile${hostSpecificSourceSet.capitalize()}KotlinMetadata"
":compile${hostSpecificSourceSet.replaceFirstChar { if (it.isLowerCase()) it.titlecase(Locale.getDefault()) else it.toString() }}KotlinMetadata"
)
build("assemble") {
@@ -201,7 +202,14 @@ class KlibBasedMppIT : BaseGradleIT() {
private fun checkPublishedHostSpecificMetadata(compiledProject: CompiledProject) = with(compiledProject) {
val groupDir = project.projectDir.resolve("repo/com/example")
assertTasksExecuted(":$dependencyModuleName:compile${hostSpecificSourceSet.capitalize()}KotlinMetadata")
assertTasksExecuted(
":$dependencyModuleName:compile${
hostSpecificSourceSet.replaceFirstChar {
if (it.isLowerCase()) it.titlecase(
Locale.getDefault()
) else it.toString()
}
}KotlinMetadata")
// Check that the metadata JAR doesn't contain the host-specific source set entries, but contains the shared-Native source set
// that can be built on every host:
@@ -222,7 +230,7 @@ class KlibBasedMppIT : BaseGradleIT() {
}
hostSpecificTargets.forEach { targetName ->
val moduleName = "$dependencyModuleName-${targetName.toLowerCase()}"
val moduleName = "$dependencyModuleName-${targetName.lowercase(Locale.getDefault())}"
ZipFile(groupDir.resolve("$moduleName/1.0/$moduleName-1.0-metadata.jar")).use { metadataJar ->
assertTrue { metadataJar.entries().asSequence().any { it.name.startsWith(hostSpecificSourceSet) } }
assertTrue { metadataJar.entries().asSequence().none { it.name.startsWith("commonMain") } }
@@ -12,6 +12,7 @@ import org.junit.Test
import org.junit.runner.RunWith
import org.junit.runners.Parameterized
import java.io.File
import java.util.*
@RunWith(Parameterized::class)
class MppHighlightingTestDataWithGradleIT : BaseGradleIT() {
@@ -88,7 +89,7 @@ class MppHighlightingTestDataWithGradleIT : BaseGradleIT() {
gradleBuildScript().appendText("\n" + scriptCustomization)
val tasks = sourceRoots.map { "compile" + it.kotlinSourceSetName.capitalize() + "KotlinMetadata" }
val tasks = sourceRoots.map { "compile" + it.kotlinSourceSetName.replaceFirstChar { if (it.isLowerCase()) it.titlecase(Locale.getDefault()) else it.toString() } + "KotlinMetadata" }
build(*tasks.toTypedArray()) {
if (expectedErrorsPerSourceSetName.values.all { it.all(ErrorInfo::isAllowedInCli) }) {
@@ -176,7 +177,7 @@ class MppHighlightingTestDataWithGradleIT : BaseGradleIT() {
get() = partsToQualifiedName(qualifiedNameParts)
val kotlinSourceSetName
get() = "intermediate${qualifiedName.capitalize()}"
get() = "intermediate${qualifiedName.replaceFirstChar { if (it.isLowerCase()) it.titlecase(Locale.getDefault()) else it.toString() }}"
val gradleSrcDir
get() = "src/$kotlinSourceSetName/kotlin"
@@ -30,6 +30,7 @@ import org.jetbrains.kotlin.gradle.util.modify
import org.jetbrains.kotlin.test.util.KtTestUtil
import org.junit.Test
import java.io.File
import java.util.*
import kotlin.test.assertTrue
@TestDataPath("\$CONTENT_ROOT/resources")
@@ -307,7 +308,7 @@ class MultiplatformGradleIT : BaseGradleIT() {
}
val customSourceSetCompileTasks = listOf(":lib" to "Common", ":libJs" to "2Js", ":libJvm" to "")
.map { (module, platform) -> "$module:compile${sourceSetName.capitalize()}Kotlin$platform" }
.map { (module, platform) -> "$module:compile${sourceSetName.replaceFirstChar { if (it.isLowerCase()) it.titlecase(Locale.getDefault()) else it.toString() }}Kotlin$platform" }
build(*customSourceSetCompileTasks.toTypedArray(), options = defaultBuildOptions().copy(warningMode = WarningMode.Summary)) {
assertSuccessful()
@@ -327,8 +327,8 @@ class NewMultiplatformIT : BaseGradleIT() {
arrayOf("NodeJs")
} else {
arrayOf(
"NodeJs${LEGACY.lowerName.capitalize()}",
"NodeJs${IR.lowerName.capitalize()}",
"NodeJs${LEGACY.lowerName.replaceFirstChar { if (it.isLowerCase()) it.titlecase(Locale.getDefault()) else it.toString() }}",
"NodeJs${IR.lowerName.replaceFirstChar { if (it.isLowerCase()) it.titlecase(Locale.getDefault()) else it.toString() }}",
)
}),
).map { ":compileKotlin$it" }
@@ -580,7 +580,7 @@ class NewMultiplatformIT : BaseGradleIT() {
)
fun javaSourceRootForCompilation(compilationName: String) =
if (testJavaSupportInJvmTargets) "src/jvm6${compilationName.capitalize()}/java" else "src/$compilationName/java"
if (testJavaSupportInJvmTargets) "src/jvm6${compilationName.replaceFirstChar { if (it.isLowerCase()) it.titlecase(Locale.getDefault()) else it.toString() }}/java" else "src/$compilationName/java"
val javaMainSrcDir = javaSourceRootForCompilation("main")
val javaTestSrcDir = javaSourceRootForCompilation("test")
@@ -1524,7 +1524,8 @@ class NewMultiplatformIT : BaseGradleIT() {
"jvm6", "nodeJs", "mingw64", "mingw86", "linux64", "macos64", "linuxMipsel32", "wasm"
).flatMapTo(mutableSetOf()) { target ->
listOf("main", "test").map { compilation ->
Triple(target, compilation, "$target${compilation.capitalize()}")
Triple(target, compilation,
"$target${compilation.replaceFirstChar { if (it.isLowerCase()) it.titlecase(Locale.getDefault()) else it.toString() }}")
}
} + Triple("metadata", "main", "commonMain")
@@ -1738,7 +1739,14 @@ class NewMultiplatformIT : BaseGradleIT() {
setupWorkingDir()
gradleBuildScript().modify(::transformBuildScriptWithPluginsDsl)
val tasks = listOf("jvm", "js", "linux64").map { ":compileIntegrationTestKotlin${it.capitalize()}" }
val tasks = listOf("jvm", "js", "linux64").map {
":compileIntegrationTestKotlin${
it.replaceFirstChar {
if (it.isLowerCase()) it.titlecase(
Locale.getDefault()
) else it.toString()
}
}" }
build(
*tasks.toTypedArray()
@@ -1788,7 +1796,7 @@ class NewMultiplatformIT : BaseGradleIT() {
assertTasksExecuted(
*testTasks,
":compileIntegrationTestKotlinJvm",
":linkIntegrationDebugTest${nativeHostTargetName.capitalize()}"
":linkIntegrationDebugTest${nativeHostTargetName.replaceFirstChar { if (it.isLowerCase()) it.titlecase(Locale.getDefault()) else it.toString() }}"
)
fun checkUnitTestOutput(targetName: String) {
@@ -27,6 +27,7 @@ import org.junit.BeforeClass
import org.junit.Test
import java.io.File
import java.io.IOException
import java.util.*
import java.util.concurrent.TimeUnit
import kotlin.test.assertEquals
import kotlin.test.assertTrue
@@ -84,20 +85,35 @@ class CocoaPodsIT : BaseGradleIT() {
private val defaultBuildTaskName = podBuildFullTaskName()
private val defaultSetupBuildTaskName = podSetupBuildFullTaskName()
private val defaultCinteropTaskName = cinteropTaskName + defaultPodName + defaultTarget
private val downloadUrlTaskName = podDownloadTaskName + downloadUrlPodName.capitalize()
private val downloadUrlTaskName =
podDownloadTaskName + downloadUrlPodName.replaceFirstChar { if (it.isLowerCase()) it.titlecase(Locale.getDefault()) else it.toString() }
private fun podDownloadFullTaskName(podName: String = defaultPodName) = podDownloadTaskName + podName.capitalize()
private fun podDownloadFullTaskName(podName: String = defaultPodName) =
podDownloadTaskName + podName.replaceFirstChar { if (it.isLowerCase()) it.titlecase(Locale.getDefault()) else it.toString() }
private fun podGenFullTaskName(familyName: String = defaultFamily) = podGenTaskName + familyName.capitalize()
private fun podGenFullTaskName(familyName: String = defaultFamily) =
podGenTaskName + familyName.replaceFirstChar { if (it.isLowerCase()) it.titlecase(Locale.getDefault()) else it.toString() }
private fun podSetupBuildFullTaskName(podName: String = defaultPodName, sdkName: String = defaultSDK) =
podSetupBuildTaskName + podName.capitalize() + sdkName.capitalize()
podSetupBuildTaskName + podName.replaceFirstChar { if (it.isLowerCase()) it.titlecase(Locale.getDefault()) else it.toString() } + sdkName.replaceFirstChar {
if (it.isLowerCase()) it.titlecase(
Locale.getDefault()
) else it.toString()
}
private fun podBuildFullTaskName(podName: String = defaultPodName, sdkName: String = defaultSDK) =
podBuildTaskName + podName.capitalize() + sdkName.capitalize()
podBuildTaskName + podName.replaceFirstChar { if (it.isLowerCase()) it.titlecase(Locale.getDefault()) else it.toString() } + sdkName.replaceFirstChar {
if (it.isLowerCase()) it.titlecase(
Locale.getDefault()
) else it.toString()
}
private fun cinteropFullTaskName(podName: String = defaultPodName, targetName: String = defaultTarget) =
cinteropTaskName + podName.capitalize() + targetName.capitalize()
cinteropTaskName + podName.replaceFirstChar { if (it.isLowerCase()) it.titlecase(Locale.getDefault()) else it.toString() } + targetName.replaceFirstChar {
if (it.isLowerCase()) it.titlecase(
Locale.getDefault()
) else it.toString()
}
private lateinit var hooks: CustomHooks
private lateinit var project: BaseGradleIT.Project
@@ -472,7 +488,7 @@ class CocoaPodsIT : BaseGradleIT() {
val anotherSdk = "macosx"
val anotherFamily = "OSX"
with(project.gradleBuildScript()) {
appendToKotlinBlock(anotherTarget.decapitalize() + "()")
appendToKotlinBlock(anotherTarget.replaceFirstChar { it.lowercase(Locale.getDefault()) } + "()")
}
hooks.rewriteHooks {
assertTasksExecuted(
@@ -494,7 +510,7 @@ class CocoaPodsIT : BaseGradleIT() {
with(project.gradleBuildScript()) {
var text = readText()
text = text.replace(anotherTarget.decapitalize() + "()", "")
text = text.replace(anotherTarget.replaceFirstChar { it.lowercase(Locale.getDefault()) } + "()", "")
writeText(text)
}
hooks.rewriteHooks {
@@ -636,7 +652,7 @@ class CocoaPodsIT : BaseGradleIT() {
val anotherSdk = "macosx"
with(project.gradleBuildScript()) {
appendToCocoapodsBlock("osx.deploymentTarget = \"10.15\"")
appendToKotlinBlock(anotherTarget.decapitalize() + "()")
appendToKotlinBlock(anotherTarget.replaceFirstChar { it.lowercase(Locale.getDefault()) } + "()")
}
val anotherSdkDefaultPodTaskName = podBuildFullTaskName(sdkName = anotherSdk)
val anotherTargetUrlTaskName = podBuildFullTaskName(downloadUrlPodName, anotherSdk)
@@ -12,6 +12,7 @@ import org.jetbrains.kotlin.konan.target.HostManager
import org.junit.Assume
import org.junit.BeforeClass
import org.junit.Test
import java.util.*
class CommonNativeIT : BaseGradleIT() {
@@ -27,10 +28,17 @@ class CommonNativeIT : BaseGradleIT() {
configureJvmMemory()
}
val libCompileTasks = libTargets.map { ":lib:compileKotlin${it.capitalize()}" }
val appCompileTasks = appTargets.map { ":app:compileKotlin${it.capitalize()}" }
val appLinkFrameworkTasks = appTargets.map { ":app:linkDebugFramework${it.capitalize()}" }
val appLinkTestTasks = appTargets.map { ":app:linkDebugTest${it.capitalize()}" }
val libCompileTasks = libTargets.map { ":lib:compileKotlin${it.replaceFirstChar { if (it.isLowerCase()) it.titlecase(Locale.getDefault()) else it.toString() }}" }
val appCompileTasks = appTargets.map { ":app:compileKotlin${it.replaceFirstChar { if (it.isLowerCase()) it.titlecase(Locale.getDefault()) else it.toString() }}" }
val appLinkFrameworkTasks = appTargets.map {
":app:linkDebugFramework${
it.replaceFirstChar {
if (it.isLowerCase()) it.titlecase(
Locale.getDefault()
) else it.toString()
}
}" }
val appLinkTestTasks = appTargets.map { ":app:linkDebugTest${it.replaceFirstChar { if (it.isLowerCase()) it.titlecase(Locale.getDefault()) else it.toString() }}" }
build(":lib:publish") {
assertSuccessful()
@@ -13,6 +13,7 @@ import org.jetbrains.kotlin.konan.target.HostManager
import org.junit.Assume
import org.junit.BeforeClass
import org.junit.Test
import java.util.*
import kotlin.test.assertTrue
class FatFrameworkIT : BaseGradleIT() {
@@ -76,7 +77,14 @@ class FatFrameworkIT : BaseGradleIT() {
expectedPlistPlatform: String
) {
assertSuccessful()
val linkTasks = archs.map { ":linkDebugFramework${targetPrefix.capitalize()}${it.capitalize()}" }
val linkTasks = archs.map {
":linkDebugFramework${targetPrefix.replaceFirstChar { if (it.isLowerCase()) it.titlecase(Locale.getDefault()) else it.toString() }}${
it.replaceFirstChar {
if (it.isLowerCase()) it.titlecase(
Locale.getDefault()
) else it.toString()
}
}" }
assertTasksExecuted(linkTasks)
assertTasksExecuted(":fat")
@@ -351,8 +351,20 @@ class GeneralNativeIT : BaseGradleIT() {
val frameworkTasks = targets.flatMap { target ->
binaries.getValue(target).flatMap {
listOf(
":link${it.name.capitalize()}DebugFramework${target.capitalize()}",
":link${it.name.capitalize()}ReleaseFramework${target.capitalize()}",
":link${it.name.replaceFirstChar { if (it.isLowerCase()) it.titlecase(Locale.getDefault()) else it.toString() }}DebugFramework${
target.replaceFirstChar {
if (it.isLowerCase()) it.titlecase(
Locale.getDefault()
) else it.toString()
}
}",
":link${it.name.replaceFirstChar { if (it.isLowerCase()) it.titlecase(Locale.getDefault()) else it.toString() }}ReleaseFramework${
target.replaceFirstChar {
if (it.isLowerCase()) it.titlecase(
Locale.getDefault()
) else it.toString()
}
}",
)
}
}
@@ -454,7 +466,7 @@ class GeneralNativeIT : BaseGradleIT() {
"releaseExecutable" to "native-binary",
"bazDebugExecutable" to "my-baz",
)
val linkTasks = binaries.map { (name, _) -> "link${name.capitalize()}Host" }
val linkTasks = binaries.map { (name, _) -> "link${name.replaceFirstChar { if (it.isLowerCase()) it.titlecase(Locale.getDefault()) else it.toString() }}Host" }
val outputFiles = binaries.map { (name, fileBaseName) ->
val outputKind = NativeOutputKind.values().single { name.endsWith(it.taskNameClassifier, true) }.compilerOutputKind
val prefix = outputKind.prefix(HostManager.host)
@@ -501,7 +513,8 @@ class GeneralNativeIT : BaseGradleIT() {
private fun testNativeBinaryDsl(project: String) = with(
transformNativeTestProjectWithPluginDsl(project, directoryPrefix = "native-binaries")
) {
val hostSuffix = nativeHostTargetName.capitalize()
val hostSuffix =
nativeHostTargetName.replaceFirstChar { if (it.isLowerCase()) it.titlecase(Locale.getDefault()) else it.toString() }
build("tasks") {
assertSuccessful()
@@ -972,9 +985,16 @@ class GeneralNativeIT : BaseGradleIT() {
.resolve("B.kt")
fileWithSpacesInPath.writeText("fun foo() = 42")
build("compileKotlin${nativeHostTargetName.capitalize()}") {
build("compileKotlin${nativeHostTargetName.replaceFirstChar { if (it.isLowerCase()) it.titlecase(Locale.getDefault()) else it.toString() }}") {
assertSuccessful()
withNativeCommandLineArguments(":compileKotlin${nativeHostTargetName.capitalize()}") { arguments ->
withNativeCommandLineArguments(
":compileKotlin${
nativeHostTargetName.replaceFirstChar {
if (it.isLowerCase()) it.titlecase(
Locale.getDefault()
) else it.toString()
}
}") { arguments ->
val escapedQuotedPath =
"\"${fileWithSpacesInPath.absolutePath.replace("\\", "\\\\").replace("\"", "\\\"")}\""
assertTrue(
@@ -12,6 +12,7 @@ import org.jetbrains.kotlin.konan.target.KonanTarget
import org.junit.Assume.assumeFalse
import org.junit.Test
import java.io.File
import java.util.*
import kotlin.test.assertEquals
import kotlin.test.assertNotNull
import kotlin.test.assertNull
@@ -171,6 +172,6 @@ class NativeExternalDependenciesIT : BaseGradleIT() {
fun findKotlinNativeTargetName(output: String): String? = findParameterInOutput("for_test_kotlin_native_target", output)
?.takeIf(String::isNotBlank)
?.toLowerCase()
?.lowercase(Locale.getDefault())
}
}
@@ -12,6 +12,7 @@ import org.jetbrains.kotlin.cli.common.CompilerSystemProperties.COMPILE_INCREMEN
import org.jetbrains.kotlin.gradle.BaseGradleIT
import org.jetbrains.kotlin.gradle.plugin.KotlinJsCompilerType
import org.jetbrains.kotlin.gradle.report.BuildReportType
import java.util.*
data class BuildOptions(
val logLevel: LogLevel = LogLevel.INFO,
@@ -70,7 +71,7 @@ data class BuildOptions(
if (gradleVersion >= GradleVersion.version("6.6.0")) {
arguments.add("-Dorg.gradle.unsafe.configuration-cache=$configurationCache")
arguments.add("-Dorg.gradle.unsafe.configuration-cache-problems=${configurationCacheProblems.name.toLowerCase()}")
arguments.add("-Dorg.gradle.unsafe.configuration-cache-problems=${configurationCacheProblems.name.lowercase(Locale.getDefault())}")
}
if (gradleVersion >= GradleVersion.version("7.1")) {
arguments.add("-Dorg.gradle.unsafe.isolated-projects=$projectIsolation")