From ddb034715d83068a6f88e253dd58303d50278403 Mon Sep 17 00:00:00 2001 From: Yan Zhulanow Date: Tue, 28 Aug 2018 23:18:46 +0500 Subject: [PATCH] Gradle importer: Join compiler plugin options as before the new MPP refactoring (KT-26424) Android Studio has at least two kinds of importers: a generic one (that is run when the "Refresh Gradle model" tool button is pressed) and a fast one (is run on the build variant switch). Fast importer doesn't invoke our import handlers (AndroidExtensionsGradleImportHandler) that modify the compiler options stored in Kotlin facet in some way. Until the recent MPP importer refactoring both old and new options were saved in the Kotlin facet; now only the new options persist. This is certainly better, though it breaks the existing behavior (as the options added by import handlers become lost). The alternative approach is to re-design import handlers in a way they won't require the whole module/source set node (so we can invoke them every time), though it requires a way more changes. --- .../jetbrains/kotlin/idea/facet/facetUtils.kt | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/idea/src/org/jetbrains/kotlin/idea/facet/facetUtils.kt b/idea/src/org/jetbrains/kotlin/idea/facet/facetUtils.kt index f23f027ad76..154819f541f 100644 --- a/idea/src/org/jetbrains/kotlin/idea/facet/facetUtils.kt +++ b/idea/src/org/jetbrains/kotlin/idea/facet/facetUtils.kt @@ -281,8 +281,12 @@ fun applyCompilerArgumentsToFacet( val defaultCompilerArguments = defaultArguments?.let { copyBean(it) } ?: compilerArguments::class.java.newInstance() defaultCompilerArguments.convertPathsToSystemIndependent() + val oldPluginOptions = compilerArguments.pluginOptions + val emptyArgs = compilerArguments::class.java.newInstance() copyBeanTo(arguments, compilerArguments) { property, value -> value != property.get(emptyArgs) } + compilerArguments.pluginOptions = joinPluginOptions(oldPluginOptions, arguments.pluginOptions) + compilerArguments.convertPathsToSystemIndependent() // Retain only fields exposed (and not explicitly ignored) in facet configuration editor. @@ -321,3 +325,15 @@ fun applyCompilerArgumentsToFacet( updateMergedArguments() } } + +private fun joinPluginOptions(old: Array?, new: Array?): Array? { + if (old == null && new == null) { + return old + } else if (new == null) { + return old + } else if (old == null) { + return new + } + + return (old + new).distinct().toTypedArray() +}