Kotlin Facet: Do no present compiler plugin classpaths and options in additional arguments string

#KT-16313 Fixed
This commit is contained in:
Alexey Sedunov
2017-03-09 13:15:24 +03:00
parent cc20c66bfc
commit faa0dff649
3 changed files with 121 additions and 10 deletions
@@ -1218,6 +1218,74 @@ class KotlinMavenImporterTest : MavenImportingTestCase() {
Assert.assertEquals(TargetPlatformKind.Common, facetSettings.targetPlatformKind)
}
fun testNoPluginsInAdditionalArgs() {
createProjectSubDirs("src/main/kotlin", "src/main/kotlin.jvm", "src/test/kotlin", "src/test/kotlin.jvm")
importProject("""
<groupId>test</groupId>
<artifactId>project</artifactId>
<version>1.0.0</version>
<dependencies>
<dependency>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-stdlib</artifactId>
<version>1.1.0</version>
</dependency>
</dependencies>
<build>
<sourceDirectory>src/main/kotlin</sourceDirectory>
<plugins>
<plugin>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-maven-plugin</artifactId>
<executions>
<execution>
<id>compile</id>
<goals>
<goal>js</goal>
</goals>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-maven-allopen</artifactId>
<version>1.1.0</version>
</dependency>
</dependencies>
<configuration>
<compilerPlugins>
<plugin>spring</plugin>
</compilerPlugins>
</configuration>
</plugin>
</plugins>
</build>
""")
assertModules("project")
assertImporterStatePresent()
with(facetSettings) {
Assert.assertEquals(
"-version",
compilerSettings!!.additionalArguments
)
Assert.assertEquals(
listOf("plugin:org.jetbrains.kotlin.allopen:annotation=org.springframework.stereotype.Component",
"plugin:org.jetbrains.kotlin.allopen:annotation=org.springframework.transaction.annotation.Transactional",
"plugin:org.jetbrains.kotlin.allopen:annotation=org.springframework.scheduling.annotation.Async",
"plugin:org.jetbrains.kotlin.allopen:annotation=org.springframework.cache.annotation.Cacheable"),
compilerArguments!!.pluginOptions.toList()
)
}
}
private fun assertImporterStatePresent() {
assertNotNull("Kotlin importer component is not present", myTestFixture.module.getComponent(KotlinImporterComponent::class.java))
}
@@ -131,26 +131,29 @@ fun KotlinFacet.configureFacet(
}
}
// "Primary" fields are written to argument beans directly and thus not presented in the "additional arguments" string
// Update these lists when facet/project settings UI changes
private val commonExposedFields = listOf("languageVersion",
private val commonPrimaryFields = listOf("languageVersion",
"apiVersion",
"suppressWarnings",
"coroutinesEnable",
"coroutinesWarn",
"coroutinesError")
private val jvmExposedFields = commonExposedFields +
"coroutinesError",
"pluginClasspaths",
"pluginOptions")
private val jvmPrimaryFields = commonPrimaryFields +
listOf("jvmTarget")
private val jsExposedFields = commonExposedFields +
private val jsPrimaryFields = commonPrimaryFields +
listOf("sourceMap",
"outputPrefix",
"outputPostfix",
"moduleKind")
private val CommonCompilerArguments.exposedFields: List<String>
private val CommonCompilerArguments.primaryFields: List<String>
get() = when (this) {
is K2JVMCompilerArguments -> jvmExposedFields
is K2JSCompilerArguments -> jsExposedFields
else -> commonExposedFields
is K2JVMCompilerArguments -> jvmPrimaryFields
is K2JSCompilerArguments -> jsPrimaryFields
else -> commonPrimaryFields
}
fun parseCompilerArgumentsToFacet(arguments: List<String>, defaultArguments: List<String>, kotlinFacet: KotlinFacet) {
@@ -175,9 +178,9 @@ fun parseCompilerArgumentsToFacet(arguments: List<String>, defaultArguments: Lis
// Retain only fields exposed in facet configuration editor.
// The rest is combined into string and stored in CompilerSettings.additionalArguments
val exposedFields = compilerArguments.exposedFields
val primaryFields = compilerArguments.primaryFields
fun exposeAsAdditionalArgument(field: Field) = field.name !in exposedFields && field.get(compilerArguments) != field.get(defaultCompilerArguments)
fun exposeAsAdditionalArgument(field: Field) = field.name !in primaryFields && field.get(compilerArguments) != field.get(defaultCompilerArguments)
val additionalArgumentsString = with(compilerArguments.javaClass.newInstance()) {
copyFieldsSatisfying(compilerArguments, this, ::exposeAsAdditionalArgument)
@@ -603,4 +603,44 @@ class GradleFacetImportTest : GradleImportingTestCase() {
)
}
}
@Test
fun testNoPluginsInAdditionalArgs() {
createProjectSubFile("build.gradle", """
group 'Again'
version '1.0-SNAPSHOT'
buildscript {
repositories {
mavenCentral()
maven {
url 'http://dl.bintray.com/kotlin/kotlin-eap-1.1'
}
}
dependencies {
classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:1.1.0")
classpath("org.jetbrains.kotlin:kotlin-allopen:1.1.0")
}
}
apply plugin: 'kotlin'
apply plugin: "kotlin-spring"
""")
importProject()
with (facetSettings) {
Assert.assertEquals(
"-version",
compilerSettings!!.additionalArguments
)
Assert.assertEquals(
listOf("plugin:org.jetbrains.kotlin.allopen:annotation=org.springframework.stereotype.Component",
"plugin:org.jetbrains.kotlin.allopen:annotation=org.springframework.transaction.annotation.Transactional",
"plugin:org.jetbrains.kotlin.allopen:annotation=org.springframework.scheduling.annotation.Async",
"plugin:org.jetbrains.kotlin.allopen:annotation=org.springframework.cache.annotation.Cacheable"),
compilerArguments!!.pluginOptions.toList()
)
}
}
}