Minor: code cleanup

KT-55530
This commit is contained in:
Pavel Kirpichenkov
2022-12-27 18:54:46 +02:00
committed by Space Team
parent cee5d568a5
commit f92558d1c3
23 changed files with 49 additions and 51 deletions
@@ -8,7 +8,6 @@
package org.jetbrains.kotlin.gradle.ide.tcs package org.jetbrains.kotlin.gradle.ide.tcs
import org.gradle.api.Project import org.gradle.api.Project
import org.jetbrains.kotlin.gradle.*
import org.jetbrains.kotlin.gradle.dsl.multiplatformExtension import org.jetbrains.kotlin.gradle.dsl.multiplatformExtension
import org.jetbrains.kotlin.gradle.idea.tcs.IdeaKotlinBinaryDependency import org.jetbrains.kotlin.gradle.idea.tcs.IdeaKotlinBinaryDependency
import org.jetbrains.kotlin.gradle.idea.tcs.IdeaKotlinDependency import org.jetbrains.kotlin.gradle.idea.tcs.IdeaKotlinDependency
@@ -3,7 +3,7 @@
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/ */
@file:Suppress("FunctionName") @file:Suppress("FunctionName", "DuplicatedCode")
package org.jetbrains.kotlin.gradle.ide.tcs package org.jetbrains.kotlin.gradle.ide.tcs
@@ -3,6 +3,8 @@
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/ */
@file:Suppress("FunctionName")
package org.jetbrains.kotlin.gradle.regression package org.jetbrains.kotlin.gradle.regression
import org.jetbrains.kotlin.gradle.MultiplatformExtensionTest import org.jetbrains.kotlin.gradle.MultiplatformExtensionTest
@@ -9,7 +9,6 @@ package org.jetbrains.kotlin.gradle.regression
import org.gradle.api.internal.project.ProjectInternal import org.gradle.api.internal.project.ProjectInternal
import org.gradle.testfixtures.ProjectBuilder import org.gradle.testfixtures.ProjectBuilder
import org.jetbrains.kotlin.gradle.*
import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeCompilation import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeCompilation
import org.jetbrains.kotlin.gradle.util.* import org.jetbrains.kotlin.gradle.util.*
import kotlin.test.Test import kotlin.test.Test
@@ -25,16 +24,16 @@ class CommonizerTaskTests {
const val JVM_ECOSYSTEM_PLUGIN_ID = "jvm-ecosystem" const val JVM_ECOSYSTEM_PLUGIN_ID = "jvm-ecosystem"
} }
private val kotlin = subproject.applyMultiplatformPlugin().apply {
linuxX64()
linuxArm64()
targets.flatMap { it.compilations }
.filterIsInstance<KotlinNativeCompilation>()
.forEach { compilation -> compilation.cinterops.create("dummy") }
}
init { init {
subproject.applyMultiplatformPlugin().apply {
linuxX64()
linuxArm64()
targets.flatMap { it.compilations }
.filterIsInstance<KotlinNativeCompilation>()
.forEach { compilation -> compilation.cinterops.create("dummy") }
}
rootProject.enableCInteropCommonization() rootProject.enableCInteropCommonization()
subproject.enableCInteropCommonization() subproject.enableCInteropCommonization()
@@ -83,7 +83,7 @@ class IdeImportPropertiesConsistencyTest {
isHmppValueUsedInCli, isHmppValueUsedInIde, isHmppValueUsedInCli, isHmppValueUsedInIde,
""" """
project.isKotlinGranularMetadataEnabled: $isHmppValueUsedInCli project.isKotlinGranularMetadataEnabled: $isHmppValueUsedInCli
GradleImportProperties.IS_HMPP_ENABLED: ${isHmppValueUsedInIde} GradleImportProperties.IS_HMPP_ENABLED: $isHmppValueUsedInIde
""".trimIndent() """.trimIndent()
) )
@@ -3,6 +3,8 @@
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/ */
@file:Suppress("FunctionName")
package org.jetbrains.kotlin.gradle.regression package org.jetbrains.kotlin.gradle.regression
import org.gradle.api.Project import org.gradle.api.Project
@@ -83,8 +85,9 @@ class KT31459JvmMainClassesTest {
/** /**
* Returns names of all tasks that given task directly depends on * Returns names of all tasks that given task directly depends on
*/ */
private val Task.directDependencies: Set<String> get() = taskDependencies private val Task.directDependencies: Set<String>
.getDependencies(null) get() = taskDependencies
.map { it.name } .getDependencies(null)
.toSet() .map { it.name }
.toSet()
} }
@@ -3,6 +3,8 @@
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/ */
@file:Suppress("FunctionName")
package org.jetbrains.kotlin.gradle.regression package org.jetbrains.kotlin.gradle.regression
import org.jetbrains.kotlin.gradle.dsl.KotlinJsProjectExtension import org.jetbrains.kotlin.gradle.dsl.KotlinJsProjectExtension
@@ -19,7 +21,7 @@ class KT55347JsProjectImport {
private fun `GranularMetadataTransformation should be accessible in pure js projects`(jsCompiler: KotlinJsCompilerType) { private fun `GranularMetadataTransformation should be accessible in pure js projects`(jsCompiler: KotlinJsCompilerType) {
val project = buildProject { plugins.apply("org.jetbrains.kotlin.js") } val project = buildProject { plugins.apply("org.jetbrains.kotlin.js") }
val kotlin = project.kotlinExtension as KotlinJsProjectExtension val kotlin = project.kotlinExtension as KotlinJsProjectExtension
with (kotlin) { with(kotlin) {
js(jsCompiler) { js(jsCompiler) {
nodejs() nodejs()
} }
@@ -12,7 +12,6 @@ import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinCommonCompilation
import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinSharedNativeCompilation import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinSharedNativeCompilation
import org.jetbrains.kotlin.gradle.tasks.KotlinCompileCommon import org.jetbrains.kotlin.gradle.tasks.KotlinCompileCommon
import org.jetbrains.kotlin.gradle.tasks.KotlinJvmCompile import org.jetbrains.kotlin.gradle.tasks.KotlinJvmCompile
import org.jetbrains.kotlin.gradle.tasks.KotlinNativeCompile
import org.jetbrains.kotlin.gradle.util.buildProjectWithMPP import org.jetbrains.kotlin.gradle.util.buildProjectWithMPP
import org.jetbrains.kotlin.gradle.util.relativeTo import org.jetbrains.kotlin.gradle.util.relativeTo
import kotlin.test.Test import kotlin.test.Test
@@ -122,7 +121,7 @@ class KotlinCompileTaskSourcesTest {
/* Check sources of linuxArm64 compile task */ /* Check sources of linuxArm64 compile task */
val linuxArm64CompileTask = kotlin.linuxArm64().compilations.getByName("main") val linuxArm64CompileTask = kotlin.linuxArm64().compilations.getByName("main")
.compileTaskProvider.get() as KotlinNativeCompile .compileTaskProvider.get()
assertEquals( assertEquals(
setOf(commonMainSourceFile, jvmAndLinuxMainSourceFile, linuxArm64MainSourceFile).relativeTo(project), setOf(commonMainSourceFile, jvmAndLinuxMainSourceFile, linuxArm64MainSourceFile).relativeTo(project),
@@ -3,8 +3,7 @@
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/ */
/* Associate compilations are not yet supported by the IDE. KT-34102 */ @file:Suppress("FunctionName", "DuplicatedCode")
@file:Suppress("invisible_reference", "invisible_member", "FunctionName", "DuplicatedCode")
package org.jetbrains.kotlin.gradle.unit package org.jetbrains.kotlin.gradle.unit
@@ -2,7 +2,7 @@
* Copyright 2010-2022 JetBrains s.r.o. and Kotlin Programming Language contributors. * 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. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/ */
@file:Suppress("invisible_reference", "invisible_member", "FunctionName") @file:Suppress("FunctionName", "DuplicatedCode")
package org.jetbrains.kotlin.gradle.unit package org.jetbrains.kotlin.gradle.unit
@@ -260,7 +260,7 @@ internal class CompilationSpecificPluginPath {
override fun isApplicable(kotlinCompilation: KotlinCompilation<*>): Boolean = kotlinCompilation.isApplicablePredicate() override fun isApplicable(kotlinCompilation: KotlinCompilation<*>): Boolean = kotlinCompilation.isApplicablePredicate()
override fun applyToCompilation(kotlinCompilation: KotlinCompilation<*>): Provider<List<SubpluginOption>> = override fun applyToCompilation(kotlinCompilation: KotlinCompilation<*>): Provider<List<SubpluginOption>> =
kotlinCompilation.target.project.provider { emptyList<SubpluginOption>() } kotlinCompilation.target.project.provider { emptyList() }
override fun getCompilerPluginId(): String = id override fun getCompilerPluginId(): String = id
@@ -3,6 +3,8 @@
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/ */
@file:Suppress("FunctionName")
package org.jetbrains.kotlin.gradle.unit package org.jetbrains.kotlin.gradle.unit
import org.gradle.kotlin.dsl.support.unzipTo import org.gradle.kotlin.dsl.support.unzipTo
@@ -43,11 +43,11 @@ class DisabledCInteropCommonizationWarningTest {
assertTrue( assertTrue(
"[" + "[" +
"cinterop:compilation/compileKotlinLinuxArm64/dummy1, " + "cinterop:compilation/compileKotlinLinuxArm64/dummy1, " +
"cinterop:compilation/compileKotlinLinuxArm64/dummy2, " + "cinterop:compilation/compileKotlinLinuxArm64/dummy2, " +
"cinterop:compilation/compileKotlinLinuxX64/dummy1, " + "cinterop:compilation/compileKotlinLinuxX64/dummy1, " +
"cinterop:compilation/compileKotlinLinuxX64/dummy2" + "cinterop:compilation/compileKotlinLinuxX64/dummy2" +
"]" in warningMessage, "]" in warningMessage,
"Expected affected cinterops being mentioned in the warning message. Found\n\n$warningMessage" "Expected affected cinterops being mentioned in the warning message. Found\n\n$warningMessage"
) )
@@ -3,8 +3,8 @@
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/ */
/* Associate compilations are not yet supported by the IDE. KT-34102 */ @file:Suppress("FunctionName", "DuplicatedCode")
@file:Suppress("invisible_reference", "invisible_member", "FunctionName")
package org.jetbrains.kotlin.gradle.unit package org.jetbrains.kotlin.gradle.unit
import com.android.build.gradle.LibraryExtension import com.android.build.gradle.LibraryExtension
@@ -3,7 +3,7 @@
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/ */
@file:Suppress("FunctionName") @file:Suppress("FunctionName", "DuplicatedCode")
package org.jetbrains.kotlin.gradle.unit package org.jetbrains.kotlin.gradle.unit
@@ -90,10 +90,9 @@ class MppPublicationTest {
val jvmComponent = kotlinComponent.variants.first { it.name == "jvm" } val jvmComponent = kotlinComponent.variants.first { it.name == "jvm" }
val jvmSourcesElementsAttributes = jvmComponent.attributesOfUsageContext("jvmSourcesElements-published") val jvmSourcesElementsAttributes = jvmComponent.attributesOfUsageContext("jvmSourcesElements-published")
val extraExpectedAttributes = mapOf( val extraExpectedAttributes = mapOf( // target disambiguation attribute
"org.jetbrains.kotlin.platform.type" to "jvm", // target disambiguation attribute "org.jetbrains.kotlin.platform.type" to "jvm", // is set by default by kgp, when it sets usage as `java-runtime-jars`
"org.gradle.libraryelements" to "jar" // is set by default by kgp, when it sets usage as `java-runtime-jars` "org.gradle.libraryelements" to "jar" // see [KotlinUsages.producerApiUsage]
// see [KotlinUsages.producerApiUsage]
) )
val expectedAttributes = javaSourcesElementsAttributes.toMapOfStrings() + extraExpectedAttributes val expectedAttributes = javaSourcesElementsAttributes.toMapOfStrings() + extraExpectedAttributes
@@ -121,7 +120,7 @@ class MppPublicationTest {
.attributesOfUsageContext("${targetName}SourcesElements-published") .attributesOfUsageContext("${targetName}SourcesElements-published")
} }
for ( (targetName, sourceElements) in sourcesElements) { for ((targetName, sourceElements) in sourcesElements) {
assertTrue( assertTrue(
message = "Sources Elements of target $targetName doesn't have 'userAttribute'" message = "Sources Elements of target $targetName doesn't have 'userAttribute'"
) { sourceElements.attributes.toMapOfStrings().containsKey("userAttribute") } ) { sourceElements.attributes.toMapOfStrings().containsKey("userAttribute") }
@@ -3,7 +3,7 @@
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/ */
@file:Suppress("DuplicatedCode") @file:Suppress("FunctionName", "DuplicatedCode")
package org.jetbrains.kotlin.gradle.unit package org.jetbrains.kotlin.gradle.unit
@@ -3,6 +3,8 @@
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/ */
@file:Suppress("FunctionName")
package org.jetbrains.kotlin.gradle.unit.kpm package org.jetbrains.kotlin.gradle.unit.kpm
import org.gradle.api.Project import org.gradle.api.Project
@@ -7,8 +7,6 @@
package org.jetbrains.kotlin.gradle.unit.kpm package org.jetbrains.kotlin.gradle.unit.kpm
import org.gradle.kotlin.dsl.creating
import org.gradle.kotlin.dsl.provideDelegate
import kotlin.test.Test import kotlin.test.Test
import kotlin.test.assertEquals import kotlin.test.assertEquals
@@ -117,7 +117,7 @@ class InternalKotlinSourceSetTest {
} }
val kotlin = project.multiplatformExtension val kotlin = project.multiplatformExtension
with(kotlin.sourceSets) { with(kotlin.sourceSets) {
val commonMain = getByName("commonMain") val commonMain = getByName("commonMain")
val commonTest = getByName("commonTest") val commonTest = getByName("commonTest")
@@ -40,7 +40,7 @@ class SourceSetVisibilityInferenceTest {
} }
@Test @Test
fun testFailureWithNoAssociation(): Unit { fun testFailureWithNoAssociation() {
val jvm = kotlin.jvm() val jvm = kotlin.jvm()
val commonMain = kotlin.sourceSets.getByName("commonMain") val commonMain = kotlin.sourceSets.getByName("commonMain")
val commonTest = kotlin.sourceSets.getByName("commonTest") val commonTest = kotlin.sourceSets.getByName("commonTest")
@@ -3,7 +3,7 @@
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/ */
@file:Suppress("FunctionName") @file:Suppress("FunctionName", "DuplicatedCode")
package org.jetbrains.kotlin.gradle.unit.sources.android package org.jetbrains.kotlin.gradle.unit.sources.android
@@ -10,7 +10,7 @@ import kotlin.test.fail
internal class TestDiagnosticsReporter : KotlinAndroidSourceSetLayoutChecker.DiagnosticReporter { internal class TestDiagnosticsReporter : KotlinAndroidSourceSetLayoutChecker.DiagnosticReporter {
class ErrorDiagnosticException(val diagnostic: KotlinAndroidSourceSetLayoutChecker.Diagnostic) : class ErrorDiagnosticException(diagnostic: KotlinAndroidSourceSetLayoutChecker.Diagnostic) :
KotlinAndroidSourceSetLayoutChecker.ProjectMisconfiguredException(diagnostic.message) KotlinAndroidSourceSetLayoutChecker.ProjectMisconfiguredException(diagnostic.message)
private val _errors = mutableListOf<KotlinAndroidSourceSetLayoutChecker.Diagnostic>() private val _errors = mutableListOf<KotlinAndroidSourceSetLayoutChecker.Diagnostic>()
@@ -23,12 +23,6 @@ fun Task.assertDependsOn(other: Task) {
} }
} }
fun Task.assertNotDependsOn(other: Task) {
if (isDependsOn(other)) {
fail("Expected ${this.path} to *not* depend on ${other.path}")
}
}
fun Task.assertNoCircularTaskDependencies() { fun Task.assertNoCircularTaskDependencies() {
data class TaskAndDependants( data class TaskAndDependants(
val task: Task, val task: Task,
@@ -38,7 +32,7 @@ fun Task.assertNoCircularTaskDependencies() {
val visited = mutableSetOf<Task>() val visited = mutableSetOf<Task>()
val queue = ArrayDeque(taskDependencies.getDependencies(this).map { TaskAndDependants(it, listOf(this)) }) val queue = ArrayDeque(taskDependencies.getDependencies(this).map { TaskAndDependants(it, listOf(this)) })
while(queue.isNotEmpty()) { while (queue.isNotEmpty()) {
val (task, dependants) = queue.removeFirst() val (task, dependants) = queue.removeFirst()
if (task in visited) { if (task in visited) {
val dependencyChain = dependants.joinToString(" -> ") { it.name } val dependencyChain = dependants.joinToString(" -> ") { it.name }