diff --git a/idea/idea-jps-common/src/org/jetbrains/kotlin/config/KotlinFacetSettings.kt b/idea/idea-jps-common/src/org/jetbrains/kotlin/config/KotlinFacetSettings.kt index cfcd52a3b9d..bf7d9b2e036 100644 --- a/idea/idea-jps-common/src/org/jetbrains/kotlin/config/KotlinFacetSettings.kt +++ b/idea/idea-jps-common/src/org/jetbrains/kotlin/config/KotlinFacetSettings.kt @@ -80,6 +80,7 @@ class KotlinFacetSettings { val DEFAULT_VERSION = 0 } + var version = CURRENT_VERSION var useProjectSettings: Boolean = true var compilerArguments: CommonCompilerArguments? = null diff --git a/idea/idea-jps-common/src/org/jetbrains/kotlin/config/facetSerialization.kt b/idea/idea-jps-common/src/org/jetbrains/kotlin/config/facetSerialization.kt index d58533299e6..ae75fa519bd 100644 --- a/idea/idea-jps-common/src/org/jetbrains/kotlin/config/facetSerialization.kt +++ b/idea/idea-jps-common/src/org/jetbrains/kotlin/config/facetSerialization.kt @@ -132,8 +132,8 @@ fun deserializeFacetSettings(element: Element): KotlinFacetSettings { 1 -> readV1Config(element) 2 -> readV2Config(element) KotlinFacetSettings.CURRENT_VERSION -> readLatestConfig(element) - else -> KotlinFacetSettings() // Reset facet configuration if versions don't match - } + else -> return KotlinFacetSettings() // Reset facet configuration if versions don't match + }.apply { this.version = version } } fun CommonCompilerArguments.convertPathsToSystemIndependent() { @@ -166,10 +166,9 @@ fun CompilerSettings.convertPathsToSystemIndependent() { outputDirectoryForJsLibraryFiles = PathUtil.toSystemIndependentName(outputDirectoryForJsLibraryFiles) } -fun KotlinFacetSettings.serializeFacetSettings(element: Element) { +private fun KotlinFacetSettings.writeLatestConfig(element: Element) { val filter = SkipDefaultsSerializationFilter() - element.setAttribute("version", KotlinFacetSettings.CURRENT_VERSION.toString()) targetPlatformKind?.let { element.setAttribute("platform", it.description) } @@ -191,3 +190,35 @@ fun KotlinFacetSettings.serializeFacetSettings(element: Element) { } } } + +// Special treatment of v2 may be dropped after transition to IDEA 172 +private fun KotlinFacetSettings.writeV2Config(element: Element) { + writeLatestConfig(element) + element.getChild("compilerArguments")?.let { + it.getOption("coroutinesState")?.detach() + val coroutineOption = when (compilerArguments?.coroutinesState) { + CommonCompilerArguments.ENABLE -> "coroutinesEnable" + CommonCompilerArguments.WARN -> "coroutinesWarn" + CommonCompilerArguments.ERROR -> "coroutinesError" + else -> null + } + if (coroutineOption != null) { + Element("option").apply { + setAttribute("name", coroutineOption) + setAttribute("value", "true") + it.addContent(this) + } + } + } +} + +fun KotlinFacetSettings.serializeFacetSettings(element: Element) { + val versionToWrite = if (version == 2) version else KotlinFacetSettings.CURRENT_VERSION + element.setAttribute("version", versionToWrite.toString()) + if (versionToWrite == 2) { + writeV2Config(element) + } + else { + writeLatestConfig(element) + } +} diff --git a/idea/testData/configuration/loadAndSaveProjectWithV2FacetConfig/module.iml b/idea/testData/configuration/loadAndSaveProjectWithV2FacetConfig/module.iml new file mode 100644 index 00000000000..f3f20b7cbfe --- /dev/null +++ b/idea/testData/configuration/loadAndSaveProjectWithV2FacetConfig/module.iml @@ -0,0 +1,26 @@ + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/idea/testData/configuration/loadAndSaveProjectWithV2FacetConfig/projectFile.ipr b/idea/testData/configuration/loadAndSaveProjectWithV2FacetConfig/projectFile.ipr new file mode 100644 index 00000000000..a1407e2c8cd --- /dev/null +++ b/idea/testData/configuration/loadAndSaveProjectWithV2FacetConfig/projectFile.ipr @@ -0,0 +1,41 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/idea/testData/configuration/loadAndSaveProjectWithV2FacetConfig/src/foo.kt b/idea/testData/configuration/loadAndSaveProjectWithV2FacetConfig/src/foo.kt new file mode 100644 index 00000000000..e69de29bb2d diff --git a/idea/tests/org/jetbrains/kotlin/idea/configuration/ConfigureKotlinInTempDirTest.kt b/idea/tests/org/jetbrains/kotlin/idea/configuration/ConfigureKotlinInTempDirTest.kt index 06c0d75b05e..3603cd865e7 100644 --- a/idea/tests/org/jetbrains/kotlin/idea/configuration/ConfigureKotlinInTempDirTest.kt +++ b/idea/tests/org/jetbrains/kotlin/idea/configuration/ConfigureKotlinInTempDirTest.kt @@ -86,4 +86,13 @@ class ConfigureKotlinInTempDirTest : AbstractConfigureKotlinTest() { Assert.assertEquals("1.1", settings.apiLevel!!.description) Assert.assertEquals("-version -Xallow-kotlin-package -Xskip-metadata-version-check", settings.compilerSettings!!.additionalArguments) } + + fun testLoadAndSaveProjectWithV2FacetConfig() { + val moduleFileContentBefore = String(module.moduleFile!!.contentsToByteArray()) + val application = ApplicationManager.getApplication() as ApplicationImpl + application.doNotSave(false) + application.saveAll() + val moduleFileContentAfter = String(module.moduleFile!!.contentsToByteArray()) + Assert.assertEquals(moduleFileContentBefore, moduleFileContentAfter) + } }