[Gradle] Remove KPM IDE Gradle Sync support

KT-61463
This commit is contained in:
Sebastian Sellmair
2023-08-25 12:03:43 +02:00
committed by Space Team
parent e800885c03
commit 0a8cca9be4
159 changed files with 2 additions and 34489 deletions
@@ -1,36 +0,0 @@
/*
* 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.idea.kpm
import org.jetbrains.kotlin.gradle.InternalKotlinGradlePluginApi
sealed interface IdeaKpmBinaryCoordinates : IdeaKpmDependencyCoordinates {
val group: String
val module: String
val version: String
val kotlinModuleName: String?
val kotlinFragmentName: String?
}
@InternalKotlinGradlePluginApi
data class IdeaKpmBinaryCoordinatesImpl(
override val group: String,
override val module: String,
override val version: String,
override val kotlinModuleName: String? = null,
override val kotlinFragmentName: String? = null
) : IdeaKpmBinaryCoordinates {
override fun toString(): String {
return "$group:$module:$version" +
(if (kotlinModuleName != null) ":$kotlinModuleName" else "") +
(if (kotlinFragmentName != null) ":$kotlinFragmentName" else "")
}
companion object {
private const val serialVersionUID = 0L
}
}
@@ -1,27 +0,0 @@
/*
* 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.idea.kpm
import org.jetbrains.kotlin.gradle.InternalKotlinGradlePluginApi
import java.io.File
import java.io.Serializable
sealed interface IdeaKpmCompilationOutput : Serializable {
val classesDirs: Set<File>
val resourcesDir: File?
}
@InternalKotlinGradlePluginApi
data class IdeaKpmCompilationOutputImpl(
override val classesDirs: Set<File>,
override val resourcesDir: File?
) : IdeaKpmCompilationOutput {
@InternalKotlinGradlePluginApi
companion object {
const val serialVersionUID = 0L
}
}
@@ -1,44 +0,0 @@
/*
* 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.
*/
@file:Suppress("unused")
package org.jetbrains.kotlin.gradle.idea.kpm
import org.jetbrains.kotlin.gradle.InternalKotlinGradlePluginApi
import org.jetbrains.kotlin.gradle.idea.kpm.IdeaKpmContentRoot.Companion.RESOURCES_TYPE
import org.jetbrains.kotlin.gradle.idea.kpm.IdeaKpmContentRoot.Companion.SOURCES_TYPE
import org.jetbrains.kotlin.tooling.core.Extras
import org.jetbrains.kotlin.tooling.core.emptyExtras
import java.io.File
import java.io.Serializable
sealed interface IdeaKpmContentRoot : Serializable {
val extras: Extras
val file: File
val type: String
companion object {
const val SOURCES_TYPE = "source"
const val RESOURCES_TYPE = "resource"
}
}
val IdeaKpmContentRoot.isSources get() = type == SOURCES_TYPE
val IdeaKpmContentRoot.isResources get() = type == RESOURCES_TYPE
@InternalKotlinGradlePluginApi
data class IdeaKpmContentRootImpl(
override val file: File,
override val type: String,
override val extras: Extras = emptyExtras(),
) : IdeaKpmContentRoot {
@InternalKotlinGradlePluginApi
companion object {
private const val serialVersionUID = 0L
}
}
@@ -1,109 +0,0 @@
/*
* 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.
*/
@file:Suppress("FunctionName")
package org.jetbrains.kotlin.gradle.idea.kpm
import org.jetbrains.kotlin.gradle.InternalKotlinGradlePluginApi
import org.jetbrains.kotlin.gradle.idea.kpm.IdeaKpmDependency.Companion.CLASSPATH_BINARY_TYPE
import org.jetbrains.kotlin.gradle.idea.kpm.IdeaKpmDependency.Companion.DOCUMENTATION_BINARY_TYPE
import org.jetbrains.kotlin.gradle.idea.kpm.IdeaKpmDependency.Companion.SOURCES_BINARY_TYPE
import org.jetbrains.kotlin.tooling.core.Extras
import org.jetbrains.kotlin.tooling.core.emptyExtras
import java.io.File
import java.io.Serializable
import java.util.*
sealed interface IdeaKpmDependency : Serializable {
val coordinates: IdeaKpmDependencyCoordinates?
val extras: Extras
companion object {
const val CLASSPATH_BINARY_TYPE = "org.jetbrains.binary.type.classpath"
const val SOURCES_BINARY_TYPE = "org.jetbrains.binary.type.sources"
const val DOCUMENTATION_BINARY_TYPE = "org.jetbrains.binary.type.documentation"
}
}
sealed interface IdeaKpmFragmentDependency : IdeaKpmDependency {
enum class Type : Serializable {
Regular, Friend, Refines;
@InternalKotlinGradlePluginApi
companion object {
private const val serialVersionUID = 0L
}
}
val type: Type
override val coordinates: IdeaKpmFragmentCoordinates
}
sealed interface IdeaKpmBinaryDependency : IdeaKpmDependency {
override val coordinates: IdeaKpmBinaryCoordinates?
}
sealed interface IdeaKpmUnresolvedBinaryDependency : IdeaKpmBinaryDependency {
val cause: String?
}
sealed interface IdeaKpmResolvedBinaryDependency : IdeaKpmBinaryDependency {
val binaryType: String
val binaryFile: File
}
val IdeaKpmResolvedBinaryDependency.isSourcesType get() = binaryType == SOURCES_BINARY_TYPE
val IdeaKpmResolvedBinaryDependency.isDocumentationType get() = binaryType == DOCUMENTATION_BINARY_TYPE
val IdeaKpmResolvedBinaryDependency.isClasspathType get() = binaryType == CLASSPATH_BINARY_TYPE
@InternalKotlinGradlePluginApi
data class IdeaKpmFragmentDependencyImpl(
override val type: IdeaKpmFragmentDependency.Type,
override val coordinates: IdeaKpmFragmentCoordinates,
override val extras: Extras = emptyExtras()
) : IdeaKpmFragmentDependency {
override fun toString(): String {
@Suppress("DEPRECATION")
return "${type.name.toLowerCase(Locale.ROOT)}:$coordinates"
}
@InternalKotlinGradlePluginApi
companion object {
private const val serialVersionUID = 0L
}
}
@InternalKotlinGradlePluginApi
data class IdeaKpmResolvedBinaryDependencyImpl(
override val coordinates: IdeaKpmBinaryCoordinates?,
override val binaryType: String,
override val binaryFile: File,
override val extras: Extras = emptyExtras()
) : IdeaKpmResolvedBinaryDependency {
override fun toString(): String {
return "${binaryType.split(".").last()}://$coordinates/${binaryFile.name}"
}
@InternalKotlinGradlePluginApi
companion object {
private const val serialVersionUID = 0L
}
}
@InternalKotlinGradlePluginApi
data class IdeaKpmUnresolvedBinaryDependencyImpl(
override val cause: String?,
override val coordinates: IdeaKpmBinaryCoordinates?,
override val extras: Extras = emptyExtras()
) : IdeaKpmUnresolvedBinaryDependency {
@InternalKotlinGradlePluginApi
companion object {
private const val serialVersionUID = 0L
}
}
@@ -1,10 +0,0 @@
/*
* 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.idea.kpm
import java.io.Serializable
sealed interface IdeaKpmDependencyCoordinates : Serializable
@@ -1,38 +0,0 @@
/*
* 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.idea.kpm
import org.jetbrains.kotlin.gradle.InternalKotlinGradlePluginApi
import org.jetbrains.kotlin.tooling.core.Extras
import java.io.Serializable
sealed interface IdeaKpmFragment : Serializable {
val coordinates: IdeaKpmFragmentCoordinates
val platforms: Set<IdeaKpmPlatform>
val languageSettings: IdeaKpmLanguageSettings
val dependencies: List<IdeaKpmDependency>
val contentRoots: List<IdeaKpmContentRoot>
val extras: Extras
}
val IdeaKpmFragment.name get() = coordinates.fragmentName
@InternalKotlinGradlePluginApi
data class IdeaKpmFragmentImpl(
override val coordinates: IdeaKpmFragmentCoordinates,
override val platforms: Set<IdeaKpmPlatform>,
override val languageSettings: IdeaKpmLanguageSettings,
override val dependencies: List<IdeaKpmDependency>,
override val contentRoots: List<IdeaKpmContentRoot>,
override val extras: Extras
) : IdeaKpmFragment {
@InternalKotlinGradlePluginApi
companion object {
private const val serialVersionUID = 0L
}
}
@@ -1,31 +0,0 @@
/*
* 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.idea.kpm
import org.jetbrains.kotlin.gradle.InternalKotlinGradlePluginApi
import java.io.Serializable
sealed interface IdeaKpmFragmentCoordinates : Serializable, IdeaKpmDependencyCoordinates {
val module: IdeaKpmModuleCoordinates
val fragmentName: String
}
@InternalKotlinGradlePluginApi
data class IdeaKpmFragmentCoordinatesImpl(
override val module: IdeaKpmModuleCoordinates,
override val fragmentName: String
) : IdeaKpmFragmentCoordinates {
override fun toString(): String = path
@InternalKotlinGradlePluginApi
companion object {
private const val serialVersionUID = 0L
}
}
val IdeaKpmFragmentCoordinates.path: String
get() = "${module.path}/$fragmentName"
@@ -1,39 +0,0 @@
/*
* 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.idea.kpm
import org.jetbrains.kotlin.gradle.InternalKotlinGradlePluginApi
import java.io.File
import java.io.Serializable
sealed interface IdeaKpmLanguageSettings : Serializable {
val languageVersion: String?
val apiVersion: String?
val isProgressiveMode: Boolean
val enabledLanguageFeatures: Set<String>
val optInAnnotationsInUse: Set<String>
val compilerPluginArguments: List<String>
val compilerPluginClasspath: List<File>
val freeCompilerArgs: List<String>
}
@InternalKotlinGradlePluginApi
data class IdeaKpmLanguageSettingsImpl(
override val languageVersion: String?,
override val apiVersion: String?,
override val isProgressiveMode: Boolean,
override val enabledLanguageFeatures: Set<String>,
override val optInAnnotationsInUse: Set<String>,
override val compilerPluginArguments: List<String>,
override val compilerPluginClasspath: List<File>,
override val freeCompilerArgs: List<String>
) : IdeaKpmLanguageSettings {
@InternalKotlinGradlePluginApi
companion object {
private const val serialVersionUID = 0L
}
}
@@ -1,30 +0,0 @@
/*
* 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.idea.kpm
import org.jetbrains.kotlin.gradle.InternalKotlinGradlePluginApi
import java.io.Serializable
sealed interface IdeaKpmModule : Serializable {
val coordinates: IdeaKpmModuleCoordinates
val fragments: List<IdeaKpmFragment>
}
val IdeaKpmModule.name get() = coordinates.moduleName
val IdeaKpmModule.moduleClassifier get() = coordinates.moduleClassifier
@InternalKotlinGradlePluginApi
data class IdeaKpmModuleImpl(
override val coordinates: IdeaKpmModuleCoordinates,
override val fragments: List<IdeaKpmFragment>
) : IdeaKpmModule {
@InternalKotlinGradlePluginApi
companion object {
private const val serialVersionUID = 0L
}
}
@@ -1,35 +0,0 @@
/*
* 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.idea.kpm
import org.jetbrains.kotlin.gradle.InternalKotlinGradlePluginApi
import java.io.Serializable
sealed interface IdeaKpmModuleCoordinates : Serializable {
val buildId: String
val projectPath: String
val projectName: String
val moduleName: String
val moduleClassifier: String?
}
val IdeaKpmModuleCoordinates.path: String
get() = "${buildId.takeIf { it != ":" }.orEmpty()}$projectPath/$moduleName"
@InternalKotlinGradlePluginApi
data class IdeaKpmModuleCoordinatesImpl(
override val buildId: String,
override val projectPath: String,
override val projectName: String,
override val moduleName: String,
override val moduleClassifier: String?
) : IdeaKpmModuleCoordinates {
@InternalKotlinGradlePluginApi
companion object {
private const val serialVersionUID = 0L
}
}
@@ -1,87 +0,0 @@
/*
* 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.
*/
@file:Suppress("unused")
package org.jetbrains.kotlin.gradle.idea.kpm
import org.jetbrains.kotlin.gradle.InternalKotlinGradlePluginApi
import org.jetbrains.kotlin.tooling.core.Extras
import org.jetbrains.kotlin.tooling.core.emptyExtras
import java.io.Serializable
sealed interface IdeaKpmPlatform : Serializable {
val extras: Extras
}
sealed interface IdeaKpmJvmPlatform : IdeaKpmPlatform {
val jvmTarget: String
}
sealed interface IdeaKpmNativePlatform : IdeaKpmPlatform {
val konanTarget: String
}
sealed interface IdeaKpmJsPlatform : IdeaKpmPlatform {
val isIr: Boolean
}
sealed interface IdeaKpmWasmPlatform : IdeaKpmPlatform
sealed interface IdeaKpmUnknownPlatform : IdeaKpmPlatform
val IdeaKpmPlatform.isWasm get() = this is IdeaKpmWasmPlatform
val IdeaKpmPlatform.isNative get() = this is IdeaKpmNativePlatform
val IdeaKpmPlatform.isJvm get() = this is IdeaKpmJvmPlatform
val IdeaKpmPlatform.isJs get() = this is IdeaKpmJsPlatform
val IdeaKpmPlatform.isUnknown get() = this is IdeaKpmUnknownPlatform
@InternalKotlinGradlePluginApi
data class IdeaKpmJvmPlatformImpl(
override val jvmTarget: String,
override val extras: Extras = emptyExtras()
) : IdeaKpmJvmPlatform {
internal companion object {
const val serialVersionUID = 0L
}
}
@InternalKotlinGradlePluginApi
data class IdeaKpmNativePlatformImpl(
override val konanTarget: String,
override val extras: Extras = emptyExtras()
) : IdeaKpmNativePlatform {
internal companion object {
const val serialVersionUID = 0L
}
}
@InternalKotlinGradlePluginApi
data class IdeaKpmJsPlatformImpl(
override val isIr: Boolean,
override val extras: Extras = emptyExtras()
) : IdeaKpmJsPlatform {
internal companion object {
const val serialVersionUID = 0L
}
}
@InternalKotlinGradlePluginApi
data class IdeaKpmWasmPlatformImpl(
override val extras: Extras = emptyExtras()
) : IdeaKpmWasmPlatform {
internal companion object {
const val serialVersionUID = 0L
}
}
@InternalKotlinGradlePluginApi
data class IdeaKpmUnknownPlatformImpl(
override val extras: Extras = emptyExtras()
) : IdeaKpmUnknownPlatform {
internal companion object {
const val serialVersionUID = 0L
}
}
@@ -1,33 +0,0 @@
/*
* 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.idea.kpm
import org.jetbrains.kotlin.gradle.InternalKotlinGradlePluginApi
import java.io.File
import java.io.Serializable
sealed interface IdeaKpmProject : Serializable {
val gradlePluginVersion: String
val coreLibrariesVersion: String
val explicitApiModeCliOption: String?
val kotlinNativeHome: File
val modules: List<IdeaKpmModule>
}
@InternalKotlinGradlePluginApi
data class IdeaKpmProjectImpl(
override val gradlePluginVersion: String,
override val coreLibrariesVersion: String,
override val explicitApiModeCliOption: String?,
override val kotlinNativeHome: File,
override val modules: List<IdeaKpmModule>
) : IdeaKpmProject {
@InternalKotlinGradlePluginApi
companion object {
private const val serialVersionUID = 0L
}
}
@@ -1,73 +0,0 @@
/*
* 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.
*/
@file:Suppress("FunctionName")
package org.jetbrains.kotlin.gradle.idea.kpm
import java.io.Serializable
fun IdeaKpmProjectContainer(project: ByteArray): IdeaKpmProjectBinaryContainer {
return IdeaKpmProjectBinaryContainerImpl(project)
}
fun IdeaKpmProjectContainer(project: IdeaKpmProject): IdeaKpmProjectInstanceContainer {
return IdeaKpmProjectInstanceContainerImpl(project)
}
/**
* Wrapper around [IdeaKpmProject] which can store the project in two forms
* - binary : [IdeaKpmProjectBinaryContainer]
* - instance: [IdeaKpmProjectInstanceContainer]
*
* This class is used to transport the [IdeaKpmProject] into the IDE, where it needs
* to take those two forms, while keeping the same class as key on IJ side.
*
* This class overcomes a limitation in IntelliJ's SerializationService, which basically
* requires a single class.
*
* When this container is requested from a Model Builder, it will
* return the binary form. This gets deserialized by the SerializationService and transformed
* into [IdeaKpmProjectInstanceContainer].
*/
sealed interface IdeaKpmProjectContainer<T : Any> : Serializable {
val project: T
val binaryOrNull: ByteArray?
val instanceOrNull: IdeaKpmProject?
}
interface IdeaKpmProjectBinaryContainer : IdeaKpmProjectContainer<ByteArray> {
override val instanceOrNull: Nothing? get() = null
override val binaryOrNull: ByteArray get() = project
}
interface IdeaKpmProjectInstanceContainer : IdeaKpmProjectContainer<IdeaKpmProject> {
override val instanceOrNull: IdeaKpmProject get() = project
override val binaryOrNull: Nothing? get() = null
}
private data class IdeaKpmProjectBinaryContainerImpl(override val project: ByteArray) : IdeaKpmProjectBinaryContainer {
override fun equals(other: Any?): Boolean {
if (other === this) return true
if (other !is IdeaKpmProjectBinaryContainer) return false
return other.project.contentEquals(this.project)
}
override fun hashCode(): Int {
return project.contentHashCode()
}
companion object {
const val serialVersionUID = 0L
}
}
private data class IdeaKpmProjectInstanceContainerImpl(
override val project: IdeaKpmProject
) : IdeaKpmProjectInstanceContainer {
companion object {
const val serialVersionUID = 0L
}
}
@@ -1,29 +0,0 @@
/*
* 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.idea.kpm
import org.jetbrains.kotlin.gradle.InternalKotlinGradlePluginApi
import java.io.Serializable
sealed interface IdeaKpmVariant : IdeaKpmFragment, Serializable {
val platform: IdeaKpmPlatform
val variantAttributes: Map<String, String>
val compilationOutputs: IdeaKpmCompilationOutput
}
@InternalKotlinGradlePluginApi
data class IdeaKpmVariantImpl(
internal val fragment: IdeaKpmFragment,
override val platform: IdeaKpmPlatform,
override val variantAttributes: Map<String, String>,
override val compilationOutputs: IdeaKpmCompilationOutput,
) : IdeaKpmVariant, IdeaKpmFragment by fragment {
@InternalKotlinGradlePluginApi
companion object {
private const val serialVersionUID = 0L
}
}
@@ -1,10 +0,0 @@
/*
* 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.idea.kpm
import kotlin.reflect.KClass
internal annotation class WriteReplacedModel(val replacedBy: KClass<*>)
@@ -1,60 +0,0 @@
/*
* 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.idea.test.kpm
import org.jetbrains.kotlin.gradle.idea.kpm.IdeaKpmProjectBinaryContainer
import org.jetbrains.kotlin.gradle.idea.kpm.IdeaKpmProjectContainer
import org.jetbrains.kotlin.gradle.idea.kpm.IdeaKpmProjectInstanceContainer
import org.jetbrains.kotlin.gradle.idea.testFixtures.kpm.TestIdeaKpmInstances
import kotlin.test.*
class IdeaKpmProjectContainerTest {
@Test
fun `test - binary container - equality`() {
val container1 = IdeaKpmProjectContainer(byteArrayOf(1))
val container2 = IdeaKpmProjectContainer(byteArrayOf(1))
val container3 = IdeaKpmProjectContainer(byteArrayOf(1, 2))
assertEquals(container1, container2)
assertNotEquals(container2, container3)
}
@Test
fun `test - instance container - equality`() {
val container1 = IdeaKpmProjectContainer(TestIdeaKpmInstances.simpleProject)
val container2 = IdeaKpmProjectContainer(TestIdeaKpmInstances.simpleProject.copy())
val container3 = IdeaKpmProjectContainer(TestIdeaKpmInstances.simpleProject.copy(gradlePluginVersion = "some.other.version"))
assertEquals(container1, container2)
assertNotEquals(container2, container3)
}
@Test
fun `test - binary container - instanceOrNull`() {
assertNull(IdeaKpmProjectContainer(byteArrayOf()).instanceOrNull)
assertNotNull(IdeaKpmProjectBinaryContainer::class.java.getMethod("getInstanceOrNull"))
}
@Test
fun `test - instance container - instanceOrNull`() {
assertSame(TestIdeaKpmInstances.simpleProject, IdeaKpmProjectContainer(TestIdeaKpmInstances.simpleProject).instanceOrNull)
assertNotNull(IdeaKpmProjectInstanceContainer::class.java.getMethod("getInstanceOrNull"))
}
@Test
fun `test - binary container - binaryOrNull`() {
val binary = byteArrayOf()
assertEquals(binary, IdeaKpmProjectContainer(binary).binaryOrNull)
assertNotNull(IdeaKpmProjectBinaryContainer::class.java.getMethod("getBinaryOrNull"))
}
@Test
fun `test - instance container - binaryOrNull`() {
assertNull(IdeaKpmProjectContainer(TestIdeaKpmInstances.simpleProject).binaryOrNull)
assertNotNull(IdeaKpmProjectInstanceContainer::class.java.getMethod("getBinaryOrNull"))
}
}
@@ -1,145 +0,0 @@
/*
* 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.idea.test.kpm
import org.jetbrains.kotlin.gradle.idea.kpm.IdeaKpmProject
import org.jetbrains.kotlin.gradle.idea.kpm.WriteReplacedModel
import org.jetbrains.kotlin.tooling.core.AbstractExtras
import org.jetbrains.kotlin.tooling.core.Extras
import org.jetbrains.kotlin.tooling.core.MutableExtras
import org.junit.runner.RunWith
import org.junit.runners.Parameterized
import org.reflections.Reflections
import java.lang.reflect.Field
import java.lang.reflect.Modifier
import kotlin.reflect.KClass
import kotlin.reflect.KVisibility.PUBLIC
import kotlin.reflect.full.findAnnotation
import kotlin.reflect.full.memberProperties
import kotlin.test.*
@OptIn(ExperimentalStdlibApi::class)
@RunWith(Parameterized::class)
class IdeaKpmProjectObjectGraphTest(private val node: KClass<*>, @Suppress("unused_parameter") clazzName: String) {
@Test
fun `test - node implements Serializable`() {
assertTrue(
java.io.Serializable::class.java.isAssignableFrom(node.java),
"Expected node ${node.simpleName} to implement `Serializable`"
)
}
@Test
fun `test - node is sealed`() {
if (node.java.isInterface) {
assertTrue(
node.isSealed,
"Expected $node to be sealed interface"
)
}
}
@Test
fun `test - node implementations contain serialVersionUID`() {
if (!node.java.isInterface && !Modifier.isAbstract(node.java.modifiers)) {
val serialVersionUID = assertNotNull(
node.java.getDeclaredFieldOrNull("serialVersionUID"),
"Expected $node to declare 'serialVersionUID' field"
)
assertTrue(
Modifier.isStatic(serialVersionUID.modifiers),
"Expected $node to declare 'serialVersionUID' statically"
)
assertTrue(
serialVersionUID.type.isPrimitive,
"Expected $node to declare primitive 'serialVersionUID'"
)
assertEquals(
serialVersionUID.type, Long::class.javaPrimitiveType,
"Expected $node to declare 'serialVersionUID' of type Long"
)
}
}
@Test
fun `test - node implementations are marked with InternalKotlinGradlePluginApi when data class`() {
if (node.isData && node.visibility == PUBLIC) {
assertTrue(
node.annotations.any { it.annotationClass.simpleName == "InternalKotlinGradlePluginApi" },
"Expected $node to be annotated with '@InternalKotlinGradlePluginApi'"
)
}
}
private fun Class<*>.getDeclaredFieldOrNull(name: String): Field? {
return try {
getDeclaredField(name)
} catch (t: NoSuchFieldException) {
return null
}
}
companion object {
private val reflections = Reflections("org.jetbrains.kotlin")
private val ignoredNodes = setOf(
/*
Extras interface and AbstractExtras are okay for now:
Let's check known implementations for correctness
*/
Extras::class, MutableExtras::class, AbstractExtras::class
)
@JvmStatic
@Parameterized.Parameters(name = "{1}")
fun findNodes(): List<Array<Any>> {
val classes = mutableSetOf<KClass<*>>()
val resolveQueue = ArrayDeque<KClass<*>>(listOf(IdeaKpmProject::class))
while (resolveQueue.isNotEmpty()) {
val next = resolveQueue.removeFirst()
/* Model gets replaced by other class */
val writeReplacedModelAnnotation = next.findAnnotation<WriteReplacedModel>()
if (writeReplacedModelAnnotation != null) {
resolveQueue.add(writeReplacedModelAnnotation.replacedBy)
continue
}
if (!classes.add(next)) continue
next.resolveReachableClasses().forEach { child ->
resolveQueue.add(child)
if (child.java.isInterface || Modifier.isAbstract(child.java.modifiers)) {
val subtypes = reflections.getSubTypesOf(child.java).map { it.kotlin }
assertTrue(subtypes.isNotEmpty(), "Missing implementations for $child")
resolveQueue.addAll(subtypes)
}
}
}
fun KClass<*>.displayName() = java.name
.removePrefix("org.jetbrains.kotlin")
.removePrefix(".gradle.kpm")
.removePrefix(".")
return classes
.filter { it !in ignoredNodes }
.map { clazz -> arrayOf(clazz, checkNotNull(clazz.displayName())) }
}
private fun KClass<*>.resolveReachableClasses(): Set<KClass<*>> {
return this.memberProperties
.map { member -> member.returnType }
.flatMap { type -> setOf(type) + type.arguments.mapNotNull { it.type } }
.mapNotNull { type -> type.classifier as? KClass<*> }
.filter { clazz -> clazz.java.name.startsWith("org.jetbrains") }
.toSet()
}
}
}
@@ -1,62 +0,0 @@
/*
* 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.idea.test.testUtils
import org.jetbrains.kotlin.gradle.idea.kpm.IdeaKpmProject
import org.jetbrains.kotlin.gradle.idea.serialize.IdeaKotlinSerializationLogger
import org.jetbrains.kotlin.gradle.idea.testFixtures.kpm.TestIdeaKpmClassLoaderProjectSerializer
import java.io.File
import java.net.URLClassLoader
import kotlin.test.assertEquals
import kotlin.test.assertNotNull
import kotlin.test.assertSame
/*
* 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.
*/
fun classLoaderForBackwardsCompatibleClasses(): ClassLoader {
val uris = classpathForBackwardsCompatibleClasses().map { file -> file.toURI().toURL() }.toTypedArray()
return URLClassLoader.newInstance(uris, null)
}
fun classpathForBackwardsCompatibleClasses(): List<File> {
val compatibilityTestClasspath = System.getProperty("compatibilityTestClasspath")
?: error("Missing compatibilityTestClasspath system property")
return compatibilityTestClasspath.split(";").map { path -> File(path) }
.onEach { file -> if (!file.exists()) println("[WARNING] Missing $file") }
.flatMap { file -> if (file.isDirectory) file.listFiles().orEmpty().toList() else listOf(file) }
}
fun deserializeIdeaKpmProjectWithBackwardsCompatibleClasses(project: IdeaKpmProject): Any {
return deserializeIdeaKpmProjectWithBackwardsCompatibleClasses(
TestIdeaKpmClassLoaderProjectSerializer().serialize(project)
)
}
fun deserializeIdeaKpmProjectWithBackwardsCompatibleClasses(project: ByteArray): Any {
val classLoader = classLoaderForBackwardsCompatibleClasses()
val serializer = TestIdeaKpmClassLoaderProjectSerializer(classLoader)
val deserialized = assertNotNull(
serializer.deserialize(project),
"Failed to deserialize project: ${serializer.reports}"
)
assertEquals(
0, serializer.reports.count { it.severity > IdeaKotlinSerializationLogger.Severity.WARNING },
"Expected no severe deserialization reports. Found ${serializer.reports}"
)
assertSame(
classLoader, deserialized::class.java.classLoader,
"Expected model do be deserialized in with old classes"
)
return deserialized
}
@@ -1,42 +0,0 @@
/*
* 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.idea.test.testUtils
import org.gradle.api.Project
import org.gradle.api.artifacts.verification.DependencyVerificationMode
import org.gradle.api.internal.project.ProjectInternal
import org.gradle.configurationcache.extensions.serviceOf
import org.gradle.testfixtures.ProjectBuilder
import org.gradle.tooling.provider.model.ToolingModelBuilderRegistry
import org.jetbrains.kotlin.gradle.idea.kpm.IdeaKpmProject
import org.jetbrains.kotlin.gradle.idea.kpm.IdeaKpmProjectBinaryContainer
import org.jetbrains.kotlin.gradle.idea.kpm.IdeaKpmProjectContainer
import org.jetbrains.kotlin.gradle.plugin.KotlinPm20PluginWrapper
import org.jetbrains.kotlin.gradle.plugin.mpp.pm20.KotlinPm20ProjectExtension
/*
* 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.
*/
fun Project.buildIdeaKpmProject(): IdeaKpmProject {
return serviceOf<ToolingModelBuilderRegistry>().getBuilder(IdeaKpmProject::class.java.name)
.buildAll(IdeaKpmProject::class.java.name, this) as IdeaKpmProject
}
fun Project.buildIdeaKpmProjectBinary(): IdeaKpmProjectBinaryContainer {
return serviceOf<ToolingModelBuilderRegistry>().getBuilder(IdeaKpmProjectContainer::class.java.name)
.buildAll(IdeaKpmProjectContainer::class.java.name, this) as IdeaKpmProjectBinaryContainer
}
fun createKpmProject(): Pair<ProjectInternal, KotlinPm20ProjectExtension> {
val project = ProjectBuilder.builder().build() as ProjectInternal
project.plugins.apply(KotlinPm20PluginWrapper::class.java)
project.gradle.startParameter.dependencyVerificationMode = DependencyVerificationMode.OFF
project.repositories.mavenLocal()
project.repositories.maven { it.setUrl("https://cache-redirector.jetbrains.com/maven-central") }
return project to project.extensions.getByType(KotlinPm20ProjectExtension::class.java)
}
@@ -1,70 +0,0 @@
/*
* 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.idea.testFixtures.kpm
import org.jetbrains.kotlin.gradle.idea.kpm.IdeaKpmBinaryCoordinates
import org.jetbrains.kotlin.gradle.idea.kpm.IdeaKpmBinaryDependency
import org.jetbrains.kotlin.gradle.idea.kpm.IdeaKpmResolvedBinaryDependency
import java.io.File
fun buildIdeaKpmBinaryDependencyMatchers(notation: Any?): List<TestIdeaKpmBinaryDependencyMatcher> {
return when (notation) {
null -> emptyList()
is TestIdeaKpmBinaryDependencyMatcher -> listOf(notation)
is String -> listOf(TestIdeaKpmBinaryDependencyMatcher.Coordinates(parseIdeaKpmBinaryCoordinates(notation)))
is Regex -> listOf(TestIdeaKpmBinaryDependencyMatcher.CoordinatesRegex(notation))
is File -> listOf(TestIdeaKpmBinaryDependencyMatcher.BinaryFile(notation))
is Iterable<*> -> notation.flatMap { child -> buildIdeaKpmBinaryDependencyMatchers(child) }
else -> error("Can't build ${TestIdeaKpmBinaryDependencyMatcher::class.simpleName} from $notation")
}
}
interface TestIdeaKpmBinaryDependencyMatcher : TestIdeaKpmDependencyMatcher<IdeaKpmBinaryDependency> {
class Coordinates(
private val coordinates: IdeaKpmBinaryCoordinates
) : TestIdeaKpmBinaryDependencyMatcher {
override val description: String = coordinates.toString()
override fun matches(dependency: IdeaKpmBinaryDependency): Boolean {
return coordinates == dependency.coordinates
}
}
class CoordinatesRegex(
private val regex: Regex
) : TestIdeaKpmBinaryDependencyMatcher {
override val description: String = regex.pattern
override fun matches(dependency: IdeaKpmBinaryDependency): Boolean {
return regex.matches(dependency.coordinates.toString())
}
}
class BinaryFile(
private val binaryFile: File
) : TestIdeaKpmBinaryDependencyMatcher {
override val description: String = binaryFile.path
override fun matches(dependency: IdeaKpmBinaryDependency): Boolean {
return dependency is IdeaKpmResolvedBinaryDependency && dependency.binaryFile == binaryFile
}
}
class InDirectory(
private val parentFile: File
) : TestIdeaKpmBinaryDependencyMatcher {
constructor(parentFilePath: String) : this(File(parentFilePath))
override val description: String = "$parentFile/**"
override fun matches(dependency: IdeaKpmBinaryDependency): Boolean {
return dependency is IdeaKpmResolvedBinaryDependency &&
dependency.binaryFile.absoluteFile.normalize().canonicalPath.startsWith(
parentFile.absoluteFile.normalize().canonicalPath
)
}
}
}
@@ -1,98 +0,0 @@
/*
* 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.idea.testFixtures.kpm
import org.jetbrains.kotlin.gradle.idea.kpm.IdeaKpmProject
import org.jetbrains.kotlin.gradle.idea.proto.kpm.IdeaKpmProject
import org.jetbrains.kotlin.gradle.idea.proto.kpm.toByteArray
import org.jetbrains.kotlin.gradle.idea.testFixtures.serialize.TestIdeaKotlinSerializationContext
import org.jetbrains.kotlin.gradle.idea.testFixtures.serialize.TestIdeaKotlinSerializationLogger
import org.jetbrains.kotlin.gradle.idea.testFixtures.utils.copy
import org.jetbrains.kotlin.tooling.core.UnsafeApi
import java.lang.reflect.InvocationHandler
import java.lang.reflect.Method
import java.lang.reflect.Proxy
import kotlin.reflect.full.primaryConstructor
import kotlin.reflect.jvm.javaGetter
import kotlin.reflect.jvm.javaMethod
@OptIn(UnsafeApi::class)
fun TestIdeaKpmClassLoaderProjectSerializer(): TestIdeaKpmClassLoaderProjectSerializer =
TestIdeaKpmProtoClassLoaderProjectSerializer(TestIdeaKpmClassLoaderProjectSerializer::class.java.classLoader)
@OptIn(UnsafeApi::class)
fun TestIdeaKpmClassLoaderProjectSerializer(classLoader: ClassLoader): TestIdeaKpmClassLoaderProjectSerializer {
/*
Instantiates the `TestIdeaKpmProtoClassLoaderProjectSerializer` in the previous version of the classes
(using the specified classLoader). A java proxy will be used to bridge this implementation and the return type interface
*/
val serializerInstance = classLoader.loadClass(TestIdeaKpmProtoClassLoaderProjectSerializer::class.java.name)
.kotlin.primaryConstructor?.call(classLoader) ?: error(
"Failed to construct ${TestIdeaKpmProtoClassLoaderProjectSerializer::class.java.name} in $classLoader"
)
return Proxy.newProxyInstance(
/* loader = */ TestIdeaKpmClassLoaderProjectSerializer::class.java.classLoader,
/* interfaces = */ arrayOf(TestIdeaKpmClassLoaderProjectSerializer::class.java),
/* h = */ ProxyInvocationHandler(classLoader, serializerInstance)
) as TestIdeaKpmClassLoaderProjectSerializer
}
/**
* Test Util to serialize / deserialize [IdeaKpmProject] within a dedicated ClassLoader.
* The serialization context used will be [TestIdeaKotlinSerializationContext]. Note, that this context
* might also depend on the version shipped by the specified [ClassLoader].
*/
interface TestIdeaKpmClassLoaderProjectSerializer {
val classLoader: ClassLoader
val reports: List<TestIdeaKotlinSerializationLogger.Report>
fun serialize(project: Any): ByteArray
fun deserialize(data: ByteArray): Any?
}
@UnsafeApi
internal class TestIdeaKpmProtoClassLoaderProjectSerializer(
override val classLoader: ClassLoader
) : TestIdeaKpmClassLoaderProjectSerializer {
private val context = TestIdeaKotlinSerializationContext()
override val reports: List<TestIdeaKotlinSerializationLogger.Report>
get() = context.logger.reports
override fun serialize(project: Any): ByteArray {
return (project as IdeaKpmProject).toByteArray(context)
}
override fun deserialize(data: ByteArray): Any? {
return context.IdeaKpmProject(data)
}
}
private class ProxyInvocationHandler(
private val classLoader: ClassLoader,
private val serializerInstance: Any
) : InvocationHandler {
override fun invoke(proxy: Any, method: Method, args: Array<out Any>?): Any? {
if (method == TestIdeaKpmClassLoaderProjectSerializer::classLoader.getter.javaMethod) {
return classLoader
}
val targetMethod = serializerInstance.javaClass.methods.find { it.name == method.name } ?: error("Missing $method")
val result = targetMethod.invoke(serializerInstance, *args.orEmpty())
/*
The result objects here are also part of the test-fixtures, which will have different classes, depending on the
ClassLoader being used. The reports here, will be copied (serialized and then deserialized in this ClassLoader).
*/
if (method == TestIdeaKpmClassLoaderProjectSerializer::reports.javaGetter) {
/* Copy into 'our' ClassLoader */
return result?.copy()
}
return result
}
}
@@ -1,13 +0,0 @@
/*
* 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.idea.testFixtures.kpm
import org.jetbrains.kotlin.gradle.idea.kpm.IdeaKpmDependency
interface TestIdeaKpmDependencyMatcher<in T : IdeaKpmDependency> {
val description: String
fun matches(dependency: T): Boolean
}
@@ -1,10 +0,0 @@
/*
* 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.idea.testFixtures.kpm
import java.io.Serializable
data class TestIdeaKpmExtra(val id: Any) : Serializable
@@ -1,36 +0,0 @@
/*
* 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.idea.testFixtures.kpm
import org.jetbrains.kotlin.gradle.idea.kpm.IdeaKpmFragmentDependency
fun buildIdeaKpmFragmentDependencyMatchers(notation: Any?): List<TestIdeaKpmFragmentDependencyMatcher> {
return when (notation) {
null -> emptyList()
is Iterable<*> -> notation.flatMap { buildIdeaKpmFragmentDependencyMatchers(it) }
is String -> listOf(TestIdeaKpmFragmentDependencyMatcher.DependencyLiteral(notation))
is Regex -> listOf(TestIdeaKpmFragmentDependencyMatcher.DependencyRegex(notation))
else -> error("Can't build ${TestIdeaKpmFragmentDependencyMatcher::class.simpleName} from $notation")
}
}
interface TestIdeaKpmFragmentDependencyMatcher : TestIdeaKpmDependencyMatcher<IdeaKpmFragmentDependency> {
class DependencyLiteral(private val dependencyLiteral: String) : TestIdeaKpmFragmentDependencyMatcher {
override val description: String = dependencyLiteral
override fun matches(dependency: IdeaKpmFragmentDependency): Boolean {
return this.dependencyLiteral == dependency.toString()
}
}
class DependencyRegex(private val dependencyRegex: Regex) : TestIdeaKpmFragmentDependencyMatcher {
override val description: String = dependencyRegex.pattern
override fun matches(dependency: IdeaKpmFragmentDependency): Boolean {
return dependencyRegex.matches(dependency.coordinates.toString())
}
}
}
@@ -1,120 +0,0 @@
/*
* 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.idea.testFixtures.kpm
import org.jetbrains.kotlin.gradle.idea.kpm.*
import org.jetbrains.kotlin.tooling.core.emptyExtras
import org.jetbrains.kotlin.tooling.core.extrasKeyOf
import org.jetbrains.kotlin.tooling.core.extrasOf
import org.jetbrains.kotlin.tooling.core.withValue
import java.io.File
object TestIdeaKpmInstances {
val extrasWithIntAndStrings = extrasOf(
extrasKeyOf<Int>() withValue 1,
extrasKeyOf<String>() withValue "Cash"
)
val simpleModuleCoordinates = IdeaKpmModuleCoordinatesImpl(
buildId = "myBuildId",
projectPath = "myProjectPath",
projectName = "myProjectName",
moduleName = "myModuleName",
moduleClassifier = "myModuleClassifier"
)
val simpleFragmentCoordinates = IdeaKpmFragmentCoordinatesImpl(
module = simpleModuleCoordinates,
fragmentName = "myFragmentName"
)
val simpleJvmPlatform = IdeaKpmJvmPlatformImpl(
jvmTarget = "myJvmTarget"
)
val simpleLanguageSettings = IdeaKpmLanguageSettingsImpl(
languageVersion = "myLanguageVersion",
apiVersion = "myApiVersion",
isProgressiveMode = true,
enabledLanguageFeatures = setOf("myFeature1", "myFeature2"),
optInAnnotationsInUse = setOf("myOptIn1", "myOptIn2"),
compilerPluginArguments = listOf("myCompilerPluginArgument1", "myCompilerPluginArgument2"),
compilerPluginClasspath = listOf(File("myCompilerPluginClasspath.jar").absoluteFile),
freeCompilerArgs = listOf("myFreeCompilerArguments")
)
val simpleBinaryCoordinates = IdeaKpmBinaryCoordinatesImpl(
group = "myGroup",
module = "myModule",
version = "myVersion",
kotlinModuleName = "myKotlinModuleName",
kotlinFragmentName = "myKotlinFragmentName"
)
val simpleUnresolvedBinaryDependency = IdeaKpmUnresolvedBinaryDependencyImpl(
cause = "myCause",
coordinates = simpleBinaryCoordinates
)
val simpleResolvedBinaryDependency = IdeaKpmResolvedBinaryDependencyImpl(
coordinates = simpleBinaryCoordinates,
binaryType = "myBinaryType",
binaryFile = File("myBinaryFile.jar").absoluteFile
)
val simpleFragmentDependency = IdeaKpmFragmentDependencyImpl(
type = IdeaKpmFragmentDependency.Type.Friend,
coordinates = simpleFragmentCoordinates
)
val simpleSourceDirectory = IdeaKpmContentRootImpl(
file = File("myFile").absoluteFile,
type = "myType"
)
val simpleFragment = IdeaKpmFragmentImpl(
coordinates = simpleFragmentCoordinates,
platforms = setOf(simpleJvmPlatform),
languageSettings = simpleLanguageSettings,
dependencies = listOf(simpleUnresolvedBinaryDependency, simpleResolvedBinaryDependency, simpleFragmentDependency),
contentRoots = listOf(simpleSourceDirectory),
extras = emptyExtras()
)
val fragmentWithExtras = simpleFragment.copy(
extras = extrasWithIntAndStrings
)
val simpleCompilationOutput = IdeaKpmCompilationOutputImpl(
classesDirs = setOf(File("myClassesDir").absoluteFile),
resourcesDir = File("myResourcesDir").absoluteFile
)
val simpleVariant = IdeaKpmVariantImpl(
fragment = simpleFragment,
platform = simpleJvmPlatform,
variantAttributes = mapOf("key1" to "attribute1", "key2" to "attribute2"),
compilationOutputs = simpleCompilationOutput
)
val variantWithExtras = simpleVariant.copy(
fragment = fragmentWithExtras
)
val simpleModule = IdeaKpmModuleImpl(
coordinates = simpleModuleCoordinates,
fragments = listOf(simpleFragment, simpleVariant)
)
val simpleProject = IdeaKpmProjectImpl(
gradlePluginVersion = "1.7.20",
coreLibrariesVersion = "1.6.20",
explicitApiModeCliOption = null,
kotlinNativeHome = File("myKotlinNativeHome").absoluteFile,
modules = listOf(simpleModule)
)
}
@@ -1,140 +0,0 @@
/*
* 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.
*/
@file:Suppress("DuplicatedCode")
package org.jetbrains.kotlin.gradle.idea.testFixtures.kpm
import org.jetbrains.kotlin.gradle.idea.kpm.*
import kotlin.test.fail
fun IdeaKpmProject.assertIsNotEmpty(): IdeaKpmProject = apply {
if (this.modules.isEmpty()) fail("Expected at least one module in model")
}
fun IdeaKpmProject.assertContainsModule(name: String): IdeaKpmModule {
return modules.find { it.name == name }
?: fail("Missing module with name '$name'. Found: ${modules.map { it.name }}")
}
fun IdeaKpmModule.assertContainsFragment(name: String): IdeaKpmFragment {
return fragments.find { it.name == name }
?: fail("Missing fragment with name '$name'. Found: ${fragments.map { it.name }}")
}
fun IdeaKpmFragment.assertResolvedBinaryDependencies(
binaryType: String,
matchers: Set<TestIdeaKpmBinaryDependencyMatcher>
): Set<IdeaKpmResolvedBinaryDependency> {
val resolvedBinaryDependencies = dependencies
.mapNotNull { dependency ->
when (dependency) {
is IdeaKpmResolvedBinaryDependencyImpl -> dependency
is IdeaKpmUnresolvedBinaryDependencyImpl -> fail("Unexpected unresolved dependency: $dependency")
is IdeaKpmFragmentDependencyImpl -> null
}
}
.filter { it.binaryType == binaryType }
.toSet()
val unexpectedResolvedBinaryDependencies = resolvedBinaryDependencies
.filter { dependency -> matchers.none { matcher -> matcher.matches(dependency) } }
val missingDependencies = matchers.filter { matcher ->
resolvedBinaryDependencies.none { dependency -> matcher.matches(dependency) }
}
if (unexpectedResolvedBinaryDependencies.isEmpty() && missingDependencies.isEmpty()) {
return resolvedBinaryDependencies
}
fail(
buildString {
if (unexpectedResolvedBinaryDependencies.isNotEmpty()) {
appendLine("${name}: Unexpected dependencies found:")
unexpectedResolvedBinaryDependencies.forEach { unexpectedDependency ->
appendLine(unexpectedDependency)
}
appendLine()
appendLine("${name}: Unexpected dependency coordinates:")
unexpectedResolvedBinaryDependencies.forEach { unexpectedDependency ->
appendLine("\"${unexpectedDependency.coordinates}\",")
}
}
if (missingDependencies.isNotEmpty()) {
appendLine()
appendLine("${name}: Missing dependencies:")
missingDependencies.forEach { missingDependency ->
appendLine(missingDependency.description)
}
}
appendLine()
appendLine("${name}: Resolved Dependency Coordinates:")
resolvedBinaryDependencies.mapNotNull { it.coordinates }.forEach { coordinates ->
appendLine("\"$coordinates\",")
}
}
)
}
@JvmName("assertResolvedBinaryDependenciesByAnyMatcher")
fun IdeaKpmFragment.assertResolvedBinaryDependencies(
binaryType: String, matchers: Set<Any?>,
) = assertResolvedBinaryDependencies(binaryType, matchers.flatMap { buildIdeaKpmBinaryDependencyMatchers(it) }.toSet())
fun IdeaKpmFragment.assertResolvedBinaryDependencies(
binaryType: String, vararg matchers: Any?
) = assertResolvedBinaryDependencies(binaryType, matchers.toSet())
fun IdeaKpmFragment.assertFragmentDependencies(matchers: Set<TestIdeaKpmFragmentDependencyMatcher>): Set<IdeaKpmFragmentDependency> {
val sourceDependencies = dependencies.filterIsInstance<IdeaKpmFragmentDependency>().toSet()
val unexpectedDependencies = sourceDependencies
.filter { dependency -> matchers.none { matcher -> matcher.matches(dependency) } }
val missingDependencies = matchers.filter { matcher ->
sourceDependencies.none { dependency -> matcher.matches(dependency) }
}
if (unexpectedDependencies.isEmpty() && missingDependencies.isEmpty()) {
return sourceDependencies
}
fail(
buildString {
if (unexpectedDependencies.isNotEmpty()) {
appendLine()
appendLine("${coordinates.path}: Unexpected source dependency found:")
unexpectedDependencies.forEach { unexpectedDependency ->
appendLine("\"${unexpectedDependency}\",")
}
}
if (missingDependencies.isNotEmpty()) {
appendLine()
appendLine("${coordinates.path}: Missing fragment dependencies:")
missingDependencies.forEach { missingDependency ->
appendLine(missingDependency.description)
}
}
appendLine()
appendLine("${coordinates.path}: Resolved source dependency paths:")
sourceDependencies.forEach { dependency ->
appendLine("\"${dependency}\",")
}
}
)
}
@JvmName("assertSourceDependenciesByAnyMatcher")
fun IdeaKpmFragment.assertFragmentDependencies(matchers: Set<Any?>): Set<IdeaKpmFragmentDependency> =
assertFragmentDependencies(matchers.flatMap { buildIdeaKpmFragmentDependencyMatchers(it) }.toSet())
fun IdeaKpmFragment.assertFragmentDependencies(vararg matchers: Any?) =
assertFragmentDependencies(matchers.toSet())
@@ -1,34 +0,0 @@
/*
* 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.idea.testFixtures.kpm
import org.jetbrains.kotlin.gradle.idea.kpm.IdeaKpmBinaryCoordinates
import org.jetbrains.kotlin.gradle.idea.kpm.IdeaKpmBinaryCoordinatesImpl
import org.jetbrains.kotlin.gradle.idea.kpm.IdeaKpmBinaryDependency
import org.jetbrains.kotlin.gradle.idea.kpm.IdeaKpmFragment
fun parseIdeaKpmBinaryCoordinates(coordinates: String): IdeaKpmBinaryCoordinates {
val parts = coordinates.split(":")
if (parts.size == 3) {
return IdeaKpmBinaryCoordinatesImpl(parts[0], parts[1], parts[2])
}
if (parts.size == 5) {
return IdeaKpmBinaryCoordinatesImpl(parts[0], parts[1], parts[2], parts[3], parts[4])
}
throw IllegalArgumentException("Cannot parse $coordinates into ${IdeaKpmBinaryCoordinates::class.java.simpleName}")
}
fun Iterable<IdeaKpmBinaryCoordinates>.parsableString() =
joinToString("," + System.lineSeparator(), "", "") { "\"$it\"" }
@Suppress("unused") // Debugging API
fun IdeaKpmFragment.parsableDependencyCoordinatesString(): String {
return dependencies.filterIsInstance<IdeaKpmBinaryDependency>()
.mapNotNull { it.coordinates }.toSet()
.parsableString()
}