Kotlin Facet: Do not rewrite v2 configuration to latest version
This causes unwanted changes in configuration files after plugin update
This commit is contained in:
@@ -80,6 +80,7 @@ class KotlinFacetSettings {
|
|||||||
val DEFAULT_VERSION = 0
|
val DEFAULT_VERSION = 0
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var version = CURRENT_VERSION
|
||||||
var useProjectSettings: Boolean = true
|
var useProjectSettings: Boolean = true
|
||||||
|
|
||||||
var compilerArguments: CommonCompilerArguments? = null
|
var compilerArguments: CommonCompilerArguments? = null
|
||||||
|
|||||||
@@ -132,8 +132,8 @@ fun deserializeFacetSettings(element: Element): KotlinFacetSettings {
|
|||||||
1 -> readV1Config(element)
|
1 -> readV1Config(element)
|
||||||
2 -> readV2Config(element)
|
2 -> readV2Config(element)
|
||||||
KotlinFacetSettings.CURRENT_VERSION -> readLatestConfig(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() {
|
fun CommonCompilerArguments.convertPathsToSystemIndependent() {
|
||||||
@@ -166,10 +166,9 @@ fun CompilerSettings.convertPathsToSystemIndependent() {
|
|||||||
outputDirectoryForJsLibraryFiles = PathUtil.toSystemIndependentName(outputDirectoryForJsLibraryFiles)
|
outputDirectoryForJsLibraryFiles = PathUtil.toSystemIndependentName(outputDirectoryForJsLibraryFiles)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun KotlinFacetSettings.serializeFacetSettings(element: Element) {
|
private fun KotlinFacetSettings.writeLatestConfig(element: Element) {
|
||||||
val filter = SkipDefaultsSerializationFilter()
|
val filter = SkipDefaultsSerializationFilter()
|
||||||
|
|
||||||
element.setAttribute("version", KotlinFacetSettings.CURRENT_VERSION.toString())
|
|
||||||
targetPlatformKind?.let {
|
targetPlatformKind?.let {
|
||||||
element.setAttribute("platform", it.description)
|
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)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -0,0 +1,26 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<module type="JAVA_MODULE" version="4">
|
||||||
|
<component name="FacetManager">
|
||||||
|
<facet type="kotlin-language" name="Kotlin">
|
||||||
|
<configuration version="2" platform="JVM 1.8" useProjectSettings="false">
|
||||||
|
<compilerSettings>
|
||||||
|
<option name="additionalArguments" value="-version -Xallow-kotlin-package -Xskip-metadata-version-check" />
|
||||||
|
</compilerSettings>
|
||||||
|
<compilerArguments>
|
||||||
|
<option name="jvmTarget" value="1.7" />
|
||||||
|
<option name="languageVersion" value="1.1" />
|
||||||
|
<option name="apiVersion" value="1.0" />
|
||||||
|
<option name="coroutinesEnable" value="true" />
|
||||||
|
</compilerArguments>
|
||||||
|
</configuration>
|
||||||
|
</facet>
|
||||||
|
</component>
|
||||||
|
<component name="NewModuleRootManager" inherit-compiler-output="true">
|
||||||
|
<exclude-output />
|
||||||
|
<content url="file://$MODULE_DIR$">
|
||||||
|
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
|
||||||
|
</content>
|
||||||
|
<orderEntry type="sourceFolder" forTests="false" />
|
||||||
|
<orderEntry type="library" name="KotlinJavaRuntime (2)" level="project" />
|
||||||
|
</component>
|
||||||
|
</module>
|
||||||
+41
@@ -0,0 +1,41 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="CompilerConfiguration">
|
||||||
|
<resourceExtensions />
|
||||||
|
<wildcardResourcePatterns>
|
||||||
|
<entry name="!?*.java" />
|
||||||
|
<entry name="!?*.form" />
|
||||||
|
<entry name="!?*.class" />
|
||||||
|
<entry name="!?*.groovy" />
|
||||||
|
<entry name="!?*.scala" />
|
||||||
|
<entry name="!?*.flex" />
|
||||||
|
<entry name="!?*.kt" />
|
||||||
|
<entry name="!?*.clj" />
|
||||||
|
<entry name="!?*.aj" />
|
||||||
|
</wildcardResourcePatterns>
|
||||||
|
<annotationProcessing>
|
||||||
|
<profile default="true" name="Default" enabled="false">
|
||||||
|
<processorPath useClasspath="true" />
|
||||||
|
</profile>
|
||||||
|
</annotationProcessing>
|
||||||
|
</component>
|
||||||
|
<component name="CopyrightManager" default="" />
|
||||||
|
<component name="ProjectModuleManager">
|
||||||
|
<modules>
|
||||||
|
<module fileurl="file://$PROJECT_DIR$/module.iml" filepath="$PROJECT_DIR$/module.iml" />
|
||||||
|
</modules>
|
||||||
|
</component>
|
||||||
|
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" default="true" assert-keyword="true" jdk-15="true" project-jdk-name="1.8" project-jdk-type="JavaSDK">
|
||||||
|
<output url="file://$PROJECT_DIR$/out" />
|
||||||
|
</component>
|
||||||
|
<component name="libraryTable">
|
||||||
|
<library name="KotlinJavaRuntime (2)">
|
||||||
|
<CLASSES>
|
||||||
|
<root url="jar://$PROJECT_DIR$/../mockRuntime11/kotlin-runtime.jar!/" />
|
||||||
|
</CLASSES>
|
||||||
|
<JAVADOC />
|
||||||
|
<SOURCES>
|
||||||
|
</SOURCES>
|
||||||
|
</library>
|
||||||
|
</component>
|
||||||
|
</project>
|
||||||
@@ -86,4 +86,13 @@ class ConfigureKotlinInTempDirTest : AbstractConfigureKotlinTest() {
|
|||||||
Assert.assertEquals("1.1", settings.apiLevel!!.description)
|
Assert.assertEquals("1.1", settings.apiLevel!!.description)
|
||||||
Assert.assertEquals("-version -Xallow-kotlin-package -Xskip-metadata-version-check", settings.compilerSettings!!.additionalArguments)
|
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)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user