From 2386a0b1ee42ec99341b74bf67e35fe2d357a4fa Mon Sep 17 00:00:00 2001 From: Konstantin Tskhovrebov Date: Tue, 7 Apr 2020 15:47:29 +0300 Subject: [PATCH] Add native run tasks data to KotlinTarget. Original commit: e1a88de3143584b39b5fc8be9c865140fa03cde9 --- .../kotlin/config/KotlinFacetSettings.kt | 38 ++++++++++++++++--- .../kotlin/config/facetSerialization.kt | 35 +++++++++++++---- 2 files changed, 60 insertions(+), 13 deletions(-) diff --git a/jps/jps-common/src/org/jetbrains/kotlin/config/KotlinFacetSettings.kt b/jps/jps-common/src/org/jetbrains/kotlin/config/KotlinFacetSettings.kt index c11fbd99dfa..2e2ec9eb36d 100644 --- a/jps/jps-common/src/org/jetbrains/kotlin/config/KotlinFacetSettings.kt +++ b/jps/jps-common/src/org/jetbrains/kotlin/config/KotlinFacetSettings.kt @@ -140,16 +140,44 @@ val KotlinMultiplatformVersion?.isNewMPP: Boolean val KotlinMultiplatformVersion?.isHmpp: Boolean get() = this == KotlinMultiplatformVersion.M3 -data class ExternalSystemTestTask(val testName: String, val externalSystemProjectId: String, val targetName: String?) { +interface ExternalSystemRunTask { + val taskName: String + val externalSystemProjectId: String + val targetName: String? +} - fun toStringRepresentation() = "$testName|$externalSystemProjectId|$targetName" +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) ExternalSystemTestTask(it[0], it[1], it[2]) else null } + line.split("|").let { if (it.size == 3) ExternalSystemTestRunTask(it[0], it[1], it[2]) else null } } - override fun toString() = "$testName@$externalSystemProjectId [$targetName]" + 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 { @@ -231,7 +259,7 @@ class KotlinFacetSettings { return field } - var externalSystemTestTasks: List = emptyList() + var externalSystemRunTasks: List = emptyList() @Suppress("DEPRECATION_ERROR") @Deprecated( diff --git a/jps/jps-common/src/org/jetbrains/kotlin/config/facetSerialization.kt b/jps/jps-common/src/org/jetbrains/kotlin/config/facetSerialization.kt index 1c4fd51330c..5d751b901eb 100644 --- a/jps/jps-common/src/org/jetbrains/kotlin/config/facetSerialization.kt +++ b/jps/jps-common/src/org/jetbrains/kotlin/config/facetSerialization.kt @@ -126,8 +126,15 @@ private fun readV2AndLaterConfig(element: Element): KotlinFacetSettings { this.targetPlatform = targetPlatform readElementsList(element, "implements", "implement")?.let { implementedModuleNames = it } readElementsList(element, "dependsOnModuleNames", "dependsOn")?.let { dependsOnModuleNames = it } - readElementsList(element, "externalSystemTestTasks", "externalSystemTestTask")?.let { - externalSystemTestTasks = it.mapNotNull { ExternalSystemTestTask.fromStringRepresentation(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 { @@ -318,12 +325,24 @@ private fun KotlinFacetSettings.writeLatestConfig(element: Element) { if (isHmppEnabled) { element.setAttribute("isHmppProject", mppVersion.isHmpp.toString()) } - if (externalSystemTestTasks.isNotEmpty()) { - saveElementsList( - element, - externalSystemTestTasks.map { it.toStringRepresentation() }, - "externalSystemTestTasks", - "externalSystemTestTask" + 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()) {