Gradle: Implement new MPP model import

Original commit: ecf607d4fa
This commit is contained in:
Alexey Sedunov
2018-08-03 18:54:40 +03:00
committed by Sergey Igushkin
parent 350e68b20f
commit 5b1ea61cd1
2 changed files with 33 additions and 0 deletions
@@ -112,6 +112,12 @@ var CommonCompilerArguments.apiVersionView: VersionView
autoAdvanceApiVersion = value == VersionView.LatestStable autoAdvanceApiVersion = value == VersionView.LatestStable
} }
enum class KotlinModuleKind {
DEFAULT,
SOURCE_SET_HOLDER,
COMPILATION_AND_SOURCE_SET_HOLDER
}
class KotlinFacetSettings { class KotlinFacetSettings {
companion object { companion object {
// Increment this when making serialization-incompatible changes to configuration data // Increment this when making serialization-incompatible changes to configuration data
@@ -196,6 +202,9 @@ class KotlinFacetSettings {
var productionOutputPath: String? = null var productionOutputPath: String? = null
var testOutputPath: String? = null var testOutputPath: String? = null
var kind: KotlinModuleKind = KotlinModuleKind.DEFAULT
var sourceSetNames: List<String> = emptyList()
} }
fun TargetPlatformKind<*>.createCompilerArguments(init: CommonCompilerArguments.() -> Unit = {}): CommonCompilerArguments { fun TargetPlatformKind<*>.createCompilerArguments(init: CommonCompilerArguments.() -> Unit = {}): CommonCompilerArguments {
@@ -111,6 +111,20 @@ private fun readV2AndLaterConfig(element: Element): KotlinFacetSettings {
listOfNotNull((it.content.firstOrNull() as? Text)?.textTrim) listOfNotNull((it.content.firstOrNull() as? Text)?.textTrim)
} }
} }
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
element.getChild("compilerSettings")?.let { element.getChild("compilerSettings")?.let {
compilerSettings = CompilerSettings() compilerSettings = CompilerSettings()
XmlSerializer.deserializeInto(compilerSettings!!, it) XmlSerializer.deserializeInto(compilerSettings!!, it)
@@ -259,6 +273,16 @@ private fun KotlinFacetSettings.writeLatestConfig(element: Element) {
} }
) )
} }
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) })
}
productionOutputPath?.let { productionOutputPath?.let {
if (it != (compilerArguments as? K2JSCompilerArguments)?.outputFile) { if (it != (compilerArguments as? K2JSCompilerArguments)?.outputFile) {
element.addContent(Element("productionOutputPath").apply { addContent(PathUtil.toSystemIndependentName(it)) }) element.addContent(Element("productionOutputPath").apply { addContent(PathUtil.toSystemIndependentName(it)) })