Kotlin Facet: Convert paths to OS-independent form
#KT-17223 Fixed
This commit is contained in:
@@ -16,12 +16,12 @@
|
||||
|
||||
package org.jetbrains.kotlin.config
|
||||
|
||||
import com.intellij.util.PathUtil
|
||||
import com.intellij.util.xmlb.SkipDefaultsSerializationFilter
|
||||
import com.intellij.util.xmlb.XmlSerializer
|
||||
import org.jdom.DataConversionException
|
||||
import org.jdom.Element
|
||||
import org.jetbrains.kotlin.cli.common.arguments.K2JSCompilerArguments
|
||||
import org.jetbrains.kotlin.cli.common.arguments.K2JVMCompilerArguments
|
||||
import org.jetbrains.kotlin.cli.common.arguments.*
|
||||
|
||||
fun Element.getOption(name: String) = getChildren("option").firstOrNull { it.getAttribute("name").value == name }
|
||||
|
||||
@@ -116,6 +116,36 @@ fun deserializeFacetSettings(element: Element): KotlinFacetSettings {
|
||||
}
|
||||
}
|
||||
|
||||
fun CommonCompilerArguments.convertPathsToSystemIndependent() {
|
||||
pluginClasspaths?.forEachIndexed { index, s -> pluginClasspaths[index] = PathUtil.toSystemIndependentName(s) }
|
||||
|
||||
when (this) {
|
||||
is K2JVMCompilerArguments -> {
|
||||
destination = PathUtil.toSystemIndependentName(destination)
|
||||
classpath = PathUtil.toSystemIndependentName(classpath)
|
||||
jdkHome = PathUtil.toSystemIndependentName(jdkHome)
|
||||
kotlinHome = PathUtil.toSystemIndependentName(kotlinHome)
|
||||
friendPaths?.forEachIndexed { index, s -> friendPaths[index] = PathUtil.toSystemIndependentName(s) }
|
||||
declarationsOutputPath = PathUtil.toSystemIndependentName(declarationsOutputPath)
|
||||
}
|
||||
|
||||
is K2JSCompilerArguments -> {
|
||||
outputFile = PathUtil.toSystemIndependentName(outputFile)
|
||||
libraries = PathUtil.toSystemIndependentName(libraries)
|
||||
}
|
||||
|
||||
is K2MetadataCompilerArguments -> {
|
||||
destination = PathUtil.toSystemIndependentName(destination)
|
||||
classpath = PathUtil.toSystemIndependentName(classpath)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun CompilerSettings.convertPathsToSystemIndependent() {
|
||||
scriptTemplatesClasspath = PathUtil.toSystemIndependentName(scriptTemplatesClasspath)
|
||||
outputDirectoryForJsLibraryFiles = PathUtil.toSystemIndependentName(outputDirectoryForJsLibraryFiles)
|
||||
}
|
||||
|
||||
fun KotlinFacetSettings.serializeFacetSettings(element: Element) {
|
||||
val filter = SkipDefaultsSerializationFilter()
|
||||
|
||||
@@ -126,13 +156,15 @@ fun KotlinFacetSettings.serializeFacetSettings(element: Element) {
|
||||
if (!useProjectSettings) {
|
||||
element.setAttribute("useProjectSettings", useProjectSettings.toString())
|
||||
}
|
||||
compilerSettings?.let {
|
||||
compilerSettings?.let { copyBean(it) }?.let {
|
||||
it.convertPathsToSystemIndependent()
|
||||
Element("compilerSettings").apply {
|
||||
XmlSerializer.serializeInto(it, this, filter)
|
||||
element.addContent(this)
|
||||
}
|
||||
}
|
||||
compilerArguments?.let {
|
||||
compilerArguments?.let { copyBean(it) }?.let {
|
||||
it.convertPathsToSystemIndependent()
|
||||
Element("compilerArguments").apply {
|
||||
XmlSerializer.serializeInto(it, this, filter)
|
||||
element.addContent(this)
|
||||
|
||||
@@ -653,7 +653,7 @@ class KotlinMavenImporterTest : MavenImportingTestCase() {
|
||||
Assert.assertEquals("1.8", (compilerArguments as K2JVMCompilerArguments).jvmTarget)
|
||||
Assert.assertEquals(LanguageFeature.State.ENABLED, coroutineSupport)
|
||||
Assert.assertEquals(
|
||||
listOf("-jdk-home", "c:\\program files\\jdk1.8"),
|
||||
listOf("-jdk-home", "c:/program files/jdk1.8"),
|
||||
compilerSettings!!.additionalArgumentsAsList
|
||||
)
|
||||
}
|
||||
|
||||
@@ -178,6 +178,7 @@ fun parseCompilerArgumentsToFacet(arguments: List<String>, defaultArguments: Lis
|
||||
|
||||
val defaultCompilerArguments = compilerArguments::class.java.newInstance()
|
||||
parseArguments(defaultArguments.toTypedArray(), defaultCompilerArguments, true)
|
||||
defaultCompilerArguments.convertPathsToSystemIndependent()
|
||||
|
||||
val oldCoroutineSupport = CoroutineSupport.byCompilerArguments(compilerArguments)
|
||||
compilerArguments.coroutinesEnable = false
|
||||
@@ -186,6 +187,8 @@ fun parseCompilerArgumentsToFacet(arguments: List<String>, defaultArguments: Lis
|
||||
|
||||
parseArguments(argumentArray, compilerArguments, true)
|
||||
|
||||
compilerArguments.convertPathsToSystemIndependent()
|
||||
|
||||
val restoreCoroutineSupport =
|
||||
!compilerArguments.coroutinesEnable && !compilerArguments.coroutinesWarn && !compilerArguments.coroutinesError
|
||||
|
||||
|
||||
@@ -624,7 +624,7 @@ class GradleFacetImportTest : GradleImportingTestCase() {
|
||||
|
||||
with (facetSettings) {
|
||||
Assert.assertEquals(
|
||||
listOf("-jdk-home", "c:\\program files\\jdk1.8", "-Xmulti-platform"),
|
||||
listOf("-jdk-home", "c:/program files/jdk1.8", "-Xmulti-platform"),
|
||||
compilerSettings!!.additionalArgumentsAsList
|
||||
)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user