Kotlin Facet: Detect module platform by 'kotlin'/'kotlin2js' plugin
This commit is contained in:
@@ -49,6 +49,10 @@ class KotlinGradleModelBuilder : ModelBuilderService {
|
|||||||
val kotlinCompileTaskClasses = listOf("org.jetbrains.kotlin.gradle.tasks.KotlinCompile_Decorated",
|
val kotlinCompileTaskClasses = listOf("org.jetbrains.kotlin.gradle.tasks.KotlinCompile_Decorated",
|
||||||
"org.jetbrains.kotlin.gradle.tasks.Kotlin2JsCompile_Decorated")
|
"org.jetbrains.kotlin.gradle.tasks.Kotlin2JsCompile_Decorated")
|
||||||
val platformPluginIds = listOf("kotlin-platform-jvm", "kotlin-platform-js", "kotlin-platform-common")
|
val platformPluginIds = listOf("kotlin-platform-jvm", "kotlin-platform-js", "kotlin-platform-common")
|
||||||
|
val pluginToPlatform = linkedMapOf(
|
||||||
|
"kotlin" to "kotlin-platform-jvm",
|
||||||
|
"kotlin2js" to "kotlin-platform-js"
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun getErrorMessageBuilder(project: Project, e: Exception): ErrorMessageBuilder {
|
override fun getErrorMessageBuilder(project: Project, e: Exception): ErrorMessageBuilder {
|
||||||
@@ -126,12 +130,15 @@ class KotlinGradleModelBuilder : ModelBuilderService {
|
|||||||
collectCompilerArguments(compileTask, "getDefaultSerializedCompilerArguments", defaultCompilerArgumentsBySourceSet)
|
collectCompilerArguments(compileTask, "getDefaultSerializedCompilerArguments", defaultCompilerArgumentsBySourceSet)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
val platform = platformPluginIds.singleOrNull { project.plugins.findPlugin(it) != null }
|
||||||
|
?: pluginToPlatform.entries.singleOrNull { project.plugins.findPlugin(it.key) != null }?.value
|
||||||
|
|
||||||
return KotlinGradleModelImpl(
|
return KotlinGradleModelImpl(
|
||||||
getImplements(project),
|
getImplements(project),
|
||||||
currentCompilerArgumentsBySourceSet,
|
currentCompilerArgumentsBySourceSet,
|
||||||
defaultCompilerArgumentsBySourceSet,
|
defaultCompilerArgumentsBySourceSet,
|
||||||
getCoroutines(project),
|
getCoroutines(project),
|
||||||
platformPluginIds.singleOrNull { project.plugins.findPlugin(it) != null }
|
platform
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -445,40 +445,6 @@ class GradleFacetImportTest : GradleImportingTestCase() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
|
||||||
fun testCommonImport() {
|
|
||||||
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")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
apply plugin: 'kotlin'
|
|
||||||
|
|
||||||
dependencies {
|
|
||||||
compile "org.jetbrains.kotlin:kotlin-stdlib-common:1.1.0"
|
|
||||||
}
|
|
||||||
""")
|
|
||||||
importProject()
|
|
||||||
|
|
||||||
with (facetSettings) {
|
|
||||||
Assert.assertEquals("1.1", languageLevel!!.versionString)
|
|
||||||
Assert.assertEquals("1.1", apiLevel!!.versionString)
|
|
||||||
Assert.assertEquals(TargetPlatformKind.Common, targetPlatformKind)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun testJvmImportByPlatformPlugin() {
|
fun testJvmImportByPlatformPlugin() {
|
||||||
createProjectSubFile("build.gradle", """
|
createProjectSubFile("build.gradle", """
|
||||||
@@ -569,6 +535,66 @@ class GradleFacetImportTest : GradleImportingTestCase() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun testJvmImportByKotlinPlugin() {
|
||||||
|
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")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
apply plugin: 'kotlin'
|
||||||
|
""")
|
||||||
|
importProject()
|
||||||
|
|
||||||
|
with (facetSettings) {
|
||||||
|
Assert.assertEquals("1.1", languageLevel!!.versionString)
|
||||||
|
Assert.assertEquals("1.1", apiLevel!!.versionString)
|
||||||
|
Assert.assertEquals(TargetPlatformKind.Jvm[JvmTarget.JVM_1_6], targetPlatformKind)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun testJsImportByKotlin2JsPlugin() {
|
||||||
|
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")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
apply plugin: 'kotlin2js'
|
||||||
|
""")
|
||||||
|
importProject()
|
||||||
|
|
||||||
|
with (facetSettings) {
|
||||||
|
Assert.assertEquals("1.1", languageLevel!!.versionString)
|
||||||
|
Assert.assertEquals("1.1", apiLevel!!.versionString)
|
||||||
|
Assert.assertEquals(TargetPlatformKind.JavaScript, targetPlatformKind)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun testArgumentEscaping() {
|
fun testArgumentEscaping() {
|
||||||
createProjectSubFile("build.gradle", """
|
createProjectSubFile("build.gradle", """
|
||||||
|
|||||||
Reference in New Issue
Block a user