From b9e40ffaa11eed2fa75fd2ee07cc92ece2a50f00 Mon Sep 17 00:00:00 2001 From: Andrey Uskov Date: Thu, 22 Aug 2019 19:08:51 +0300 Subject: [PATCH] Add list of modules available via dependsOn in FacetSettings Original commit: 106452b5f0b56d3730857a49cdd844c98fdc613d --- .../kotlin/config/KotlinFacetSettings.kt | 3 +- .../kotlin/config/facetSerialization.kt | 53 ++++++++++++------- 2 files changed, 35 insertions(+), 21 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 6defec73059..78ae53efb2f 100644 --- a/jps/jps-common/src/org/jetbrains/kotlin/config/KotlinFacetSettings.kt +++ b/jps/jps-common/src/org/jetbrains/kotlin/config/KotlinFacetSettings.kt @@ -245,7 +245,8 @@ class KotlinFacetSettings { } } - var implementedModuleNames: List = emptyList() + var implementedModuleNames: List = emptyList() // used for first implementation of MPP, aka 'old' MPP + var dependsOnModuleNames: List = emptyList() // used for New MPP and later implementations var productionOutputPath: String? = null var testOutputPath: String? = null 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 900c1ad90fc..479d86a1402 100644 --- a/jps/jps-common/src/org/jetbrains/kotlin/config/facetSerialization.kt +++ b/jps/jps-common/src/org/jetbrains/kotlin/config/facetSerialization.kt @@ -136,14 +136,9 @@ private fun readV2AndLaterConfig(element: Element): KotlinFacetSettings { element.getAttributeValue("useProjectSettings")?.let { useProjectSettings = it.toBoolean() } val targetPlatform = element.getFacetPlatformByConfigurationElement() this.targetPlatform = targetPlatform - element.getChild("implements")?.let { - val items = it.getChildren("implement") - implementedModuleNames = if (items.isNotEmpty()) { - items.mapNotNull { (it.content.firstOrNull() as? Text)?.textTrim } - } else { - listOfNotNull((it.content.firstOrNull() as? Text)?.textTrim) - } - } + readModulesList(element, "implements", "implement")?.let { implementedModuleNames = it } + readModulesList(element, "dependsOnModuleNames", "dependsOn")?.let { dependsOnModuleNames = it } + element.getChild("sourceSets")?.let { val items = it.getChildren("sourceSet") sourceSetNames = items.mapNotNull { (it.content.firstOrNull() as? Text)?.textTrim } @@ -183,6 +178,18 @@ private fun readV2AndLaterConfig(element: Element): KotlinFacetSettings { } } +private fun readModulesList(element: Element, rootElementName: String, elementName: String): List? { + 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).apply { element.getChild("compilerArguments")?.children?.let { args -> @@ -303,18 +310,9 @@ private fun KotlinFacetSettings.writeLatestConfig(element: Element) { if (!useProjectSettings) { element.setAttribute("useProjectSettings", useProjectSettings.toString()) } - if (implementedModuleNames.isNotEmpty()) { - element.addContent( - Element("implements").apply { - val singleModule = implementedModuleNames.singleOrNull() - if (singleModule != null) { - addContent(singleModule) - } else { - implementedModuleNames.map { addContent(Element("implement").apply { addContent(it) }) } - } - } - ) - } + saveModulesList(element, implementedModuleNames, "implements", "implement") + saveModulesList(element, dependsOnModuleNames, "dependsOnModuleNames", "dependsOn") + if (sourceSetNames.isNotEmpty()) { element.addContent( Element("sourceSets").apply { @@ -356,6 +354,21 @@ private fun KotlinFacetSettings.writeLatestConfig(element: Element) { } } +private fun saveModulesList(element: Element, moduleList: List, rootElementName: String, elementName: String) { + if (moduleList.isNotEmpty()) { + element.addContent( + Element(rootElementName).apply { + val singleModule = moduleList.singleOrNull() + if (singleModule != null) { + addContent(singleModule) + } else { + moduleList.map { addContent(Element(elementName).apply { addContent(it) }) } + } + } + ) + } +} + fun CommonCompilerArguments.detectVersionAutoAdvance() { autoAdvanceLanguageVersion = languageVersion == null autoAdvanceApiVersion = apiVersion == null