summaryrefslogtreecommitdiff
path: root/plugins/kotlin/jps/jps-common/src/org/jetbrains
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/kotlin/jps/jps-common/src/org/jetbrains')
-rw-r--r--plugins/kotlin/jps/jps-common/src/org/jetbrains/kotlin/arguments/CompilerArgumentsContentProspector.kt46
-rw-r--r--plugins/kotlin/jps/jps-common/src/org/jetbrains/kotlin/arguments/CompilerArgumentsDeserializer.kt109
-rw-r--r--plugins/kotlin/jps/jps-common/src/org/jetbrains/kotlin/arguments/CompilerArgumentsSerializer.kt114
-rw-r--r--plugins/kotlin/jps/jps-common/src/org/jetbrains/kotlin/arguments/serializationUtils.kt18
-rw-r--r--plugins/kotlin/jps/jps-common/src/org/jetbrains/kotlin/config/CompilerRunnerConstants.kt11
-rw-r--r--plugins/kotlin/jps/jps-common/src/org/jetbrains/kotlin/config/CompilerSettings.kt26
-rw-r--r--plugins/kotlin/jps/jps-common/src/org/jetbrains/kotlin/config/JpsUtils.kt25
-rw-r--r--plugins/kotlin/jps/jps-common/src/org/jetbrains/kotlin/config/KotlinCommonJpsModelSerializerExtension.kt14
-rw-r--r--plugins/kotlin/jps/jps-common/src/org/jetbrains/kotlin/config/KotlinFacetSettings.kt289
-rw-r--r--plugins/kotlin/jps/jps-common/src/org/jetbrains/kotlin/config/KotlinResourceRootType.kt24
-rw-r--r--plugins/kotlin/jps/jps-common/src/org/jetbrains/kotlin/config/KotlinSourceRootType.kt23
-rw-r--r--plugins/kotlin/jps/jps-common/src/org/jetbrains/kotlin/config/SettingConstants.kt13
-rw-r--r--plugins/kotlin/jps/jps-common/src/org/jetbrains/kotlin/config/facetSerialization.kt465
-rw-r--r--plugins/kotlin/jps/jps-common/src/org/jetbrains/kotlin/config/moduleSourceRootPropertiesSerializers.kt83
-rw-r--r--plugins/kotlin/jps/jps-common/src/org/jetbrains/kotlin/platform/DefaultIdeTargetPlatformKindProvider.kt31
-rw-r--r--plugins/kotlin/jps/jps-common/src/org/jetbrains/kotlin/platform/IdePlatform.kt24
-rw-r--r--plugins/kotlin/jps/jps-common/src/org/jetbrains/kotlin/platform/IdePlatformKind.kt88
-rw-r--r--plugins/kotlin/jps/jps-common/src/org/jetbrains/kotlin/platform/compat/compatConversions.kt62
-rw-r--r--plugins/kotlin/jps/jps-common/src/org/jetbrains/kotlin/platform/impl/CommonIdePlatformKind.kt57
-rw-r--r--plugins/kotlin/jps/jps-common/src/org/jetbrains/kotlin/platform/impl/IdeaDefaultIdeTargetPlatformKindProvider.kt9
-rw-r--r--plugins/kotlin/jps/jps-common/src/org/jetbrains/kotlin/platform/impl/JsIdePlatformKind.kt63
-rw-r--r--plugins/kotlin/jps/jps-common/src/org/jetbrains/kotlin/platform/impl/JvmIdePlatformKind.kt74
-rw-r--r--plugins/kotlin/jps/jps-common/src/org/jetbrains/kotlin/platform/impl/NativeIdePlatformKind.kt67
23 files changed, 0 insertions, 1735 deletions
diff --git a/plugins/kotlin/jps/jps-common/src/org/jetbrains/kotlin/arguments/CompilerArgumentsContentProspector.kt b/plugins/kotlin/jps/jps-common/src/org/jetbrains/kotlin/arguments/CompilerArgumentsContentProspector.kt
deleted file mode 100644
index 92b01d4659c5..000000000000
--- a/plugins/kotlin/jps/jps-common/src/org/jetbrains/kotlin/arguments/CompilerArgumentsContentProspector.kt
+++ /dev/null
@@ -1,46 +0,0 @@
-// Copyright 2000-2021 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
-package org.jetbrains.kotlin.arguments
-
-import org.jetbrains.kotlin.cli.common.arguments.Argument
-import org.jetbrains.kotlin.cli.common.arguments.CommonToolArguments
-import org.jetbrains.kotlin.cli.common.arguments.InternalArgument
-import org.jetbrains.kotlin.utils.addToStdlib.safeAs
-import kotlin.reflect.KClass
-import kotlin.reflect.KProperty1
-import kotlin.reflect.KType
-import kotlin.reflect.full.memberProperties
-
-object CompilerArgumentsContentProspector {
- private val argumentPropertiesCache: MutableMap<KClass<out CommonToolArguments>, Collection<KProperty1<out CommonToolArguments, *>>> =
- mutableMapOf()
-
- private val flagArgumentPropertiesCache: MutableMap<KClass<out CommonToolArguments>, Collection<KProperty1<out CommonToolArguments, Boolean>>> =
- mutableMapOf()
-
- private val stringArgumentPropertiesCache: MutableMap<KClass<out CommonToolArguments>, Collection<KProperty1<out CommonToolArguments, String?>>> =
- mutableMapOf()
-
- private val arrayArgumentPropertiesCache: MutableMap<KClass<out CommonToolArguments>, Collection<KProperty1<out CommonToolArguments, Array<String>?>>> =
- mutableMapOf()
-
- private fun getCompilerArgumentsProperties(kClass: KClass<out CommonToolArguments>) = argumentPropertiesCache.getOrPut(kClass) {
- kClass.memberProperties.filter { prop -> prop.annotations.any { it is Argument } }
- }
-
- private inline fun <reified R : Any?> Collection<KProperty1<out CommonToolArguments, *>>.filterByReturnType(predicate: (KType?) -> Boolean) =
- filter { predicate(it.returnType) }.mapNotNull { it.safeAs<KProperty1<CommonToolArguments, R>>() }
-
- fun getFlagCompilerArgumentProperties(kClass: KClass<out CommonToolArguments>): Collection<KProperty1<out CommonToolArguments, Boolean>> =
- flagArgumentPropertiesCache.getOrPut(kClass) { getCompilerArgumentsProperties(kClass).filterByReturnType { it?.classifier == Boolean::class } }
-
- fun getStringCompilerArgumentProperties(kClass: KClass<out CommonToolArguments>): Collection<KProperty1<out CommonToolArguments, String?>> =
- stringArgumentPropertiesCache.getOrPut(kClass) { getCompilerArgumentsProperties(kClass).filterByReturnType { it?.classifier == String::class } }
-
- fun getArrayCompilerArgumentProperties(kClass: KClass<out CommonToolArguments>): Collection<KProperty1<out CommonToolArguments, Array<String>?>> =
- arrayArgumentPropertiesCache.getOrPut(kClass) { getCompilerArgumentsProperties(kClass).filterByReturnType { (it?.classifier as? KClass<*>)?.java?.isArray == true } }
-
- val freeArgsProperty: KProperty1<in CommonToolArguments, List<String>>
- get() = CommonToolArguments::freeArgs
- val internalArgumentsProperty: KProperty1<in CommonToolArguments, List<InternalArgument>>
- get() = CommonToolArguments::internalArguments
-} \ No newline at end of file
diff --git a/plugins/kotlin/jps/jps-common/src/org/jetbrains/kotlin/arguments/CompilerArgumentsDeserializer.kt b/plugins/kotlin/jps/jps-common/src/org/jetbrains/kotlin/arguments/CompilerArgumentsDeserializer.kt
deleted file mode 100644
index ad7f48c27167..000000000000
--- a/plugins/kotlin/jps/jps-common/src/org/jetbrains/kotlin/arguments/CompilerArgumentsDeserializer.kt
+++ /dev/null
@@ -1,109 +0,0 @@
-// Copyright 2000-2021 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
-package org.jetbrains.kotlin.arguments
-
-import org.jdom.Element
-import org.jdom.Text
-import org.jetbrains.kotlin.cli.common.arguments.ArgumentParseErrors
-import org.jetbrains.kotlin.cli.common.arguments.CommonToolArguments
-import org.jetbrains.kotlin.cli.common.arguments.InternalArgument
-import org.jetbrains.kotlin.cli.common.arguments.LanguageSettingsParser
-import org.jetbrains.kotlin.utils.addToStdlib.safeAs
-import java.io.File
-import kotlin.reflect.KMutableProperty1
-
-interface CompilerArgumentsDeserializer<T : CommonToolArguments> {
- val compilerArguments: T
- fun deserializeFrom(element: Element)
-}
-
-class CompilerArgumentsDeserializerV5<T : CommonToolArguments>(override val compilerArguments: T) : CompilerArgumentsDeserializer<T> {
- override fun deserializeFrom(element: Element) {
- val flagArgumentsByName = readFlagArguments(element)
- val flagArgumentsPropertiesMap = CompilerArgumentsContentProspector.getFlagCompilerArgumentProperties(compilerArguments::class)
- .associateBy { it.name }
- flagArgumentsByName.forEach { (name, value) ->
- val mutableProp = flagArgumentsPropertiesMap[name].safeAs<KMutableProperty1<T, Boolean>>() ?: return@forEach
- mutableProp.set(compilerArguments, value)
- }
-
- val stringArgumentsByName = readStringArguments(element)
- val stringArgumentPropertiesMap = CompilerArgumentsContentProspector.getStringCompilerArgumentProperties(compilerArguments::class)
- .associateBy { it.name }
- stringArgumentsByName.forEach { (name, arg) ->
- val mutableProp = stringArgumentPropertiesMap[name].safeAs<KMutableProperty1<T, String?>>() ?: return@forEach
- mutableProp.set(compilerArguments, arg)
- }
- val arrayArgumentsByName = readArrayArguments(element)
- val arrayArgumentPropertiesMap = CompilerArgumentsContentProspector.getArrayCompilerArgumentProperties(compilerArguments::class)
- .associateBy { it.name }
- arrayArgumentsByName.forEach { (name, arr) ->
- val mutableProp = arrayArgumentPropertiesMap[name].safeAs<KMutableProperty1<T, Array<String>?>>() ?: return@forEach
- mutableProp.set(compilerArguments, arr)
- }
- val freeArgs = readElementsList(element, FREE_ARGS_ROOT_ELEMENTS_NAME, FREE_ARGS_ELEMENT_NAME)
- CompilerArgumentsContentProspector.freeArgsProperty.also {
- val mutableProp = it.safeAs<KMutableProperty1<T, List<String>>>() ?: return@also
- mutableProp.set(compilerArguments, freeArgs)
- }
-
- val internalArguments = readElementsList(element, INTERNAL_ARGS_ROOT_ELEMENTS_NAME, INTERNAL_ARGS_ELEMENT_NAME)
- .mapNotNull { parseInternalArgument(it) }
- CompilerArgumentsContentProspector.internalArgumentsProperty.safeAs<KMutableProperty1<T, List<InternalArgument>>>()
- ?.set(compilerArguments, internalArguments)
- }
-
- companion object {
- private fun readElementConfigurable(element: Element, rootElementName: String, configurable: Element.() -> Unit) {
- element.getChild(rootElementName)?.apply { configurable(this) }
- }
-
- private fun readStringArguments(element: Element): Map<String, String> = mutableMapOf<String, String>().also {
- readElementConfigurable(element, STRING_ROOT_ELEMENTS_NAME) {
- getChildren(STRING_ELEMENT_NAME).forEach { child ->
- val name = child.getAttribute(NAME_ATTR_NAME)?.value ?: return@forEach
- val arg = if (name == "classpath")
- readElementsList(child, ARGS_ATTR_NAME, ARG_ATTR_NAME).joinToString(File.pathSeparator)
- else child.getAttribute(ARG_ATTR_NAME)?.value ?: return@forEach
- it += name to arg
- }
- }
- }
-
- private fun readFlagArguments(element: Element): Map<String, Boolean> = mutableMapOf<String, Boolean>().also {
- readElementConfigurable(element, FLAG_ROOT_ELEMENTS_NAME) {
- getChildren(FLAG_ELEMENT_NAME).forEach { child ->
- val name = child.getAttribute(NAME_ATTR_NAME)?.value ?: return@forEach
- val arg = child.getAttribute(ARG_ATTR_NAME)?.booleanValue ?: return@forEach
- it += name to arg
- }
- }
- }
-
- private fun readElementsList(element: Element, rootElementName: String, elementName: String): List<String> =
- mutableListOf<String>().also { list ->
- readElementConfigurable(element, rootElementName) {
- val items = getChildren(elementName)
- if (items.isNotEmpty()) {
- items.mapNotNullTo(list) { (it.content.firstOrNull() as? Text)?.textTrim }
- } else {
- list += listOfNotNull((content.firstOrNull() as? Text)?.textTrim)
- }
- }
- }
-
- private fun readArrayArguments(element: Element): Map<String, Array<String>> = mutableMapOf<String, Array<String>>().apply {
- readElementConfigurable(element, ARRAY_ROOT_ELEMENTS_NAME) {
- getChildren(ARRAY_ELEMENT_NAME).forEach { child ->
- val name = child.getAttribute(NAME_ATTR_NAME)?.value ?: return@forEach
- val array = readElementsList(child, ARGS_ATTR_NAME, ARG_ATTR_NAME).toTypedArray()
- this@apply += name to array
- }
- }
- }
-
- private fun parseInternalArgument(argument: String): InternalArgument? {
- val parser = LanguageSettingsParser()
- return parser.parseInternalArgument(argument, ArgumentParseErrors())
- }
- }
-} \ No newline at end of file
diff --git a/plugins/kotlin/jps/jps-common/src/org/jetbrains/kotlin/arguments/CompilerArgumentsSerializer.kt b/plugins/kotlin/jps/jps-common/src/org/jetbrains/kotlin/arguments/CompilerArgumentsSerializer.kt
deleted file mode 100644
index 7d8d73cc8d01..000000000000
--- a/plugins/kotlin/jps/jps-common/src/org/jetbrains/kotlin/arguments/CompilerArgumentsSerializer.kt
+++ /dev/null
@@ -1,114 +0,0 @@
-// Copyright 2000-2021 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
-package org.jetbrains.kotlin.arguments
-
-import org.jdom.Element
-import org.jetbrains.kotlin.cli.common.arguments.CommonToolArguments
-import org.jetbrains.kotlin.config.restoreNormalOrdering
-import org.jetbrains.kotlin.utils.addToStdlib.safeAs
-import java.io.File
-import kotlin.reflect.KProperty1
-
-interface CompilerArgumentsSerializer<T : CommonToolArguments> {
- val arguments: T
- fun serializeTo(element: Element): Element
-}
-
-class CompilerArgumentsSerializerV5<T : CommonToolArguments>(override val arguments: T) : CompilerArgumentsSerializer<T> {
-
- override fun serializeTo(element: Element): Element = Element(COMPILER_ARGUMENTS_ELEMENT_NAME).apply {
- val newInstance = arguments::class.java.getConstructor().newInstance()
- val flagArgumentsByName = CompilerArgumentsContentProspector.getFlagCompilerArgumentProperties(arguments::class)
- .mapNotNull { prop ->
- prop.safeAs<KProperty1<T, Boolean>>()
- ?.takeIf { it.get(arguments) != it.get(newInstance) }
- ?.get(arguments)
- ?.let { prop.name to it }
- }.toMap()
- saveFlagArguments(this, flagArgumentsByName)
-
- val stringArgumentsByName = CompilerArgumentsContentProspector.getStringCompilerArgumentProperties(arguments::class)
- .mapNotNull { prop ->
- prop.safeAs<KProperty1<T, String?>>()
- ?.takeIf { it.get(arguments) != it.get(newInstance) }
- ?.get(arguments)
- ?.let { prop.name to it }
- }.toMap()
- saveStringArguments(this, stringArgumentsByName)
-
- val arrayArgumentsByName = CompilerArgumentsContentProspector.getArrayCompilerArgumentProperties(arguments::class)
- .mapNotNull { prop ->
- prop.safeAs<KProperty1<T, Array<String>?>>()
- ?.takeIf { it.get(arguments)?.contentEquals(it.get(newInstance)) != true }
- ?.get(arguments)
- ?.let { prop.name to it }
- }.toMap()
- saveArrayArguments(this, arrayArgumentsByName)
- val freeArgs = CompilerArgumentsContentProspector.freeArgsProperty.get(arguments)
- saveElementsList(this, FREE_ARGS_ROOT_ELEMENTS_NAME, FREE_ARGS_ELEMENT_NAME, freeArgs)
- val internalArguments = CompilerArgumentsContentProspector.internalArgumentsProperty.get(arguments).map { it.stringRepresentation }
- saveElementsList(this, INTERNAL_ARGS_ROOT_ELEMENTS_NAME, INTERNAL_ARGS_ELEMENT_NAME, internalArguments)
- restoreNormalOrdering(arguments)
- element.addContent(this)
- }
-
- companion object {
- private fun saveElementConfigurable(element: Element, rootElementName: String, configurable: Element.() -> Unit) {
- element.addContent(Element(rootElementName).apply { configurable(this) })
- }
-
- private fun saveStringArguments(element: Element, argumentsByName: Map<String, String>) {
- if (argumentsByName.isEmpty()) return
- saveElementConfigurable(element, STRING_ROOT_ELEMENTS_NAME) {
- argumentsByName.entries.forEach { (name, arg) ->
- Element(STRING_ELEMENT_NAME).also {
- it.setAttribute(NAME_ATTR_NAME, name)
- if (name == "classpath") {
- saveElementsList(it, ARGS_ATTR_NAME, ARG_ATTR_NAME, arg.split(File.pathSeparator))
- } else {
- it.setAttribute(ARG_ATTR_NAME, arg)
- }
- addContent(it)
- }
- }
- }
- }
-
- private fun saveFlagArguments(element: Element, argumentsByName: Map<String, Boolean>) {
- if (argumentsByName.isEmpty()) return
- saveElementConfigurable(element, FLAG_ROOT_ELEMENTS_NAME) {
- argumentsByName.entries.forEach { (name, arg) ->
- Element(FLAG_ELEMENT_NAME).also {
- it.setAttribute(NAME_ATTR_NAME, name)
- it.setAttribute(ARG_ATTR_NAME, arg.toString())
- addContent(it)
- }
- }
- }
- }
-
- private fun saveElementsList(element: Element, rootElementName: String, elementName: String, elementList: List<String>) {
- if (elementList.isEmpty()) return
- saveElementConfigurable(element, rootElementName) {
- val singleModule = elementList.singleOrNull()
- if (singleModule != null) {
- addContent(singleModule)
- } else {
- elementList.forEach { elementValue -> addContent(Element(elementName).also { it.addContent(elementValue) }) }
- }
- }
- }
-
- private fun saveArrayArguments(element: Element, arrayArgumentsByName: Map<String, Array<String>>) {
- if (arrayArgumentsByName.isEmpty()) return
- saveElementConfigurable(element, ARRAY_ROOT_ELEMENTS_NAME) {
- arrayArgumentsByName.entries.forEach { (name, arg) ->
- Element(ARRAY_ELEMENT_NAME).also {
- it.setAttribute(NAME_ATTR_NAME, name)
- saveElementsList(it, ARGS_ATTR_NAME, ARG_ATTR_NAME, arg.toList())
- addContent(it)
- }
- }
- }
- }
- }
-} \ No newline at end of file
diff --git a/plugins/kotlin/jps/jps-common/src/org/jetbrains/kotlin/arguments/serializationUtils.kt b/plugins/kotlin/jps/jps-common/src/org/jetbrains/kotlin/arguments/serializationUtils.kt
deleted file mode 100644
index e0af786e454d..000000000000
--- a/plugins/kotlin/jps/jps-common/src/org/jetbrains/kotlin/arguments/serializationUtils.kt
+++ /dev/null
@@ -1,18 +0,0 @@
-// Copyright 2000-2021 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
-package org.jetbrains.kotlin.arguments
-
-internal const val COMPILER_ARGUMENTS_ELEMENT_NAME = "compilerArguments"
-internal const val FLAG_ROOT_ELEMENTS_NAME = "flagArguments"
-internal const val FLAG_ELEMENT_NAME = "flagArg"
-internal const val STRING_ROOT_ELEMENTS_NAME = "stringArguments"
-internal const val STRING_ELEMENT_NAME = "stringArg"
-internal const val ARRAY_ROOT_ELEMENTS_NAME = "arrayArguments"
-internal const val ARRAY_ELEMENT_NAME = "arrayArg"
-internal const val FREE_ARGS_ROOT_ELEMENTS_NAME = "freeArgs"
-internal const val FREE_ARGS_ELEMENT_NAME = "freeArg"
-internal const val INTERNAL_ARGS_ROOT_ELEMENTS_NAME = "internalArgs"
-internal const val INTERNAL_ARGS_ELEMENT_NAME = "internalArg"
-
-internal const val NAME_ATTR_NAME = "name"
-internal const val ARG_ATTR_NAME = "arg"
-internal const val ARGS_ATTR_NAME = "args"
diff --git a/plugins/kotlin/jps/jps-common/src/org/jetbrains/kotlin/config/CompilerRunnerConstants.kt b/plugins/kotlin/jps/jps-common/src/org/jetbrains/kotlin/config/CompilerRunnerConstants.kt
deleted file mode 100644
index 97fb39c3dcdb..000000000000
--- a/plugins/kotlin/jps/jps-common/src/org/jetbrains/kotlin/config/CompilerRunnerConstants.kt
+++ /dev/null
@@ -1,11 +0,0 @@
-// Copyright 2000-2021 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
-
-package org.jetbrains.kotlin.config
-
-import com.intellij.openapi.util.NlsSafe
-
-object CompilerRunnerConstants {
- const val KOTLIN_COMPILER_NAME = "Kotlin"
- @NlsSafe
- const val INTERNAL_ERROR_PREFIX = "[Internal Error] "
-}
diff --git a/plugins/kotlin/jps/jps-common/src/org/jetbrains/kotlin/config/CompilerSettings.kt b/plugins/kotlin/jps/jps-common/src/org/jetbrains/kotlin/config/CompilerSettings.kt
deleted file mode 100644
index 05003fedc2b2..000000000000
--- a/plugins/kotlin/jps/jps-common/src/org/jetbrains/kotlin/config/CompilerSettings.kt
+++ /dev/null
@@ -1,26 +0,0 @@
-// Copyright 2000-2021 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
-
-package org.jetbrains.kotlin.config
-
-import com.intellij.openapi.util.text.StringUtil
-import org.jetbrains.kotlin.cli.common.arguments.Freezable
-
-class CompilerSettings : Freezable() {
- var additionalArguments: String by FreezableVar(DEFAULT_ADDITIONAL_ARGUMENTS)
- var scriptTemplates: String by FreezableVar("")
- var scriptTemplatesClasspath: String by FreezableVar("")
- var copyJsLibraryFiles: Boolean by FreezableVar(true)
- var outputDirectoryForJsLibraryFiles: String by FreezableVar(DEFAULT_OUTPUT_DIRECTORY)
-
- companion object {
- val DEFAULT_ADDITIONAL_ARGUMENTS = "-version"
- private val DEFAULT_OUTPUT_DIRECTORY = "lib"
- }
-}
-
-val CompilerSettings.additionalArgumentsAsList: List<String>
- get() = splitArgumentString(additionalArguments)
-
-fun splitArgumentString(arguments: String) = StringUtil.splitHonorQuotes(arguments, ' ').map {
- if (it.startsWith('"')) StringUtil.unescapeChar(StringUtil.unquoteString(it), '"') else it
-} \ No newline at end of file
diff --git a/plugins/kotlin/jps/jps-common/src/org/jetbrains/kotlin/config/JpsUtils.kt b/plugins/kotlin/jps/jps-common/src/org/jetbrains/kotlin/config/JpsUtils.kt
deleted file mode 100644
index 7ae0f5edc4c9..000000000000
--- a/plugins/kotlin/jps/jps-common/src/org/jetbrains/kotlin/config/JpsUtils.kt
+++ /dev/null
@@ -1,25 +0,0 @@
-// Copyright 2000-2021 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
-
-package org.jetbrains.kotlin.config
-
-import com.intellij.openapi.application.ApplicationManager
-
-private const val APPLICATION_MANAGER_CLASS_NAME = "com.intellij.openapi.application.ApplicationManager"
-
-val isJps: Boolean by lazy {
- /*
- Normally, JPS shouldn't have an ApplicationManager class in the classpath,
- but that's not true for JPS inside IDEA right now.
- Though Application is not properly initialized inside JPS so we can use it as a check.
- */
- return@lazy if (doesClassExist(APPLICATION_MANAGER_CLASS_NAME)) {
- ApplicationManager.getApplication() == null
- } else {
- true
- }
-}
-
-private fun doesClassExist(fqName: String): Boolean {
- val classPath = fqName.replace('.', '/') + ".class"
- return {}.javaClass.classLoader.getResource(classPath) != null
-} \ No newline at end of file
diff --git a/plugins/kotlin/jps/jps-common/src/org/jetbrains/kotlin/config/KotlinCommonJpsModelSerializerExtension.kt b/plugins/kotlin/jps/jps-common/src/org/jetbrains/kotlin/config/KotlinCommonJpsModelSerializerExtension.kt
deleted file mode 100644
index 727ce1c309e6..000000000000
--- a/plugins/kotlin/jps/jps-common/src/org/jetbrains/kotlin/config/KotlinCommonJpsModelSerializerExtension.kt
+++ /dev/null
@@ -1,14 +0,0 @@
-// Copyright 2000-2021 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
-package org.jetbrains.kotlin.config
-
-import org.jetbrains.jps.model.serialization.JpsModelSerializerExtension
-import org.jetbrains.jps.model.serialization.module.JpsModuleSourceRootPropertiesSerializer
-
-open class KotlinCommonJpsModelSerializerExtension : JpsModelSerializerExtension() {
- override fun getModuleSourceRootPropertiesSerializers(): List<JpsModuleSourceRootPropertiesSerializer<*>> = listOf(
- KotlinSourceRootPropertiesSerializer.Source,
- KotlinSourceRootPropertiesSerializer.TestSource,
- KotlinResourceRootPropertiesSerializer.Resource,
- KotlinResourceRootPropertiesSerializer.TestResource
- )
-} \ No newline at end of file
diff --git a/plugins/kotlin/jps/jps-common/src/org/jetbrains/kotlin/config/KotlinFacetSettings.kt b/plugins/kotlin/jps/jps-common/src/org/jetbrains/kotlin/config/KotlinFacetSettings.kt
deleted file mode 100644
index f97ab59406a1..000000000000
--- a/plugins/kotlin/jps/jps-common/src/org/jetbrains/kotlin/config/KotlinFacetSettings.kt
+++ /dev/null
@@ -1,289 +0,0 @@
-// Copyright 2000-2021 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
-
-package org.jetbrains.kotlin.config
-
-import com.intellij.openapi.module.Module
-import com.intellij.openapi.project.Project
-import org.jetbrains.kotlin.cli.common.arguments.Argument
-import org.jetbrains.kotlin.cli.common.arguments.CommonCompilerArguments
-import org.jetbrains.kotlin.cli.common.arguments.copyBean
-import org.jetbrains.kotlin.cli.common.arguments.parseCommandLineArguments
-import org.jetbrains.kotlin.platform.IdePlatformKind
-import org.jetbrains.kotlin.platform.TargetPlatform
-import org.jetbrains.kotlin.platform.TargetPlatformVersion
-import org.jetbrains.kotlin.platform.compat.toIdePlatform
-import org.jetbrains.kotlin.platform.isCommon
-import org.jetbrains.kotlin.platform.jvm.JvmPlatforms
-import org.jetbrains.kotlin.utils.DescriptionAware
-import org.jetbrains.kotlin.utils.addToStdlib.safeAs
-import kotlin.reflect.KProperty1
-import kotlin.reflect.full.findAnnotation
-
-@Deprecated("Use IdePlatformKind instead.", level = DeprecationLevel.ERROR)
-sealed class TargetPlatformKind<out Version : TargetPlatformVersion>(
- val version: Version,
- val name: String
-) : DescriptionAware {
- override val description = "$name ${version.description}"
-
- class Jvm(version: JvmTarget) : @Suppress("DEPRECATION_ERROR") TargetPlatformKind<JvmTarget>(version, "JVM") {
- companion object {
- private val JVM_PLATFORMS by lazy { JvmTarget.values().map(::Jvm) }
- operator fun get(version: JvmTarget) = JVM_PLATFORMS[version.ordinal]
- }
- }
-
- object JavaScript : @Suppress("DEPRECATION_ERROR") TargetPlatformKind<TargetPlatformVersion.NoVersion>(
- TargetPlatformVersion.NoVersion,
- "JavaScript"
- )
-
- object Common : @Suppress("DEPRECATION_ERROR") TargetPlatformKind<TargetPlatformVersion.NoVersion>(
- TargetPlatformVersion.NoVersion,
- "Common (experimental)"
- )
-}
-
-sealed class VersionView : DescriptionAware {
- abstract val version: LanguageOrApiVersion
-
- object LatestStable : VersionView() {
- override val version: LanguageVersion = RELEASED_VERSION
-
- override val description: String
- get() = "Latest stable (${version.versionString})"
- }
-
- class Specific(override val version: LanguageOrApiVersion) : VersionView() {
- override val description: String
- get() = version.description
-
- override fun equals(other: Any?) = other is Specific && version == other.version
-
- override fun hashCode() = version.hashCode()
- }
-
- companion object {
- val RELEASED_VERSION = LanguageVersion.LATEST_STABLE
-
- fun deserialize(value: String?, isAutoAdvance: Boolean): VersionView {
- if (isAutoAdvance) return LatestStable
- val languageVersion = LanguageVersion.fromVersionString(value)
- return if (languageVersion != null) Specific(languageVersion) else LatestStable
- }
- }
-}
-
-var CommonCompilerArguments.languageVersionView: VersionView
- get() = VersionView.deserialize(languageVersion, autoAdvanceLanguageVersion)
- set(value) {
- languageVersion = value.version.versionString
- autoAdvanceLanguageVersion = value == VersionView.LatestStable
- }
-
-var CommonCompilerArguments.apiVersionView: VersionView
- get() = VersionView.deserialize(apiVersion, autoAdvanceApiVersion)
- set(value) {
- apiVersion = value.version.versionString
- autoAdvanceApiVersion = value == VersionView.LatestStable
- }
-
-enum class KotlinModuleKind {
- DEFAULT,
- SOURCE_SET_HOLDER,
- COMPILATION_AND_SOURCE_SET_HOLDER;
-
- @Deprecated("Use KotlinFacetSettings.mppVersion.isNewMpp")
- val isNewMPP: Boolean
- get() = this != DEFAULT
-}
-
-enum class KotlinMultiplatformVersion(val version: Int) {
- M1(1), // the first implementation of MPP. Aka 1.2.0 MPP
- M2(2), // the "New" MPP. Aka 1.3.0 MPP
- M3(3) // the "Hierarchical" MPP.
-}
-
-val KotlinMultiplatformVersion?.isOldMpp: Boolean
- get() = this == KotlinMultiplatformVersion.M1
-
-val KotlinMultiplatformVersion?.isNewMPP: Boolean
- get() = this == KotlinMultiplatformVersion.M2
-
-val KotlinMultiplatformVersion?.isHmpp: Boolean
- get() = this == KotlinMultiplatformVersion.M3
-
-interface ExternalSystemRunTask {
- val taskName: String
- val externalSystemProjectId: String
- val targetName: String?
-}
-
-data class ExternalSystemTestRunTask(
- override val taskName: String,
- override val externalSystemProjectId: String,
- override val targetName: String?
-) : ExternalSystemRunTask {
-
- fun toStringRepresentation() = "$taskName|$externalSystemProjectId|$targetName"
-
- companion object {
- fun fromStringRepresentation(line: String) =
- line.split("|").let { if (it.size == 3) ExternalSystemTestRunTask(it[0], it[1], it[2]) else null }
- }
-
- override fun toString() = "$taskName@$externalSystemProjectId [$targetName]"
-}
-
-data class ExternalSystemNativeMainRunTask(
- override val taskName: String,
- override val externalSystemProjectId: String,
- override val targetName: String?,
- val entryPoint: String,
- val debuggable: Boolean,
-) : ExternalSystemRunTask {
-
- fun toStringRepresentation() = "$taskName|$externalSystemProjectId|$targetName|$entryPoint|$debuggable"
-
- companion object {
- fun fromStringRepresentation(line: String): ExternalSystemNativeMainRunTask? =
- line.split("|").let {
- if (it.size == 5) ExternalSystemNativeMainRunTask(it[0], it[1], it[2], it[3], it[4].toBoolean()) else null
- }
- }
-}
-
-class KotlinFacetSettings {
- companion object {
- // Increment this when making serialization-incompatible changes to configuration data
- val CURRENT_VERSION = 5
- val DEFAULT_VERSION = 0
- }
-
- var version = CURRENT_VERSION
- var useProjectSettings: Boolean = true
-
- var mergedCompilerArguments: CommonCompilerArguments? = null
- private set
-
- // TODO: Workaround for unwanted facet settings modification on code analysis
- // To be replaced with proper API for settings update (see BaseKotlinCompilerSettings as an example)
- fun updateMergedArguments() {
- val compilerArguments = compilerArguments
- val compilerSettings = compilerSettings
-
- mergedCompilerArguments = if (compilerArguments != null) {
- copyBean(compilerArguments).apply {
- if (compilerSettings != null) {
- parseCommandLineArguments(compilerSettings.additionalArgumentsAsList, this)
- }
- }
- } else null
- }
-
- var compilerArguments: CommonCompilerArguments? = null
- set(value) {
- field = value?.unfrozen() as CommonCompilerArguments?
- updateMergedArguments()
- }
-
- var compilerSettings: CompilerSettings? = null
- set(value) {
- field = value?.unfrozen() as CompilerSettings?
- updateMergedArguments()
- }
-
- /*
- This function is needed as some setting values may not be present in compilerArguments
- but present in additional arguments instead, so we have to check both cases manually
- */
- inline fun <reified A : CommonCompilerArguments> isCompilerSettingPresent(settingReference: KProperty1<A, Boolean>): Boolean {
- val isEnabledByCompilerArgument = compilerArguments?.safeAs<A>()?.let(settingReference::get)
- if (isEnabledByCompilerArgument == true) return true
- val isEnabledByAdditionalSettings = run {
- val stringArgumentName = settingReference.findAnnotation<Argument>()?.value ?: return@run null
- compilerSettings?.additionalArguments?.contains(stringArgumentName, ignoreCase = true)
- }
- return isEnabledByAdditionalSettings ?: false
- }
-
- var languageLevel: LanguageVersion?
- get() = compilerArguments?.languageVersion?.let { LanguageVersion.fromFullVersionString(it) }
- set(value) {
- compilerArguments?.apply {
- languageVersion = value?.versionString
- }
- }
-
- var apiLevel: LanguageVersion?
- get() = compilerArguments?.apiVersion?.let { LanguageVersion.fromFullVersionString(it) }
- set(value) {
- compilerArguments?.apply {
- apiVersion = value?.versionString
- }
- }
-
- var targetPlatform: TargetPlatform? = null
- get() {
- // This work-around is required in order to fix importing of the proper JVM target version and works only
- // for fully actualized JVM target platform
- //TODO(auskov): this hack should be removed after fixing equals in SimplePlatform
- val args = compilerArguments
- val singleSimplePlatform = field?.componentPlatforms?.singleOrNull()
- if (singleSimplePlatform == JvmPlatforms.defaultJvmPlatform.singleOrNull() && args != null) {
- return IdePlatformKind.platformByCompilerArguments(args)
- }
- return field
- }
-
- var externalSystemRunTasks: List<ExternalSystemRunTask> = emptyList()
-
- @Suppress("DEPRECATION_ERROR")
- @Deprecated(
- message = "This accessor is deprecated and will be removed soon, use API from 'org.jetbrains.kotlin.platform.*' packages instead",
- replaceWith = ReplaceWith("targetPlatform"),
- level = DeprecationLevel.ERROR
- )
- fun getPlatform(): org.jetbrains.kotlin.platform.IdePlatform<*, *>? {
- return targetPlatform?.toIdePlatform()
- }
-
- var implementedModuleNames: List<String> = emptyList() // used for first implementation of MPP, aka 'old' MPP
- var dependsOnModuleNames: List<String> = emptyList() // used for New MPP and later implementations
-
- var additionalVisibleModuleNames: Set<String> = emptySet()
-
- var productionOutputPath: String? = null
- var testOutputPath: String? = null
-
- var kind: KotlinModuleKind = KotlinModuleKind.DEFAULT
- var sourceSetNames: List<String> = emptyList()
- var isTestModule: Boolean = false
-
- var externalProjectId: String = ""
-
- var isHmppEnabled: Boolean = false
- @Deprecated(message = "Use mppVersion.isHmppEnabled", ReplaceWith("mppVersion.isHmpp"))
- get
-
- val mppVersion: KotlinMultiplatformVersion?
- @Suppress("DEPRECATION")
- get() = when {
- isHmppEnabled -> KotlinMultiplatformVersion.M3
- kind.isNewMPP -> KotlinMultiplatformVersion.M2
- targetPlatform.isCommon() || implementedModuleNames.isNotEmpty() -> KotlinMultiplatformVersion.M1
- else -> null
- }
-
- var pureKotlinSourceFolders: List<String> = emptyList()
-}
-
-interface KotlinFacetSettingsProvider {
- fun getSettings(module: Module): KotlinFacetSettings?
- fun getInitializedSettings(module: Module): KotlinFacetSettings
-
- companion object {
- fun getInstance(project: Project): KotlinFacetSettingsProvider? = project.takeUnless(Project::isDisposed)
- ?.getService(KotlinFacetSettingsProvider::class.java)
- }
-}
diff --git a/plugins/kotlin/jps/jps-common/src/org/jetbrains/kotlin/config/KotlinResourceRootType.kt b/plugins/kotlin/jps/jps-common/src/org/jetbrains/kotlin/config/KotlinResourceRootType.kt
deleted file mode 100644
index 66aa7d8e9666..000000000000
--- a/plugins/kotlin/jps/jps-common/src/org/jetbrains/kotlin/config/KotlinResourceRootType.kt
+++ /dev/null
@@ -1,24 +0,0 @@
-// Copyright 2000-2021 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
-
-package org.jetbrains.kotlin.config
-
-import org.jetbrains.jps.model.ex.JpsElementTypeBase
-import org.jetbrains.jps.model.java.JavaResourceRootProperties
-import org.jetbrains.jps.model.java.JavaResourceRootType
-import org.jetbrains.jps.model.java.JpsJavaExtensionService
-import org.jetbrains.jps.model.module.JpsModuleSourceRootType
-
-sealed class KotlinResourceRootType() : JpsElementTypeBase<JavaResourceRootProperties>(),
- JpsModuleSourceRootType<JavaResourceRootProperties> {
-
- override fun createDefaultProperties() =
- JpsJavaExtensionService.getInstance().createResourceRootProperties("", false)
-}
-
-object ResourceKotlinRootType : KotlinResourceRootType()
-
-object TestResourceKotlinRootType : KotlinResourceRootType() {
- override fun isForTests() = true
-}
-
-val ALL_KOTLIN_RESOURCE_ROOT_TYPES = setOf(ResourceKotlinRootType, TestResourceKotlinRootType) \ No newline at end of file
diff --git a/plugins/kotlin/jps/jps-common/src/org/jetbrains/kotlin/config/KotlinSourceRootType.kt b/plugins/kotlin/jps/jps-common/src/org/jetbrains/kotlin/config/KotlinSourceRootType.kt
deleted file mode 100644
index 495f0a58c3c4..000000000000
--- a/plugins/kotlin/jps/jps-common/src/org/jetbrains/kotlin/config/KotlinSourceRootType.kt
+++ /dev/null
@@ -1,23 +0,0 @@
-// Copyright 2000-2021 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
-
-package org.jetbrains.kotlin.config
-
-import org.jetbrains.jps.model.ex.JpsElementTypeBase
-import org.jetbrains.jps.model.java.JavaSourceRootProperties
-import org.jetbrains.jps.model.java.JavaSourceRootType
-import org.jetbrains.jps.model.java.JpsJavaExtensionService
-import org.jetbrains.jps.model.module.JpsModuleSourceRootType
-
-sealed class KotlinSourceRootType() : JpsElementTypeBase<JavaSourceRootProperties>(), JpsModuleSourceRootType<JavaSourceRootProperties> {
-
- override fun createDefaultProperties() = JpsJavaExtensionService.getInstance().createSourceRootProperties("")
-
-}
-
-object SourceKotlinRootType : KotlinSourceRootType()
-
-object TestSourceKotlinRootType : KotlinSourceRootType() {
- override fun isForTests() = true
-}
-
-val ALL_KOTLIN_SOURCE_ROOT_TYPES = setOf(SourceKotlinRootType, TestSourceKotlinRootType)
diff --git a/plugins/kotlin/jps/jps-common/src/org/jetbrains/kotlin/config/SettingConstants.kt b/plugins/kotlin/jps/jps-common/src/org/jetbrains/kotlin/config/SettingConstants.kt
deleted file mode 100644
index a1c37559a4a6..000000000000
--- a/plugins/kotlin/jps/jps-common/src/org/jetbrains/kotlin/config/SettingConstants.kt
+++ /dev/null
@@ -1,13 +0,0 @@
-// Copyright 2000-2021 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
-
-package org.jetbrains.kotlin.config
-
-object SettingConstants {
- const val KOTLIN_COMMON_COMPILER_ARGUMENTS_SECTION = "KotlinCommonCompilerArguments"
- const val KOTLIN_TO_JS_COMPILER_ARGUMENTS_SECTION = "Kotlin2JsCompilerArguments"
- const val KOTLIN_TO_JVM_COMPILER_ARGUMENTS_SECTION = "Kotlin2JvmCompilerArguments"
- const val KOTLIN_COMPILER_SETTINGS_SECTION = "KotlinCompilerSettings"
- const val KOTLIN_COMPILER_SETTINGS_FILE = "kotlinc.xml"
- const val KOTLIN_COMPILER_REFERENCE_INDEX_BUILDER_ID = "kotlin.compiler.ref.index"
- const val KOTLIN_DATA_CONTAINER_ID = "kotlin-data-container"
-}
diff --git a/plugins/kotlin/jps/jps-common/src/org/jetbrains/kotlin/config/facetSerialization.kt b/plugins/kotlin/jps/jps-common/src/org/jetbrains/kotlin/config/facetSerialization.kt
deleted file mode 100644
index 724857f94c43..000000000000
--- a/plugins/kotlin/jps/jps-common/src/org/jetbrains/kotlin/config/facetSerialization.kt
+++ /dev/null
@@ -1,465 +0,0 @@
-// Copyright 2000-2021 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
-
-package org.jetbrains.kotlin.config
-
-import com.intellij.util.PathUtil
-import com.intellij.util.xmlb.SerializationFilter
-import com.intellij.util.xmlb.SkipDefaultsSerializationFilter
-import com.intellij.util.xmlb.XmlSerializer
-import org.jdom.DataConversionException
-import org.jdom.Element
-import org.jdom.Text
-import org.jetbrains.kotlin.arguments.COMPILER_ARGUMENTS_ELEMENT_NAME
-import org.jetbrains.kotlin.arguments.CompilerArgumentsDeserializerV5
-import org.jetbrains.kotlin.arguments.CompilerArgumentsSerializerV5
-import org.jetbrains.kotlin.cli.common.arguments.*
-import org.jetbrains.kotlin.load.java.JvmAbi
-import org.jetbrains.kotlin.platform.*
-import org.jetbrains.kotlin.platform.impl.FakeK2NativeCompilerArguments
-import org.jetbrains.kotlin.platform.impl.JvmIdePlatformKind
-import org.jetbrains.kotlin.platform.js.isJs
-import org.jetbrains.kotlin.platform.jvm.JdkPlatform
-import org.jetbrains.kotlin.platform.jvm.isJvm
-import org.jetbrains.kotlin.platform.konan.*
-import java.lang.reflect.Modifier
-import kotlin.reflect.KClass
-import kotlin.reflect.full.superclasses
-
-fun Element.getOption(name: String) = getChildren("option").firstOrNull { name == it?.getAttribute("name")?.value }
-
-private fun Element.getOptionValue(name: String) = getOption(name)?.getAttribute("value")?.value
-
-private fun Element.getOptionBody(name: String) = getOption(name)?.children?.firstOrNull()
-
-fun TargetPlatform.createArguments(init: (CommonCompilerArguments).() -> Unit = {}): CommonCompilerArguments {
- return when {
- isCommon() -> K2MetadataCompilerArguments().apply { init() }
- isJvm() -> K2JVMCompilerArguments().apply {
- init()
- // TODO(dsavvinov): review this
- jvmTarget = (single() as? JdkPlatform)?.targetVersion?.description ?: JvmTarget.DEFAULT.description
- }
- isJs() -> K2JSCompilerArguments().apply { init() }
- isNative() -> FakeK2NativeCompilerArguments().apply { init() }
- else -> error("Unknown platform $this")
- }
-}
-
-private fun readV1Config(element: Element): KotlinFacetSettings {
- return KotlinFacetSettings().apply {
- val useProjectSettings = element.getOptionValue("useProjectSettings")?.toBoolean()
-
- val versionInfoElement = element.getOptionBody("versionInfo")
- val targetPlatformName = versionInfoElement?.getOptionValue("targetPlatformName")
- val languageLevel = versionInfoElement?.getOptionValue("languageLevel")
- val apiLevel = versionInfoElement?.getOptionValue("apiLevel")
- val targetPlatform = CommonPlatforms.allSimplePlatforms.union(setOf(CommonPlatforms.defaultCommonPlatform))
- .firstOrNull { it.oldFashionedDescription == targetPlatformName }
- ?: JvmIdePlatformKind.defaultPlatform // FIXME(dsavvinov): choose proper default
-
- val compilerInfoElement = element.getOptionBody("compilerInfo")
-
- val compilerSettings = CompilerSettings().apply {
- compilerInfoElement?.getOptionBody("compilerSettings")?.let { compilerSettingsElement ->
- XmlSerializer.deserializeInto(this, compilerSettingsElement)
- }
- }
-
- val commonArgumentsElement = compilerInfoElement?.getOptionBody("_commonCompilerArguments")
- val jvmArgumentsElement = compilerInfoElement?.getOptionBody("k2jvmCompilerArguments")
- val jsArgumentsElement = compilerInfoElement?.getOptionBody("k2jsCompilerArguments")
-
- val compilerArguments = targetPlatform.createArguments { freeArgs = arrayListOf() }
-
- commonArgumentsElement?.let { XmlSerializer.deserializeInto(compilerArguments, it) }
- when (compilerArguments) {
- is K2JVMCompilerArguments -> jvmArgumentsElement?.let { XmlSerializer.deserializeInto(compilerArguments, it) }
- is K2JSCompilerArguments -> jsArgumentsElement?.let { XmlSerializer.deserializeInto(compilerArguments, it) }
- }
-
- if (languageLevel != null) {
- compilerArguments.languageVersion = languageLevel
- }
-
- if (apiLevel != null) {
- compilerArguments.apiVersion = apiLevel
- }
-
- compilerArguments.detectVersionAutoAdvance()
-
- if (useProjectSettings != null) {
- this.useProjectSettings = useProjectSettings
- } else {
- // Migration problem workaround for pre-1.1-beta releases (mainly 1.0.6) -> 1.1-rc+
- // Problematic cases: 1.1-beta/1.1-beta2 -> 1.1-rc+ (useProjectSettings gets reset to false)
- // This heuristic detects old enough configurations:
- if (jvmArgumentsElement == null) {
- this.useProjectSettings = false
- }
- }
-
- this.compilerSettings = compilerSettings
- this.compilerArguments = compilerArguments
- this.targetPlatform = IdePlatformKind.platformByCompilerArguments(compilerArguments)
- }
-}
-
-// TODO: Introduce new version of facet serialization. See https://youtrack.jetbrains.com/issue/KT-38235
-// This is necessary to avoid having too much custom logic for platform serialization.
-fun Element.getFacetPlatformByConfigurationElement(): TargetPlatform {
- getAttributeValue("allPlatforms").deserializeTargetPlatformByComponentPlatforms()?.let { return it }
-
- // failed to read list of all platforms. Fallback to legacy algorithm
- val platformName = getAttributeValue("platform") ?: return (null as TargetPlatform?).orDefault()
- return CommonPlatforms.allSimplePlatforms.firstOrNull {
- // first, look for exact match through all simple platforms
- it.oldFashionedDescription == platformName
- } ?: CommonPlatforms.defaultCommonPlatform.takeIf {
- // then, check exact match for the default common platform
- it.oldFashionedDescription == platformName
- } ?: NativePlatforms.unspecifiedNativePlatform.takeIf {
- // if none of the above succeeded, check if it's an old-style record about native platform (without suffix with target name)
- it.oldFashionedDescription.startsWith(platformName)
- }.orDefault() // finally, fallback to the default platform
-}
-
-private fun readV2AndLaterConfig(
- element: Element,
- argumentReader: (Element, CommonToolArguments) -> Unit = { el, arg -> XmlSerializer.deserializeInto(arg, el) }
-): KotlinFacetSettings {
- return KotlinFacetSettings().apply {
- element.getAttributeValue("useProjectSettings")?.let { useProjectSettings = it.toBoolean() }
- val targetPlatform = element.getFacetPlatformByConfigurationElement()
- this.targetPlatform = targetPlatform
- readElementsList(element, "implements", "implement")?.let { implementedModuleNames = it }
- readElementsList(element, "dependsOnModuleNames", "dependsOn")?.let { dependsOnModuleNames = it }
- element.getChild("externalSystemTestTasks")?.let {
- val testRunTasks = it.getChildren("externalSystemTestTask")
- .mapNotNull { (it.content.firstOrNull() as? Text)?.textTrim }
- .mapNotNull { ExternalSystemTestRunTask.fromStringRepresentation(it) }
- val nativeMainRunTasks = it.getChildren("externalSystemNativeMainRunTask")
- .mapNotNull { (it.content.firstOrNull() as? Text)?.textTrim }
- .mapNotNull { ExternalSystemNativeMainRunTask.fromStringRepresentation(it) }
-
- externalSystemRunTasks = testRunTasks + nativeMainRunTasks
- }
-
- element.getChild("sourceSets")?.let {
- val items = it.getChildren("sourceSet")
- sourceSetNames = items.mapNotNull { (it.content.firstOrNull() as? Text)?.textTrim }
- }
- kind = element.getChild("newMppModelJpsModuleKind")?.let {
- val kindName = (it.content.firstOrNull() as? Text)?.textTrim
- if (kindName != null) {
- try {
- KotlinModuleKind.valueOf(kindName)
- } catch (e: Exception) {
- null
- }
- } else null
- } ?: KotlinModuleKind.DEFAULT
- isTestModule = element.getAttributeValue("isTestModule")?.toBoolean() ?: false
- externalProjectId = element.getAttributeValue("externalProjectId") ?: ""
- isHmppEnabled = element.getAttribute("isHmppProject")?.booleanValue ?: false
- pureKotlinSourceFolders = element.getAttributeValue("pureKotlinSourceFolders")?.split(";")?.toList() ?: emptyList()
- element.getChild("compilerSettings")?.let {
- compilerSettings = CompilerSettings()
- XmlSerializer.deserializeInto(compilerSettings!!, it)
- }
- element.getChild(COMPILER_ARGUMENTS_ELEMENT_NAME)?.let {
- compilerArguments = targetPlatform.createArguments {
- freeArgs = mutableListOf()
- internalArguments = mutableListOf()
- }
- argumentReader(it, compilerArguments!!)
- compilerArguments!!.detectVersionAutoAdvance()
- }
- productionOutputPath = element.getChild("productionOutputPath")?.let {
- PathUtil.toSystemDependentName((it.content.firstOrNull() as? Text)?.textTrim)
- } ?: (compilerArguments as? K2JSCompilerArguments)?.outputFile
- testOutputPath = element.getChild("testOutputPath")?.let {
- PathUtil.toSystemDependentName((it.content.firstOrNull() as? Text)?.textTrim)
- } ?: (compilerArguments as? K2JSCompilerArguments)?.outputFile
- }
-}
-
-private fun readElementsList(element: Element, rootElementName: String, elementName: String): List<String>? {
- element.getChild(rootElementName)?.let {
- val items = it.getChildren(elementName)
- return if (items.isNotEmpty()) {
- items.mapNotNull { (it.content.firstOrNull() as? Text)?.textTrim }
- } else {
- listOfNotNull((it.content.firstOrNull() as? Text)?.textTrim)
- }
- }
- return null
-}
-
-private fun readV2Config(element: Element): KotlinFacetSettings {
- return readV2AndLaterConfig(element)
-}
-
-private fun readLatestConfig(element: Element): KotlinFacetSettings {
- return readV2AndLaterConfig(element) { el, bean -> CompilerArgumentsDeserializerV5(bean).deserializeFrom(el) }
-}
-
-fun deserializeFacetSettings(element: Element): KotlinFacetSettings {
- val version = try {
- element.getAttribute("version")?.intValue
- } catch (e: DataConversionException) {
- null
- } ?: KotlinFacetSettings.DEFAULT_VERSION
- return when (version) {
- 1 -> readV1Config(element)
- 2, 3, 4 -> readV2Config(element)
- KotlinFacetSettings.CURRENT_VERSION -> readLatestConfig(element)
- else -> return KotlinFacetSettings() // Reset facet configuration if versions don't match
- }.apply { this.version = version }
-}
-
-fun CommonCompilerArguments.convertPathsToSystemIndependent() {
- pluginClasspaths?.forEachIndexed { index, s -> pluginClasspaths!![index] = PathUtil.toSystemIndependentName(s) }
-
- when (this) {
- is K2JVMCompilerArguments -> {
- destination = PathUtil.toSystemIndependentName(destination)
- classpath = PathUtil.toSystemIndependentName(classpath)
- jdkHome = PathUtil.toSystemIndependentName(jdkHome)
- kotlinHome = PathUtil.toSystemIndependentName(kotlinHome)
- friendPaths?.forEachIndexed { index, s -> friendPaths!![index] = PathUtil.toSystemIndependentName(s) }
- declarationsOutputPath = PathUtil.toSystemIndependentName(declarationsOutputPath)
- }
-
- is K2JSCompilerArguments -> {
- outputFile = PathUtil.toSystemIndependentName(outputFile)
- libraries = PathUtil.toSystemIndependentName(libraries)
- }
-
- is K2MetadataCompilerArguments -> {
- destination = PathUtil.toSystemIndependentName(destination)
- classpath = PathUtil.toSystemIndependentName(classpath)
- }
- }
-}
-
-fun CompilerSettings.convertPathsToSystemIndependent() {
- scriptTemplatesClasspath = PathUtil.toSystemIndependentName(scriptTemplatesClasspath)
- outputDirectoryForJsLibraryFiles = PathUtil.toSystemIndependentName(outputDirectoryForJsLibraryFiles)
-}
-
-private fun KClass<*>.superClass() = superclasses.firstOrNull { !it.java.isInterface }
-
-private fun Class<*>.computeNormalPropertyOrdering(): Map<String, Int> {
- val result = LinkedHashMap<String, Int>()
- var count = 0
- generateSequence(this) { it.superclass }.forEach { clazz ->
- for (field in clazz.declaredFields) {
- if (field.modifiers and Modifier.STATIC != 0) continue
-
- var propertyName = field.name
- if (propertyName.endsWith(JvmAbi.DELEGATED_PROPERTY_NAME_SUFFIX)) {
- propertyName = propertyName.dropLast(JvmAbi.DELEGATED_PROPERTY_NAME_SUFFIX.length)
- }
-
- result[propertyName] = count++
- }
- }
- return result
-}
-
-private val allNormalOrderings = HashMap<Class<*>, Map<String, Int>>()
-
-private val Class<*>.normalOrdering
- get() = synchronized(allNormalOrderings) { allNormalOrderings.getOrPut(this) { computeNormalPropertyOrdering() } }
-
-// Replacing fields with delegated properties leads to unexpected reordering of entries in facet configuration XML
-// It happens due to XmlSerializer using different orderings for field- and method-based accessors
-// This code restores the original ordering
-internal fun Element.restoreNormalOrdering(bean: Any) {
- val normalOrdering = bean.javaClass.normalOrdering
- val elementsToReorder = this.getContent<Element> { it is Element && it.getAttribute("name")?.value in normalOrdering }
- elementsToReorder.sortedBy { normalOrdering[it.getAttribute("name")?.value!!] }
- .forEachIndexed { index, element -> elementsToReorder[index] = element.clone() }
-}
-
-private fun buildChildElement(element: Element, tag: String, bean: Any, filter: SerializationFilter): Element {
- return Element(tag).apply {
- XmlSerializer.serializeInto(bean, this, filter)
- restoreNormalOrdering(bean)
- element.addContent(this)
- }
-}
-
-private fun KotlinFacetSettings.writeConfig(element: Element) {
- val filter = SkipDefaultsSerializationFilter()
-
- // TODO: Introduce new version of facet serialization. See https://youtrack.jetbrains.com/issue/KT-38235
- // This is necessary to avoid having too much custom logic for platform serialization.
- targetPlatform?.let { targetPlatform ->
- element.setAttribute("platform", targetPlatform.oldFashionedDescription)
- element.setAttribute("allPlatforms", targetPlatform.serializeComponentPlatforms())
- }
- if (!useProjectSettings) {
- element.setAttribute("useProjectSettings", useProjectSettings.toString())
- }
- saveElementsList(element, implementedModuleNames, "implements", "implement")
- saveElementsList(element, dependsOnModuleNames, "dependsOnModuleNames", "dependsOn")
-
- if (sourceSetNames.isNotEmpty()) {
- element.addContent(
- Element("sourceSets").apply {
- sourceSetNames.map { addContent(Element("sourceSet").apply { addContent(it) }) }
- }
- )
- }
- if (kind != KotlinModuleKind.DEFAULT) {
- element.addContent(Element("newMppModelJpsModuleKind").apply { addContent(kind.name) })
- element.setAttribute("isTestModule", isTestModule.toString())
- }
- if (externalProjectId.isNotEmpty()) {
- element.setAttribute("externalProjectId", externalProjectId)
- }
- if (mppVersion.isHmpp) {
- element.setAttribute("isHmppProject", mppVersion.isHmpp.toString())
- }
- if (externalSystemRunTasks.isNotEmpty()) {
- element.addContent(
- Element("externalSystemTestTasks").apply {
- externalSystemRunTasks.forEach { task ->
- when (task) {
- is ExternalSystemTestRunTask -> {
- addContent(
- Element("externalSystemTestTask").apply { addContent(task.toStringRepresentation()) }
- )
- }
- is ExternalSystemNativeMainRunTask -> {
- addContent(
- Element("externalSystemNativeMainRunTask").apply { addContent(task.toStringRepresentation()) }
- )
- }
- }
- }
- }
- )
- }
- if (pureKotlinSourceFolders.isNotEmpty()) {
- element.setAttribute("pureKotlinSourceFolders", pureKotlinSourceFolders.joinToString(";"))
- }
- productionOutputPath?.let {
- if (it != (compilerArguments as? K2JSCompilerArguments)?.outputFile) {
- element.addContent(Element("productionOutputPath").apply { addContent(PathUtil.toSystemIndependentName(it)) })
- }
- }
- testOutputPath?.let {
- if (it != (compilerArguments as? K2JSCompilerArguments)?.outputFile) {
- element.addContent(Element("testOutputPath").apply { addContent(PathUtil.toSystemIndependentName(it)) })
- }
- }
- compilerSettings?.let { copyBean(it) }?.let {
- it.convertPathsToSystemIndependent()
- buildChildElement(element, "compilerSettings", it, filter)
- }
-}
-
-private fun KotlinFacetSettings.writeV2toV4Config(element: Element) = writeConfig(element).apply {
- compilerArguments?.let { copyBean(it) }?.let {
- it.convertPathsToSystemIndependent()
- val compilerArgumentsXml = buildChildElement(element, "compilerArguments", it, SkipDefaultsSerializationFilter())
- compilerArgumentsXml.dropVersionsIfNecessary(it)
- }
-}
-
-private fun KotlinFacetSettings.writeLatestConfig(element: Element) = writeConfig(element).apply {
- compilerArguments?.let { copyBean(it) }?.let {
- it.convertPathsToSystemIndependent()
- val compilerArgumentsXml = CompilerArgumentsSerializerV5(it).serializeTo(element)
- compilerArgumentsXml.dropVersionsIfNecessary(it)
- }
-}
-
-private fun saveElementsList(element: Element, elementsList: List<String>, rootElementName: String, elementName: String) {
- if (elementsList.isNotEmpty()) {
- element.addContent(
- Element(rootElementName).apply {
- val singleModule = elementsList.singleOrNull()
- if (singleModule != null) {
- addContent(singleModule)
- } else {
- elementsList.map { addContent(Element(elementName).apply { addContent(it) }) }
- }
- }
- )
- }
-}
-
-fun CommonCompilerArguments.detectVersionAutoAdvance() {
- autoAdvanceLanguageVersion = languageVersion == null
- autoAdvanceApiVersion = apiVersion == null
-}
-
-fun Element.dropVersionsIfNecessary(settings: CommonCompilerArguments) {
- // Do not serialize language/api version if they correspond to the default language version
- if (settings.autoAdvanceLanguageVersion) {
- getOption("languageVersion")?.detach()
- }
-
- if (settings.autoAdvanceApiVersion) {
- getOption("apiVersion")?.detach()
- }
-}
-
-fun KotlinFacetSettings.serializeFacetSettings(element: Element) = when (version) {
- 2, 3, 4 -> {
- element.setAttribute("version", version.toString())
- writeV2toV4Config(element)
- }
- else -> {
- element.setAttribute("version", KotlinFacetSettings.CURRENT_VERSION.toString())
- writeLatestConfig(element)
- }
-}
-
-
-private fun TargetPlatform.serializeComponentPlatforms(): String {
- val componentPlatforms = componentPlatforms
- val componentPlatformNames = componentPlatforms.mapTo(ArrayList()) { it.serializeToString() }
-
- // workaround for old Kotlin IDE plugins, KT-38634
- if (componentPlatforms.any { it is NativePlatform })
- componentPlatformNames.add(NativePlatformUnspecifiedTarget.legacySerializeToString())
-
- return componentPlatformNames.sorted().joinToString("/")
-}
-
-private fun String?.deserializeTargetPlatformByComponentPlatforms(): TargetPlatform? {
- val componentPlatformNames = this?.split('/')?.toSet()?.takeIf { it.isNotEmpty() } ?: return null
-
- val knownComponentPlatforms = HashMap<String, SimplePlatform>() // "serialization presentation" to "simple platform name"
-
- // first, collect serialization presentations for every known simple platform
- CommonPlatforms.allSimplePlatforms
- .flatMap { it.componentPlatforms }
- .forEach { knownComponentPlatforms[it.serializeToString()] = it }
-
- // next, add legacy aliases for some of the simple platforms; ex: unspecifiedNativePlatform
- NativePlatformUnspecifiedTarget.let { knownComponentPlatforms[it.legacySerializeToString()] = it }
-
- val componentPlatforms = componentPlatformNames.mapNotNull(knownComponentPlatforms::get).toSet()
- return when (componentPlatforms.size) {
- 0 -> {
- // empty set of component platforms is not allowed, in such case fallback to legacy algorithm
- null
- }
- 1 -> TargetPlatform(componentPlatforms)
- else -> {
- // workaround for old Kotlin IDE plugins, KT-38634
- if (componentPlatforms.any { it is NativePlatformUnspecifiedTarget }
- && componentPlatforms.any { it is NativePlatformWithTarget }
- ) {
- TargetPlatform(componentPlatforms - NativePlatformUnspecifiedTarget)
- } else {
- TargetPlatform(componentPlatforms)
- }
- }
- }
-}
diff --git a/plugins/kotlin/jps/jps-common/src/org/jetbrains/kotlin/config/moduleSourceRootPropertiesSerializers.kt b/plugins/kotlin/jps/jps-common/src/org/jetbrains/kotlin/config/moduleSourceRootPropertiesSerializers.kt
deleted file mode 100644
index a80b81e35d2c..000000000000
--- a/plugins/kotlin/jps/jps-common/src/org/jetbrains/kotlin/config/moduleSourceRootPropertiesSerializers.kt
+++ /dev/null
@@ -1,83 +0,0 @@
-// Copyright 2000-2021 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
-
-package org.jetbrains.kotlin.config
-
-import org.jdom.Element
-import org.jetbrains.jps.model.java.JavaResourceRootProperties
-import org.jetbrains.jps.model.java.JavaSourceRootProperties
-import org.jetbrains.jps.model.java.JpsJavaExtensionService
-import org.jetbrains.jps.model.module.JpsModuleSourceRootType
-import org.jetbrains.jps.model.serialization.module.JpsModuleRootModelSerializer
-import org.jetbrains.jps.model.serialization.module.JpsModuleSourceRootPropertiesSerializer
-
-private const val IS_GENERATED_ATTRIBUTE = "generated"
-private const val RELATIVE_OUTPUT_PATH_ATTRIBUTE = "relativeOutputPath"
-
-const val KOTLIN_SOURCE_ROOT_TYPE_ID = "kotlin-source"
-const val KOTLIN_TEST_ROOT_TYPE_ID = "kotlin-test"
-const val KOTLIN_RESOURCE_ROOT_TYPE_ID = "kotlin-resource"
-const val KOTLIN_TEST_RESOURCE_ROOT_TYPE_ID = "kotlin-test-resource"
-
-// Based on org.jetbrains.jps.model.serialization.java.JpsJavaModelSerializerExtension.JavaSourceRootPropertiesSerializer class
-sealed class KotlinSourceRootPropertiesSerializer(
- type: JpsModuleSourceRootType<JavaSourceRootProperties>,
- typeId: String
-) : JpsModuleSourceRootPropertiesSerializer<JavaSourceRootProperties>(type, typeId) {
- object Source : KotlinSourceRootPropertiesSerializer(
- SourceKotlinRootType,
- KOTLIN_SOURCE_ROOT_TYPE_ID
- )
-
- object TestSource : KotlinSourceRootPropertiesSerializer(
- TestSourceKotlinRootType,
- KOTLIN_TEST_ROOT_TYPE_ID
- )
-
- override fun loadProperties(sourceRootTag: Element): JavaSourceRootProperties {
- val packagePrefix = sourceRootTag.getAttributeValue(JpsModuleRootModelSerializer.PACKAGE_PREFIX_ATTRIBUTE) ?: ""
- val isGenerated = sourceRootTag.getAttributeValue(IS_GENERATED_ATTRIBUTE)?.toBoolean() ?: false
- return JpsJavaExtensionService.getInstance().createSourceRootProperties(packagePrefix, isGenerated)
- }
-
- override fun saveProperties(properties: JavaSourceRootProperties, sourceRootTag: Element) {
- val packagePrefix = properties.packagePrefix
- if (packagePrefix.isNotEmpty()) {
- sourceRootTag.setAttribute(JpsModuleRootModelSerializer.PACKAGE_PREFIX_ATTRIBUTE, packagePrefix)
- }
- if (properties.isForGeneratedSources) {
- sourceRootTag.setAttribute(IS_GENERATED_ATTRIBUTE, "true")
- }
- }
-}
-
-// Based on org.jetbrains.jps.model.serialization.java.JpsJavaModelSerializerExtension.JavaResourceRootPropertiesSerializer
-sealed class KotlinResourceRootPropertiesSerializer(
- type: JpsModuleSourceRootType<JavaResourceRootProperties>,
- typeId: String
-) : JpsModuleSourceRootPropertiesSerializer<JavaResourceRootProperties>(type, typeId) {
- object Resource : KotlinResourceRootPropertiesSerializer(
- ResourceKotlinRootType,
- KOTLIN_RESOURCE_ROOT_TYPE_ID
- )
-
- object TestResource : KotlinResourceRootPropertiesSerializer(
- TestResourceKotlinRootType,
- KOTLIN_TEST_RESOURCE_ROOT_TYPE_ID
- )
-
- override fun loadProperties(sourceRootTag: Element): JavaResourceRootProperties {
- val relativeOutputPath = sourceRootTag.getAttributeValue(RELATIVE_OUTPUT_PATH_ATTRIBUTE) ?: ""
- val isGenerated = sourceRootTag.getAttributeValue(IS_GENERATED_ATTRIBUTE)?.toBoolean() ?: false
- return JpsJavaExtensionService.getInstance().createResourceRootProperties(relativeOutputPath, isGenerated)
- }
-
- override fun saveProperties(properties: JavaResourceRootProperties, sourceRootTag: Element) {
- val relativeOutputPath = properties.relativeOutputPath
- if (relativeOutputPath.isNotEmpty()) {
- sourceRootTag.setAttribute(RELATIVE_OUTPUT_PATH_ATTRIBUTE, relativeOutputPath)
- }
- if (properties.isForGeneratedSources) {
- sourceRootTag.setAttribute(IS_GENERATED_ATTRIBUTE, "true")
- }
- }
-} \ No newline at end of file
diff --git a/plugins/kotlin/jps/jps-common/src/org/jetbrains/kotlin/platform/DefaultIdeTargetPlatformKindProvider.kt b/plugins/kotlin/jps/jps-common/src/org/jetbrains/kotlin/platform/DefaultIdeTargetPlatformKindProvider.kt
deleted file mode 100644
index 24e6100c7470..000000000000
--- a/plugins/kotlin/jps/jps-common/src/org/jetbrains/kotlin/platform/DefaultIdeTargetPlatformKindProvider.kt
+++ /dev/null
@@ -1,31 +0,0 @@
-// Copyright 2000-2021 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
-
-package org.jetbrains.kotlin.platform
-
-import com.intellij.openapi.application.ApplicationManager
-import org.jetbrains.kotlin.config.isJps
-import org.jetbrains.kotlin.platform.jvm.JvmPlatforms
-
-interface DefaultIdeTargetPlatformKindProvider {
- val defaultPlatform: TargetPlatform
-
- companion object {
- val defaultPlatform: TargetPlatform
- get() {
- if (isJps) {
- // TODO support passing custom platforms in JPS
- return JvmPlatforms.defaultJvmPlatform
- }
-
- return ApplicationManager.getApplication().getService(DefaultIdeTargetPlatformKindProvider::class.java).defaultPlatform
- }
- }
-}
-
-fun TargetPlatform?.orDefault(): TargetPlatform {
- return this ?: DefaultIdeTargetPlatformKindProvider.defaultPlatform
-}
-
-fun IdePlatformKind<*>?.orDefault(): IdePlatformKind<*> {
- return this ?: DefaultIdeTargetPlatformKindProvider.defaultPlatform.idePlatformKind
-} \ No newline at end of file
diff --git a/plugins/kotlin/jps/jps-common/src/org/jetbrains/kotlin/platform/IdePlatform.kt b/plugins/kotlin/jps/jps-common/src/org/jetbrains/kotlin/platform/IdePlatform.kt
deleted file mode 100644
index 3199f777bb87..000000000000
--- a/plugins/kotlin/jps/jps-common/src/org/jetbrains/kotlin/platform/IdePlatform.kt
+++ /dev/null
@@ -1,24 +0,0 @@
-// Copyright 2000-2021 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
-
-package org.jetbrains.kotlin.platform
-
-import org.jetbrains.kotlin.cli.common.arguments.CommonCompilerArguments
-import org.jetbrains.kotlin.utils.DescriptionAware
-
-@Suppress("DEPRECATION_ERROR")
-@Deprecated(
- message = "This interface is deprecated and will be removed soon, use API from 'org.jetbrains.kotlin.platform.*' packages instead",
- replaceWith = ReplaceWith("TargetPlatform", "org.jetbrains.kotlin.platform.TargetPlatform"),
- level = DeprecationLevel.ERROR
-)
-abstract class IdePlatform<Kind : IdePlatformKind<Kind>, out Arguments : CommonCompilerArguments> : DescriptionAware {
- abstract val kind: Kind
- abstract val version: TargetPlatformVersion
-
- abstract fun createArguments(init: Arguments.() -> Unit = {}): Arguments
-
- override val description
- get() = kind.name + " " + version.description
-
- override fun toString() = description
-}
diff --git a/plugins/kotlin/jps/jps-common/src/org/jetbrains/kotlin/platform/IdePlatformKind.kt b/plugins/kotlin/jps/jps-common/src/org/jetbrains/kotlin/platform/IdePlatformKind.kt
deleted file mode 100644
index 1dd370e2dbf8..000000000000
--- a/plugins/kotlin/jps/jps-common/src/org/jetbrains/kotlin/platform/IdePlatformKind.kt
+++ /dev/null
@@ -1,88 +0,0 @@
-// Copyright 2000-2021 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
-
-@file:JvmName("IdePlatformKindUtil")
-
-package org.jetbrains.kotlin.platform
-
-import com.intellij.openapi.diagnostic.Logger
-import org.jetbrains.kotlin.cli.common.arguments.CommonCompilerArguments
-import org.jetbrains.kotlin.config.isJps
-import org.jetbrains.kotlin.extensions.ApplicationExtensionDescriptor
-import org.jetbrains.kotlin.platform.impl.CommonIdePlatformKind
-import org.jetbrains.kotlin.platform.impl.JsIdePlatformKind
-import org.jetbrains.kotlin.platform.impl.JvmIdePlatformKind
-import org.jetbrains.kotlin.platform.impl.NativeIdePlatformKind
-
-abstract class IdePlatformKind<Kind : IdePlatformKind<Kind>> {
- abstract fun supportsTargetPlatform(platform: TargetPlatform): Boolean
-
- abstract val defaultPlatform: TargetPlatform
-
- @Suppress("DEPRECATION_ERROR", "DeprecatedCallableAddReplaceWith")
- @Deprecated(
- message = "IdePlatform is deprecated and will be removed soon, please, migrate to org.jetbrains.kotlin.platform.TargetPlatform",
- level = DeprecationLevel.ERROR
- )
- abstract fun getDefaultPlatform(): IdePlatform<*, *>
-
- abstract fun platformByCompilerArguments(arguments: CommonCompilerArguments): TargetPlatform?
-
- abstract val argumentsClass: Class<out CommonCompilerArguments>
-
- abstract val name: String
-
- abstract fun createArguments(): CommonCompilerArguments
-
- override fun equals(other: Any?): Boolean = javaClass == other?.javaClass
- override fun hashCode(): Int = javaClass.hashCode()
-
- override fun toString() = name
-
- companion object {
- // We can't use the ApplicationExtensionDescriptor class directly because it's missing in the JPS process
- private val extension = run {
- if (isJps) return@run null
- ApplicationExtensionDescriptor("org.jetbrains.kotlin.idePlatformKind", IdePlatformKind::class.java)
- }
-
- // For using only in JPS
- private val JPS_KINDS
- get() = listOf(
- JvmIdePlatformKind,
- JsIdePlatformKind,
- CommonIdePlatformKind,
- NativeIdePlatformKind
- )
-
- val ALL_KINDS by lazy {
- val kinds = extension?.getInstances() ?: return@lazy JPS_KINDS
- require(kinds.isNotEmpty()) { "Platform kind list is empty" }
- kinds
- }
-
-
- fun <Args : CommonCompilerArguments> platformByCompilerArguments(arguments: Args): TargetPlatform? =
- ALL_KINDS.firstNotNullResult { it.platformByCompilerArguments(arguments) }
-
- }
-}
-
-val TargetPlatform.idePlatformKind: IdePlatformKind<*>
- get() = IdePlatformKind.ALL_KINDS.filter { it.supportsTargetPlatform(this) }.let { list ->
- when {
- list.size == 1 -> list.first()
- list.size > 1 -> list.first().also {
- Logger.getInstance(IdePlatformKind.javaClass).warn("Found more than one IdePlatformKind [$list] for target [$this].")
- }
- else -> error("Unknown platform $this")
- }
- }
-
-// TODO: replace with firstNotNullOfOrNull
-private inline fun <T, R : Any> Iterable<T>.firstNotNullResult(transform: (T) -> R?): R? {
- for (element in this) {
- val result = transform(element)
- if (result != null) return result
- }
- return null
-}
diff --git a/plugins/kotlin/jps/jps-common/src/org/jetbrains/kotlin/platform/compat/compatConversions.kt b/plugins/kotlin/jps/jps-common/src/org/jetbrains/kotlin/platform/compat/compatConversions.kt
deleted file mode 100644
index 9941338ae0c0..000000000000
--- a/plugins/kotlin/jps/jps-common/src/org/jetbrains/kotlin/platform/compat/compatConversions.kt
+++ /dev/null
@@ -1,62 +0,0 @@
-// Copyright 2000-2021 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
-
-@file:Suppress("DEPRECATION_ERROR", "TYPEALIAS_EXPANSION_DEPRECATION_ERROR")
-
-package org.jetbrains.kotlin.platform.compat
-
-import org.jetbrains.kotlin.config.JvmTarget
-import org.jetbrains.kotlin.platform.CommonPlatforms
-import org.jetbrains.kotlin.platform.IdePlatform
-import org.jetbrains.kotlin.platform.impl.CommonIdePlatformKind
-import org.jetbrains.kotlin.platform.impl.JsIdePlatformKind
-import org.jetbrains.kotlin.platform.impl.JvmIdePlatformKind
-import org.jetbrains.kotlin.platform.impl.NativeIdePlatformKind
-import org.jetbrains.kotlin.platform.js.JsPlatform
-import org.jetbrains.kotlin.platform.js.JsPlatforms
-import org.jetbrains.kotlin.platform.jvm.JdkPlatform
-import org.jetbrains.kotlin.platform.jvm.JvmPlatform
-import org.jetbrains.kotlin.platform.jvm.JvmPlatforms
-import org.jetbrains.kotlin.platform.konan.NativePlatforms
-import org.jetbrains.kotlin.platform.konan.NativePlatform
-
-typealias OldPlatform = org.jetbrains.kotlin.resolve.TargetPlatform
-typealias NewPlatform = org.jetbrains.kotlin.platform.TargetPlatform
-
-fun NewPlatform.toOldPlatform(): OldPlatform = when (val single = singleOrNull()) {
- null -> CommonPlatforms.CompatCommonPlatform
- is JvmPlatform -> JvmPlatforms.CompatJvmPlatform
- is JsPlatform -> JsPlatforms.CompatJsPlatform
- is NativePlatform -> NativePlatforms.CompatNativePlatform
- else -> error("Unknown platform $single")
-}
-
-fun OldPlatform.toNewPlatform(): NewPlatform = when (this) {
- is CommonPlatforms.CompatCommonPlatform -> this
- is JvmPlatforms.CompatJvmPlatform -> this
- is JsPlatforms.CompatJsPlatform -> this
- is NativePlatforms.CompatNativePlatform -> this
- else -> error(
- "Can't convert org.jetbrains.kotlin.resolve.TargetPlatform to org.jetbrains.kotlin.platform.TargetPlatform: " +
- "non-Compat instance passed\n" +
- "toString: $this\n" +
- "class: ${this::class}\n" +
- "hashCode: ${this.hashCode().toString(16)}"
- )
-}
-
-fun IdePlatform<*, *>.toNewPlatform(): NewPlatform = when (this) {
- is CommonIdePlatformKind.Platform -> CommonPlatforms.defaultCommonPlatform
- is JvmIdePlatformKind.Platform -> JvmPlatforms.jvmPlatformByTargetVersion(this.version)
- is JsIdePlatformKind.Platform -> JsPlatforms.defaultJsPlatform
- is NativeIdePlatformKind.Platform -> NativePlatforms.unspecifiedNativePlatform
- else -> error("Unknown platform $this")
-}
-
-fun NewPlatform.toIdePlatform(): IdePlatform<*, *> = when (val single = singleOrNull()) {
- null -> CommonIdePlatformKind.Platform
- is JdkPlatform -> JvmIdePlatformKind.Platform(single.targetVersion)
- is JvmPlatform -> JvmIdePlatformKind.Platform(JvmTarget.DEFAULT)
- is JsPlatform -> JsIdePlatformKind.Platform
- is NativePlatform -> NativeIdePlatformKind.Platform
- else -> error("Unknown platform $single")
-}
diff --git a/plugins/kotlin/jps/jps-common/src/org/jetbrains/kotlin/platform/impl/CommonIdePlatformKind.kt b/plugins/kotlin/jps/jps-common/src/org/jetbrains/kotlin/platform/impl/CommonIdePlatformKind.kt
deleted file mode 100644
index e3bc19d369a5..000000000000
--- a/plugins/kotlin/jps/jps-common/src/org/jetbrains/kotlin/platform/impl/CommonIdePlatformKind.kt
+++ /dev/null
@@ -1,57 +0,0 @@
-// Copyright 2000-2021 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
-
-@file:JvmName("CommonIdePlatformUtil")
-@file:Suppress("DEPRECATION_ERROR", "DeprecatedCallableAddReplaceWith")
-
-package org.jetbrains.kotlin.platform.impl
-
-import org.jetbrains.kotlin.cli.common.arguments.CommonCompilerArguments
-import org.jetbrains.kotlin.cli.common.arguments.K2MetadataCompilerArguments
-import org.jetbrains.kotlin.platform.*
-
-object CommonIdePlatformKind : IdePlatformKind<CommonIdePlatformKind>() {
- override fun supportsTargetPlatform(platform: TargetPlatform) = platform.isCommon()
-
- override fun platformByCompilerArguments(arguments: CommonCompilerArguments): TargetPlatform? {
- return if (arguments is K2MetadataCompilerArguments)
- CommonPlatforms.defaultCommonPlatform
- else
- null
- }
-
- @Deprecated(
- message = "IdePlatform is deprecated and will be removed soon, please, migrate to org.jetbrains.kotlin.platform.TargetPlatform",
- level = DeprecationLevel.ERROR
- )
- override fun getDefaultPlatform(): IdePlatform<*, *> = Platform
-
- override fun createArguments(): CommonCompilerArguments {
- return K2MetadataCompilerArguments() // TODO(dsavvinov): review that, as now MPP !== K2Metadata
- }
-
- override val defaultPlatform get() = CommonPlatforms.defaultCommonPlatform
-
- override val argumentsClass get() = K2MetadataCompilerArguments::class.java
-
- override val name get() = "Common (experimental)"
-
- @Deprecated(
- message = "IdePlatform is deprecated and will be removed soon, please, migrate to org.jetbrains.kotlin.platform.TargetPlatform",
- level = DeprecationLevel.ERROR
- )
- object Platform : IdePlatform<CommonIdePlatformKind, CommonCompilerArguments>() {
- override val kind get() = CommonIdePlatformKind
- override val version get() = TargetPlatformVersion.NoVersion
- override fun createArguments(init: CommonCompilerArguments.() -> Unit) = K2MetadataCompilerArguments().apply(init)
- }
-}
-
-val IdePlatformKind<*>?.isCommon
- get() = this is CommonIdePlatformKind
-
-@Deprecated(
- message = "IdePlatform is deprecated and will be removed soon, please, migrate to org.jetbrains.kotlin.platform.TargetPlatform",
- level = DeprecationLevel.ERROR
-)
-val IdePlatform<*, *>.isCommon: Boolean
- get() = this is CommonIdePlatformKind.Platform \ No newline at end of file
diff --git a/plugins/kotlin/jps/jps-common/src/org/jetbrains/kotlin/platform/impl/IdeaDefaultIdeTargetPlatformKindProvider.kt b/plugins/kotlin/jps/jps-common/src/org/jetbrains/kotlin/platform/impl/IdeaDefaultIdeTargetPlatformKindProvider.kt
deleted file mode 100644
index 647b9c6d6e2b..000000000000
--- a/plugins/kotlin/jps/jps-common/src/org/jetbrains/kotlin/platform/impl/IdeaDefaultIdeTargetPlatformKindProvider.kt
+++ /dev/null
@@ -1,9 +0,0 @@
-// Copyright 2000-2021 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
-
-package org.jetbrains.kotlin.platform.impl
-
-import org.jetbrains.kotlin.platform.DefaultIdeTargetPlatformKindProvider
-
-class IdeaDefaultIdeTargetPlatformKindProvider private constructor() : DefaultIdeTargetPlatformKindProvider {
- override val defaultPlatform = JvmIdePlatformKind.defaultPlatform
-} \ No newline at end of file
diff --git a/plugins/kotlin/jps/jps-common/src/org/jetbrains/kotlin/platform/impl/JsIdePlatformKind.kt b/plugins/kotlin/jps/jps-common/src/org/jetbrains/kotlin/platform/impl/JsIdePlatformKind.kt
deleted file mode 100644
index 4159789a2483..000000000000
--- a/plugins/kotlin/jps/jps-common/src/org/jetbrains/kotlin/platform/impl/JsIdePlatformKind.kt
+++ /dev/null
@@ -1,63 +0,0 @@
-// Copyright 2000-2021 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
-
-@file:JvmName("JsIdePlatformUtil")
-@file:Suppress("DEPRECATION_ERROR", "DeprecatedCallableAddReplaceWith")
-
-package org.jetbrains.kotlin.platform.impl
-
-import org.jetbrains.kotlin.cli.common.arguments.CommonCompilerArguments
-import org.jetbrains.kotlin.cli.common.arguments.K2JSCompilerArguments
-import org.jetbrains.kotlin.platform.IdePlatform
-import org.jetbrains.kotlin.platform.IdePlatformKind
-import org.jetbrains.kotlin.platform.TargetPlatform
-import org.jetbrains.kotlin.platform.TargetPlatformVersion
-import org.jetbrains.kotlin.platform.js.JsPlatforms
-import org.jetbrains.kotlin.platform.js.isJs
-
-object JsIdePlatformKind : IdePlatformKind<JsIdePlatformKind>() {
- override fun supportsTargetPlatform(platform: TargetPlatform): Boolean = platform.isJs()
-
- override fun platformByCompilerArguments(arguments: CommonCompilerArguments): TargetPlatform? {
- return if (arguments is K2JSCompilerArguments)
- JsPlatforms.defaultJsPlatform
- else
- null
- }
-
- val platforms get() = listOf(JsPlatforms.defaultJsPlatform)
- override val defaultPlatform get() = JsPlatforms.defaultJsPlatform
-
- @Deprecated(
- message = "IdePlatform is deprecated and will be removed soon, please, migrate to org.jetbrains.kotlin.platform.TargetPlatform",
- level = DeprecationLevel.ERROR
- )
- override fun getDefaultPlatform(): IdePlatform<*, *> = Platform
-
- override fun createArguments(): CommonCompilerArguments {
- return K2JSCompilerArguments()
- }
-
- override val argumentsClass get() = K2JSCompilerArguments::class.java
-
- override val name get() = "JavaScript"
-
- @Deprecated(
- message = "IdePlatform is deprecated and will be removed soon, please, migrate to org.jetbrains.kotlin.platform.TargetPlatform",
- level = DeprecationLevel.ERROR
- )
- object Platform : IdePlatform<JsIdePlatformKind, K2JSCompilerArguments>() {
- override val kind get() = JsIdePlatformKind
- override val version get() = TargetPlatformVersion.NoVersion
- override fun createArguments(init: K2JSCompilerArguments.() -> Unit) = K2JSCompilerArguments().apply(init)
- }
-}
-
-val IdePlatformKind<*>?.isJavaScript
- get() = this is JsIdePlatformKind
-
-@Deprecated(
- message = "IdePlatform is deprecated and will be removed soon, please, migrate to org.jetbrains.kotlin.platform.TargetPlatform",
- level = DeprecationLevel.ERROR
-)
-val IdePlatform<*, *>?.isJavaScript
- get() = this is JsIdePlatformKind.Platform
diff --git a/plugins/kotlin/jps/jps-common/src/org/jetbrains/kotlin/platform/impl/JvmIdePlatformKind.kt b/plugins/kotlin/jps/jps-common/src/org/jetbrains/kotlin/platform/impl/JvmIdePlatformKind.kt
deleted file mode 100644
index fa3ad6428f36..000000000000
--- a/plugins/kotlin/jps/jps-common/src/org/jetbrains/kotlin/platform/impl/JvmIdePlatformKind.kt
+++ /dev/null
@@ -1,74 +0,0 @@
-// Copyright 2000-2021 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
-
-@file:JvmName("JvmIdePlatformUtil")
-@file:Suppress("DEPRECATION_ERROR", "DeprecatedCallableAddReplaceWith")
-
-package org.jetbrains.kotlin.platform.impl
-
-import com.intellij.util.text.VersionComparatorUtil
-import org.jetbrains.kotlin.cli.common.arguments.CommonCompilerArguments
-import org.jetbrains.kotlin.cli.common.arguments.K2JVMCompilerArguments
-import org.jetbrains.kotlin.config.JvmTarget
-import org.jetbrains.kotlin.platform.IdePlatform
-import org.jetbrains.kotlin.platform.IdePlatformKind
-import org.jetbrains.kotlin.platform.TargetPlatform
-import org.jetbrains.kotlin.platform.jvm.JvmPlatforms
-import org.jetbrains.kotlin.platform.jvm.isJvm
-
-object JvmIdePlatformKind : IdePlatformKind<JvmIdePlatformKind>() {
- override fun supportsTargetPlatform(platform: TargetPlatform): Boolean = platform.isJvm()
-
- override fun platformByCompilerArguments(arguments: CommonCompilerArguments): TargetPlatform? {
- if (arguments !is K2JVMCompilerArguments) return null
-
- val jvmTargetDescription = arguments.jvmTarget
- ?: return JvmPlatforms.defaultJvmPlatform
-
- val jvmTarget = JvmTarget.values()
- .firstOrNull { VersionComparatorUtil.COMPARATOR.compare(it.description, jvmTargetDescription) >= 0 }
- ?: return JvmPlatforms.defaultJvmPlatform
-
- return JvmPlatforms.jvmPlatformByTargetVersion(jvmTarget)
- }
-
- @Deprecated(
- message = "IdePlatform is deprecated and will be removed soon, please, migrate to org.jetbrains.kotlin.platform.TargetPlatform",
- level = DeprecationLevel.ERROR
- )
- override fun getDefaultPlatform(): Platform = Platform(JvmTarget.DEFAULT)
-
- override fun createArguments(): CommonCompilerArguments {
- return K2JVMCompilerArguments()
- }
-
- val platforms: List<TargetPlatform> = JvmTarget.values()
- .map { ver -> JvmPlatforms.jvmPlatformByTargetVersion(ver) } + listOf(JvmPlatforms.unspecifiedJvmPlatform)
-
- override val defaultPlatform get() = JvmPlatforms.defaultJvmPlatform
-
- override val argumentsClass get() = K2JVMCompilerArguments::class.java
-
- override val name get() = "JVM"
-
- @Deprecated(
- message = "IdePlatform is deprecated and will be removed soon, please, migrate to org.jetbrains.kotlin.platform.TargetPlatform",
- level = DeprecationLevel.ERROR
- )
- data class Platform(override val version: JvmTarget) : IdePlatform<JvmIdePlatformKind, K2JVMCompilerArguments>() {
- override val kind get() = JvmIdePlatformKind
-
- override fun createArguments(init: K2JVMCompilerArguments.() -> Unit) = K2JVMCompilerArguments()
- .apply(init)
- .apply { jvmTarget = this@Platform.version.description }
- }
-}
-
-val IdePlatformKind<*>?.isJvm
- get() = this is JvmIdePlatformKind
-
-@Deprecated(
- message = "IdePlatform is deprecated and will be removed soon, please, migrate to org.jetbrains.kotlin.platform.TargetPlatform",
- level = DeprecationLevel.ERROR
-)
-val IdePlatform<*, *>.isJvm: Boolean
- get() = this is JvmIdePlatformKind.Platform \ No newline at end of file
diff --git a/plugins/kotlin/jps/jps-common/src/org/jetbrains/kotlin/platform/impl/NativeIdePlatformKind.kt b/plugins/kotlin/jps/jps-common/src/org/jetbrains/kotlin/platform/impl/NativeIdePlatformKind.kt
deleted file mode 100644
index f1003ce8cc37..000000000000
--- a/plugins/kotlin/jps/jps-common/src/org/jetbrains/kotlin/platform/impl/NativeIdePlatformKind.kt
+++ /dev/null
@@ -1,67 +0,0 @@
-// Copyright 2000-2021 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
-
-@file:JvmName("NativeIdePlatformUtil")
-@file:Suppress("DEPRECATION_ERROR", "DeprecatedCallableAddReplaceWith")
-
-package org.jetbrains.kotlin.platform.impl
-
-import org.jetbrains.kotlin.cli.common.arguments.CommonCompilerArguments
-import org.jetbrains.kotlin.platform.IdePlatform
-import org.jetbrains.kotlin.platform.IdePlatformKind
-import org.jetbrains.kotlin.platform.TargetPlatform
-import org.jetbrains.kotlin.platform.TargetPlatformVersion
-import org.jetbrains.kotlin.platform.konan.NativePlatforms
-import org.jetbrains.kotlin.platform.konan.isNative
-
-object NativeIdePlatformKind : IdePlatformKind<NativeIdePlatformKind>() {
- override fun supportsTargetPlatform(platform: TargetPlatform): Boolean = platform.isNative()
-
- override fun platformByCompilerArguments(arguments: CommonCompilerArguments): TargetPlatform? {
- return if (arguments is FakeK2NativeCompilerArguments)
- NativePlatforms.unspecifiedNativePlatform
- else
- null
- }
-
- override fun createArguments(): CommonCompilerArguments {
- return FakeK2NativeCompilerArguments()
- }
-
- override val defaultPlatform: TargetPlatform
- get() = NativePlatforms.unspecifiedNativePlatform
-
- @Deprecated(
- message = "IdePlatform is deprecated and will be removed soon, please, migrate to org.jetbrains.kotlin.platform.TargetPlatform",
- level = DeprecationLevel.ERROR
- )
- override fun getDefaultPlatform(): IdePlatform<*, *> = Platform
-
- override val argumentsClass
- get() = FakeK2NativeCompilerArguments::class.java
-
- override val name
- get() = "Native"
-
- @Deprecated(
- message = "IdePlatform is deprecated and will be removed soon, please, migrate to org.jetbrains.kotlin.platform.TargetPlatform",
- level = DeprecationLevel.ERROR
- )
- object Platform : IdePlatform<NativeIdePlatformKind, FakeK2NativeCompilerArguments>() {
- override val kind get() = NativeIdePlatformKind
- override val version get() = TargetPlatformVersion.NoVersion
- override fun createArguments(init: FakeK2NativeCompilerArguments.() -> Unit) = FakeK2NativeCompilerArguments().apply(init)
- }
-}
-
-// These are fake compiler arguments for Kotlin/Native - only for usage within IDEA plugin:
-class FakeK2NativeCompilerArguments : CommonCompilerArguments()
-
-val IdePlatformKind<*>?.isKotlinNative
- get() = this is NativeIdePlatformKind
-
-@Deprecated(
- message = "IdePlatform is deprecated and will be removed soon, please, migrate to org.jetbrains.kotlin.platform.TargetPlatform",
- level = DeprecationLevel.ERROR
-)
-val IdePlatform<*, *>?.isKotlinNative
- get() = this is NativeIdePlatformKind.Platform