Skip to content

Commit faa0dff

Browse files
committed
Kotlin Facet: Do no present compiler plugin classpaths and options in additional arguments string
#KT-16313 Fixed
1 parent cc20c66 commit faa0dff

File tree

3 files changed

+121
-10
lines changed

3 files changed

+121
-10
lines changed

idea/idea-maven/test/org/jetbrains/kotlin/idea/maven/KotlinMavenImporterTest.kt

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1218,6 +1218,74 @@ class KotlinMavenImporterTest : MavenImportingTestCase() {
12181218
Assert.assertEquals(TargetPlatformKind.Common, facetSettings.targetPlatformKind)
12191219
}
12201220

1221+
fun testNoPluginsInAdditionalArgs() {
1222+
createProjectSubDirs("src/main/kotlin", "src/main/kotlin.jvm", "src/test/kotlin", "src/test/kotlin.jvm")
1223+
1224+
importProject("""
1225+
<groupId>test</groupId>
1226+
<artifactId>project</artifactId>
1227+
<version>1.0.0</version>
1228+
1229+
<dependencies>
1230+
<dependency>
1231+
<groupId>org.jetbrains.kotlin</groupId>
1232+
<artifactId>kotlin-stdlib</artifactId>
1233+
<version>1.1.0</version>
1234+
</dependency>
1235+
</dependencies>
1236+
1237+
<build>
1238+
<sourceDirectory>src/main/kotlin</sourceDirectory>
1239+
1240+
<plugins>
1241+
<plugin>
1242+
<groupId>org.jetbrains.kotlin</groupId>
1243+
<artifactId>kotlin-maven-plugin</artifactId>
1244+
<executions>
1245+
<execution>
1246+
<id>compile</id>
1247+
<goals>
1248+
<goal>js</goal>
1249+
</goals>
1250+
</execution>
1251+
</executions>
1252+
1253+
<dependencies>
1254+
<dependency>
1255+
<groupId>org.jetbrains.kotlin</groupId>
1256+
<artifactId>kotlin-maven-allopen</artifactId>
1257+
<version>1.1.0</version>
1258+
</dependency>
1259+
</dependencies>
1260+
1261+
<configuration>
1262+
<compilerPlugins>
1263+
<plugin>spring</plugin>
1264+
</compilerPlugins>
1265+
</configuration>
1266+
</plugin>
1267+
</plugins>
1268+
</build>
1269+
""")
1270+
1271+
assertModules("project")
1272+
assertImporterStatePresent()
1273+
1274+
with(facetSettings) {
1275+
Assert.assertEquals(
1276+
"-version",
1277+
compilerSettings!!.additionalArguments
1278+
)
1279+
Assert.assertEquals(
1280+
listOf("plugin:org.jetbrains.kotlin.allopen:annotation=org.springframework.stereotype.Component",
1281+
"plugin:org.jetbrains.kotlin.allopen:annotation=org.springframework.transaction.annotation.Transactional",
1282+
"plugin:org.jetbrains.kotlin.allopen:annotation=org.springframework.scheduling.annotation.Async",
1283+
"plugin:org.jetbrains.kotlin.allopen:annotation=org.springframework.cache.annotation.Cacheable"),
1284+
compilerArguments!!.pluginOptions.toList()
1285+
)
1286+
}
1287+
}
1288+
12211289
private fun assertImporterStatePresent() {
12221290
assertNotNull("Kotlin importer component is not present", myTestFixture.module.getComponent(KotlinImporterComponent::class.java))
12231291
}

idea/src/org/jetbrains/kotlin/idea/facet/facetUtils.kt

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -131,26 +131,29 @@ fun KotlinFacet.configureFacet(
131131
}
132132
}
133133

134+
// "Primary" fields are written to argument beans directly and thus not presented in the "additional arguments" string
134135
// Update these lists when facet/project settings UI changes
135-
private val commonExposedFields = listOf("languageVersion",
136+
private val commonPrimaryFields = listOf("languageVersion",
136137
"apiVersion",
137138
"suppressWarnings",
138139
"coroutinesEnable",
139140
"coroutinesWarn",
140-
"coroutinesError")
141-
private val jvmExposedFields = commonExposedFields +
141+
"coroutinesError",
142+
"pluginClasspaths",
143+
"pluginOptions")
144+
private val jvmPrimaryFields = commonPrimaryFields +
142145
listOf("jvmTarget")
143-
private val jsExposedFields = commonExposedFields +
146+
private val jsPrimaryFields = commonPrimaryFields +
144147
listOf("sourceMap",
145148
"outputPrefix",
146149
"outputPostfix",
147150
"moduleKind")
148151

149-
private val CommonCompilerArguments.exposedFields: List<String>
152+
private val CommonCompilerArguments.primaryFields: List<String>
150153
get() = when (this) {
151-
is K2JVMCompilerArguments -> jvmExposedFields
152-
is K2JSCompilerArguments -> jsExposedFields
153-
else -> commonExposedFields
154+
is K2JVMCompilerArguments -> jvmPrimaryFields
155+
is K2JSCompilerArguments -> jsPrimaryFields
156+
else -> commonPrimaryFields
154157
}
155158

156159
fun parseCompilerArgumentsToFacet(arguments: List<String>, defaultArguments: List<String>, kotlinFacet: KotlinFacet) {
@@ -175,9 +178,9 @@ fun parseCompilerArgumentsToFacet(arguments: List<String>, defaultArguments: Lis
175178
// Retain only fields exposed in facet configuration editor.
176179
// The rest is combined into string and stored in CompilerSettings.additionalArguments
177180

178-
val exposedFields = compilerArguments.exposedFields
181+
val primaryFields = compilerArguments.primaryFields
179182

180-
fun exposeAsAdditionalArgument(field: Field) = field.name !in exposedFields && field.get(compilerArguments) != field.get(defaultCompilerArguments)
183+
fun exposeAsAdditionalArgument(field: Field) = field.name !in primaryFields && field.get(compilerArguments) != field.get(defaultCompilerArguments)
181184

182185
val additionalArgumentsString = with(compilerArguments.javaClass.newInstance()) {
183186
copyFieldsSatisfying(compilerArguments, this, ::exposeAsAdditionalArgument)

idea/tests/org/jetbrains/kotlin/idea/codeInsight/gradle/GradleFacetImportTest.kt

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -603,4 +603,44 @@ class GradleFacetImportTest : GradleImportingTestCase() {
603603
)
604604
}
605605
}
606+
607+
@Test
608+
fun testNoPluginsInAdditionalArgs() {
609+
createProjectSubFile("build.gradle", """
610+
group 'Again'
611+
version '1.0-SNAPSHOT'
612+
613+
buildscript {
614+
repositories {
615+
mavenCentral()
616+
maven {
617+
url 'http://dl.bintray.com/kotlin/kotlin-eap-1.1'
618+
}
619+
}
620+
621+
dependencies {
622+
classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:1.1.0")
623+
classpath("org.jetbrains.kotlin:kotlin-allopen:1.1.0")
624+
}
625+
}
626+
627+
apply plugin: 'kotlin'
628+
apply plugin: "kotlin-spring"
629+
""")
630+
importProject()
631+
632+
with (facetSettings) {
633+
Assert.assertEquals(
634+
"-version",
635+
compilerSettings!!.additionalArguments
636+
)
637+
Assert.assertEquals(
638+
listOf("plugin:org.jetbrains.kotlin.allopen:annotation=org.springframework.stereotype.Component",
639+
"plugin:org.jetbrains.kotlin.allopen:annotation=org.springframework.transaction.annotation.Transactional",
640+
"plugin:org.jetbrains.kotlin.allopen:annotation=org.springframework.scheduling.annotation.Async",
641+
"plugin:org.jetbrains.kotlin.allopen:annotation=org.springframework.cache.annotation.Cacheable"),
642+
compilerArguments!!.pluginOptions.toList()
643+
)
644+
}
645+
}
606646
}

0 commit comments

Comments
 (0)