MPP: Refactoring, extract IDE platform kinds, allow to add custom platforms

This commit is contained in:
Yan Zhulanow
2018-08-30 18:46:59 +05:00
parent cf1b2bedf4
commit d00f5b335a
81 changed files with 1327 additions and 844 deletions
@@ -26,7 +26,6 @@ import com.intellij.openapi.roots.*
import com.intellij.openapi.roots.impl.libraries.LibraryEx
import com.intellij.openapi.roots.libraries.Library
import com.intellij.openapi.util.AsyncResult
import com.intellij.util.PairConsumer
import com.intellij.util.PathUtil
import org.jdom.Element
import org.jdom.Text
@@ -38,16 +37,20 @@ import org.jetbrains.jps.model.java.JavaSourceRootType
import org.jetbrains.jps.model.module.JpsModuleSourceRootType
import org.jetbrains.kotlin.cli.common.arguments.K2JSCompilerArguments
import org.jetbrains.kotlin.cli.common.arguments.K2JVMCompilerArguments
import org.jetbrains.kotlin.cli.common.arguments.K2MetadataCompilerArguments
import org.jetbrains.kotlin.cli.common.arguments.parseCommandLineArguments
import org.jetbrains.kotlin.compilerRunner.ArgumentUtils
import org.jetbrains.kotlin.config.*
import org.jetbrains.kotlin.extensions.ProjectExtensionDescriptor
import org.jetbrains.kotlin.idea.facet.*
import org.jetbrains.kotlin.idea.framework.detectLibraryKind
import org.jetbrains.kotlin.idea.framework.libraryKind
import org.jetbrains.kotlin.idea.maven.configuration.KotlinMavenConfigurator
import org.jetbrains.kotlin.idea.project.targetPlatform
import org.jetbrains.kotlin.idea.platform.tooling
import org.jetbrains.kotlin.platform.IdePlatform
import org.jetbrains.kotlin.platform.IdePlatformKind
import org.jetbrains.kotlin.platform.impl.CommonIdePlatformKind
import org.jetbrains.kotlin.platform.impl.JsIdePlatformKind
import org.jetbrains.kotlin.platform.impl.JvmIdePlatformKind
import org.jetbrains.kotlin.platform.impl.isCommon
import org.jetbrains.kotlin.utils.SmartList
import org.jetbrains.kotlin.utils.addIfNotNull
import java.io.File
@@ -105,7 +108,7 @@ class KotlinMavenImporter : MavenImporter(KOTLIN_PLUGIN_GROUP_ID, KOTLIN_PLUGIN_
if (changes.dependencies) {
scheduleDownloadStdlibSources(mavenProject, module)
val targetLibraryKind = detectPlatformByExecutions(mavenProject)?.libraryKind
val targetLibraryKind = detectPlatformByExecutions(mavenProject)?.tooling?.libraryKind
if (targetLibraryKind != null) {
modifiableModelsProvider.getModifiableRootModel(module).orderEntries().forEachLibrary { library ->
if ((library as LibraryEx).kind == null) {
@@ -177,13 +180,9 @@ class KotlinMavenImporter : MavenImporter(KOTLIN_PLUGIN_GROUP_ID, KOTLIN_PLUGIN_
private fun getCompilerArgumentsByConfigurationElement(
mavenProject: MavenProject,
configuration: Element?,
platform: TargetPlatformKind<*>
platform: IdePlatform<*, *>
): List<String> {
val arguments = when (platform) {
is TargetPlatformKind.Jvm -> K2JVMCompilerArguments()
TargetPlatformKind.JavaScript -> K2JSCompilerArguments()
TargetPlatformKind.Common -> K2MetadataCompilerArguments()
}
val arguments = platform.createArguments()
arguments.apiVersion = configuration?.getChild("apiVersion")?.text ?:
mavenProject.properties["kotlin.compiler.apiVersion"]?.toString()
@@ -252,11 +251,13 @@ class KotlinMavenImporter : MavenImporter(KOTLIN_PLUGIN_GROUP_ID, KOTLIN_PLUGIN_
false,
ExternalProjectSystemRegistry.MAVEN_EXTERNAL_SOURCE_ID
)
val platform = detectPlatform(mavenProject)
// TODO There should be a way to figure out the correct platform version
val platform = detectPlatform(mavenProject)?.defaultPlatform
kotlinFacet.configureFacet(compilerVersion, LanguageFeature.Coroutines.defaultState, platform, modifiableModelsProvider)
val facetSettings = kotlinFacet.configuration.settings
val configuredPlatform = kotlinFacet.configuration.settings.targetPlatformKind!!
val configuredPlatform = kotlinFacet.configuration.settings.platform!!
val configuration = mavenPlugin.configurationElement
val sharedArguments = getCompilerArgumentsByConfigurationElement(mavenProject, configuration, configuredPlatform)
val executionArguments = mavenPlugin.executions
@@ -277,22 +278,28 @@ class KotlinMavenImporter : MavenImporter(KOTLIN_PLUGIN_GROUP_ID, KOTLIN_PLUGIN_
private fun detectPlatform(mavenProject: MavenProject) =
detectPlatformByExecutions(mavenProject) ?: detectPlatformByLibraries(mavenProject)
private fun detectPlatformByExecutions(mavenProject: MavenProject): TargetPlatformKind<*>? {
private fun detectPlatformByExecutions(mavenProject: MavenProject): IdePlatformKind<*>? {
return mavenProject.findPlugin(KOTLIN_PLUGIN_GROUP_ID, KOTLIN_PLUGIN_ARTIFACT_ID)?.executions?.flatMap { it.goals }
?.mapNotNull { goal ->
when (goal) {
PomFile.KotlinGoals.Compile, PomFile.KotlinGoals.TestCompile -> TargetPlatformKind.Jvm[JvmTarget.JVM_1_6]
PomFile.KotlinGoals.Js, PomFile.KotlinGoals.TestJs -> TargetPlatformKind.JavaScript
PomFile.KotlinGoals.MetaData -> TargetPlatformKind.Common
PomFile.KotlinGoals.Compile, PomFile.KotlinGoals.TestCompile -> JvmIdePlatformKind
PomFile.KotlinGoals.Js, PomFile.KotlinGoals.TestJs -> JsIdePlatformKind
PomFile.KotlinGoals.MetaData -> CommonIdePlatformKind
else -> null
}
}?.distinct()?.singleOrNull()
}
private fun detectPlatformByLibraries(mavenProject: MavenProject): TargetPlatformKind<*>? {
return TargetPlatformKind.ALL_PLATFORMS.firstOrNull {
it.mavenLibraryIds.any { mavenProject.findDependencies(KOTLIN_PLUGIN_GROUP_ID, it).isNotEmpty() }
private fun detectPlatformByLibraries(mavenProject: MavenProject): IdePlatformKind<*>? {
for (kind in IdePlatformKind.ALL_KINDS) {
val mavenLibraryIds = kind.tooling.mavenLibraryIds
if (mavenLibraryIds.any { mavenProject.findDependencies(KOTLIN_PLUGIN_GROUP_ID, it).isNotEmpty() }) {
// TODO we could return here the correct version
return kind
}
}
return null
}
// TODO in theory it should work like this but it doesn't as it couldn't unmark source roots that are not roots anymore.
@@ -362,12 +369,12 @@ class KotlinMavenImporter : MavenImporter(KOTLIN_PLUGIN_GROUP_ID, KOTLIN_PLUGIN_
}.distinct()
private fun setImplementedModuleName(kotlinFacet: KotlinFacet, mavenProject: MavenProject, module: Module) {
if (kotlinFacet.configuration.settings.targetPlatformKind == TargetPlatformKind.Common) {
if (kotlinFacet.configuration.settings.platform.isCommon) {
kotlinFacet.configuration.settings.implementedModuleNames = emptyList()
} else {
val manager = MavenProjectsManager.getInstance(module.project)
val mavenDependencies = mavenProject.dependencies.mapNotNull { manager?.findProject(it) }
val implemented = mavenDependencies.filter { detectPlatformByExecutions(it) == TargetPlatformKind.Common }
val implemented = mavenDependencies.filter { detectPlatformByExecutions(it).isCommon }
kotlinFacet.configuration.settings.implementedModuleNames = implemented.map { manager.findModule(it)?.name ?: it.displayName }
}
@@ -45,9 +45,14 @@ import org.jetbrains.kotlin.config.*
import org.jetbrains.kotlin.extensions.ProjectExtensionDescriptor
import org.jetbrains.kotlin.idea.facet.*
import org.jetbrains.kotlin.idea.framework.detectLibraryKind
import org.jetbrains.kotlin.idea.framework.libraryKind
import org.jetbrains.kotlin.idea.maven.configuration.KotlinMavenConfigurator
import org.jetbrains.kotlin.idea.project.targetPlatform
import org.jetbrains.kotlin.idea.platform.tooling
import org.jetbrains.kotlin.platform.IdePlatform
import org.jetbrains.kotlin.platform.IdePlatformKind
import org.jetbrains.kotlin.platform.impl.CommonIdePlatformKind
import org.jetbrains.kotlin.platform.impl.JsIdePlatformKind
import org.jetbrains.kotlin.platform.impl.JvmIdePlatformKind
import org.jetbrains.kotlin.platform.impl.isCommon
import org.jetbrains.kotlin.utils.SmartList
import org.jetbrains.kotlin.utils.addIfNotNull
import java.io.File
@@ -105,7 +110,7 @@ class KotlinMavenImporter : MavenImporter(KOTLIN_PLUGIN_GROUP_ID, KOTLIN_PLUGIN_
if (changes.dependencies) {
scheduleDownloadStdlibSources(mavenProject, module)
val targetLibraryKind = detectPlatformByExecutions(mavenProject)?.libraryKind
val targetLibraryKind = detectPlatformByExecutions(mavenProject)?.tooling?.libraryKind
if (targetLibraryKind != null) {
modifiableModelsProvider.getModifiableRootModel(module).orderEntries().forEachLibrary { library ->
if ((library as LibraryEx).kind == null) {
@@ -177,13 +182,9 @@ class KotlinMavenImporter : MavenImporter(KOTLIN_PLUGIN_GROUP_ID, KOTLIN_PLUGIN_
private fun getCompilerArgumentsByConfigurationElement(
mavenProject: MavenProject,
configuration: Element?,
platform: TargetPlatformKind<*>
platform: IdePlatform<*, *>
): List<String> {
val arguments = when (platform) {
is TargetPlatformKind.Jvm -> K2JVMCompilerArguments()
TargetPlatformKind.JavaScript -> K2JSCompilerArguments()
TargetPlatformKind.Common -> K2MetadataCompilerArguments()
}
val arguments = platform.createArguments()
arguments.apiVersion = configuration?.getChild("apiVersion")?.text ?:
mavenProject.properties["kotlin.compiler.apiVersion"]?.toString()
@@ -252,11 +253,13 @@ class KotlinMavenImporter : MavenImporter(KOTLIN_PLUGIN_GROUP_ID, KOTLIN_PLUGIN_
false,
ExternalProjectSystemRegistry.MAVEN_EXTERNAL_SOURCE_ID
)
val platform = detectPlatform(mavenProject)
// TODO There should be a way to figure out the correct platform version
val platform = detectPlatform(mavenProject)?.defaultPlatform
kotlinFacet.configureFacet(compilerVersion, LanguageFeature.Coroutines.defaultState, platform, modifiableModelsProvider)
val facetSettings = kotlinFacet.configuration.settings
val configuredPlatform = kotlinFacet.configuration.settings.targetPlatformKind!!
val configuredPlatform = kotlinFacet.configuration.settings.platform!!
val configuration = mavenPlugin.configurationElement
val sharedArguments = getCompilerArgumentsByConfigurationElement(mavenProject, configuration, configuredPlatform)
val executionArguments = mavenPlugin.executions
@@ -277,22 +280,28 @@ class KotlinMavenImporter : MavenImporter(KOTLIN_PLUGIN_GROUP_ID, KOTLIN_PLUGIN_
private fun detectPlatform(mavenProject: MavenProject) =
detectPlatformByExecutions(mavenProject) ?: detectPlatformByLibraries(mavenProject)
private fun detectPlatformByExecutions(mavenProject: MavenProject): TargetPlatformKind<*>? {
private fun detectPlatformByExecutions(mavenProject: MavenProject): IdePlatformKind<*>? {
return mavenProject.findPlugin(KOTLIN_PLUGIN_GROUP_ID, KOTLIN_PLUGIN_ARTIFACT_ID)?.executions?.flatMap { it.goals }
?.mapNotNull { goal ->
when (goal) {
PomFile.KotlinGoals.Compile, PomFile.KotlinGoals.TestCompile -> TargetPlatformKind.Jvm[JvmTarget.JVM_1_6]
PomFile.KotlinGoals.Js, PomFile.KotlinGoals.TestJs -> TargetPlatformKind.JavaScript
PomFile.KotlinGoals.MetaData -> TargetPlatformKind.Common
PomFile.KotlinGoals.Compile, PomFile.KotlinGoals.TestCompile -> JvmIdePlatformKind
PomFile.KotlinGoals.Js, PomFile.KotlinGoals.TestJs -> JsIdePlatformKind
PomFile.KotlinGoals.MetaData -> CommonIdePlatformKind
else -> null
}
}?.distinct()?.singleOrNull()
}
private fun detectPlatformByLibraries(mavenProject: MavenProject): TargetPlatformKind<*>? {
return TargetPlatformKind.ALL_PLATFORMS.firstOrNull {
it.mavenLibraryIds.any { mavenProject.findDependencies(KOTLIN_PLUGIN_GROUP_ID, it).isNotEmpty() }
private fun detectPlatformByLibraries(mavenProject: MavenProject): IdePlatformKind<*>? {
for (kind in IdePlatformKind.ALL_KINDS) {
val mavenLibraryIds = kind.tooling.mavenLibraryIds
if (mavenLibraryIds.any { mavenProject.findDependencies(KOTLIN_PLUGIN_GROUP_ID, it).isNotEmpty() }) {
// TODO we could return here the correct version
return kind
}
}
return null
}
// TODO in theory it should work like this but it doesn't as it couldn't unmark source roots that are not roots anymore.
@@ -362,12 +371,12 @@ class KotlinMavenImporter : MavenImporter(KOTLIN_PLUGIN_GROUP_ID, KOTLIN_PLUGIN_
}.distinct()
private fun setImplementedModuleName(kotlinFacet: KotlinFacet, mavenProject: MavenProject, module: Module) {
if (kotlinFacet.configuration.settings.targetPlatformKind == TargetPlatformKind.Common) {
if (kotlinFacet.configuration.settings.platform.isCommon) {
kotlinFacet.configuration.settings.implementedModuleNames = emptyList()
} else {
val manager = MavenProjectsManager.getInstance(module.project)
val mavenDependencies = mavenProject.dependencies.mapNotNull { manager?.findProject(it) }
val implemented = mavenDependencies.filter { detectPlatformByExecutions(it) == TargetPlatformKind.Common }
val implemented = mavenDependencies.filter { detectPlatformByExecutions(it).isCommon }
kotlinFacet.configuration.settings.implementedModuleNames = implemented.map { manager.findModule(it)?.name ?: it.displayName }
}
@@ -31,7 +31,7 @@ import org.jetbrains.idea.maven.project.MavenProject
import org.jetbrains.idea.maven.project.MavenProjectsManager
import org.jetbrains.kotlin.idea.maven.PomFile
import org.jetbrains.kotlin.idea.maven.configuration.KotlinMavenConfigurator
import org.jetbrains.kotlin.idea.versions.MAVEN_STDLIB_ID
import org.jetbrains.kotlin.utils.PathUtil
class DifferentMavenStdlibVersionInspection : DomElementsInspection<MavenDomProjectModel>(MavenDomProjectModel::class.java) {
override fun checkFileElement(domFileElement: DomFileElement<MavenDomProjectModel>?, holder: DomElementAnnotationHolder?) {
@@ -44,7 +44,7 @@ class DifferentMavenStdlibVersionInspection : DomElementsInspection<MavenDomProj
val manager = MavenProjectsManager.getInstance(module.project) ?: return
val project = manager.findProject(module) ?: return
val stdlibVersion = project.findDependencies(KotlinMavenConfigurator.GROUP_ID, MAVEN_STDLIB_ID).map { it.version }.distinct()
val stdlibVersion = project.findDependencies(KotlinMavenConfigurator.GROUP_ID, PathUtil.KOTLIN_JAVA_STDLIB_NAME).map { it.version }.distinct()
val pluginVersion = project.findPlugin(KotlinMavenConfigurator.GROUP_ID, KotlinMavenConfigurator.MAVEN_PLUGIN_ID)?.version
if (pluginVersion == null || stdlibVersion.isEmpty() || stdlibVersion.singleOrNull() == pluginVersion) {
@@ -65,7 +65,7 @@ class DifferentMavenStdlibVersionInspection : DomElementsInspection<MavenDomProj
)
}
pomFile.findDependencies(MavenId(KotlinMavenConfigurator.GROUP_ID, MAVEN_STDLIB_ID, null))
pomFile.findDependencies(MavenId(KotlinMavenConfigurator.GROUP_ID, PathUtil.KOTLIN_JAVA_STDLIB_NAME, null))
.filter { it.version.stringValue != pluginVersion }
.forEach { dependency ->
val fixes = dependency.version.stringValue?.let { version ->
@@ -38,19 +38,15 @@ import org.jetbrains.idea.maven.project.MavenProjectsManager
import org.jetbrains.idea.maven.utils.MavenArtifactScope
import org.jetbrains.kotlin.idea.maven.PomFile
import org.jetbrains.kotlin.idea.maven.configuration.KotlinMavenConfigurator
import org.jetbrains.kotlin.idea.platform.tooling
import org.jetbrains.kotlin.idea.versions.*
import org.jetbrains.kotlin.platform.impl.JvmIdePlatformKind
import java.util.*
class KotlinMavenPluginPhaseInspection : DomElementsInspection<MavenDomProjectModel>(MavenDomProjectModel::class.java) {
companion object {
private val STDLIB_MAVEN_ID = MavenId(KotlinMavenConfigurator.GROUP_ID, MAVEN_STDLIB_ID, null)
private val STDLIB_JRE7_MAVEN_ID = MavenId(KotlinMavenConfigurator.GROUP_ID, MAVEN_STDLIB_ID_JRE7, null)
private val STDLIB_JDK7_MAVEN_ID = MavenId(KotlinMavenConfigurator.GROUP_ID, MAVEN_STDLIB_ID_JDK7, null)
private val STDLIB_JRE8_MAVEN_ID = MavenId(KotlinMavenConfigurator.GROUP_ID, MAVEN_STDLIB_ID_JRE8, null)
private val STDLIB_JDK8_MAVEN_ID = MavenId(KotlinMavenConfigurator.GROUP_ID, MAVEN_STDLIB_ID_JDK8, null)
private val JVM_STDLIB_IDS =
listOf(STDLIB_MAVEN_ID, STDLIB_JRE7_MAVEN_ID, STDLIB_JDK7_MAVEN_ID, STDLIB_JRE8_MAVEN_ID, STDLIB_JDK8_MAVEN_ID)
private val JVM_STDLIB_IDS = JvmIdePlatformKind.tooling
.mavenLibraryIds.map { MavenId(KotlinMavenConfigurator.GROUP_ID, it, null) }
private val JS_STDLIB_MAVEN_ID = MavenId(KotlinMavenConfigurator.GROUP_ID, MAVEN_JS_STDLIB_ID, null)
}
@@ -42,6 +42,7 @@ import org.jetbrains.kotlin.idea.framework.KotlinSdkType
import org.jetbrains.kotlin.idea.project.languageVersionSettings
import org.jetbrains.kotlin.idea.refactoring.toPsiFile
import org.jetbrains.kotlin.js.resolve.JsPlatform
import org.jetbrains.kotlin.platform.impl.*
import org.jetbrains.kotlin.psi.KtFile
import org.jetbrains.kotlin.resolve.TargetPlatform
import org.jetbrains.kotlin.resolve.jvm.platform.JvmPlatform
@@ -491,7 +492,7 @@ class KotlinMavenImporterTest : MavenImportingTestCase() {
Assert.assertFalse(compilerArguments!!.autoAdvanceApiVersion)
Assert.assertEquals(true, compilerArguments!!.suppressWarnings)
Assert.assertEquals(LanguageFeature.State.ENABLED, coroutineSupport)
Assert.assertEquals("JVM 1.8", targetPlatformKind!!.description)
Assert.assertEquals("JVM 1.8", platform!!.description)
Assert.assertEquals("1.8", (compilerArguments as K2JVMCompilerArguments).jvmTarget)
Assert.assertEquals("foobar.jar", (compilerArguments as K2JVMCompilerArguments).classpath)
Assert.assertEquals(
@@ -612,7 +613,7 @@ class KotlinMavenImporterTest : MavenImportingTestCase() {
Assert.assertEquals("1.0", compilerArguments!!.languageVersion)
Assert.assertEquals("1.0", apiLevel!!.versionString)
Assert.assertEquals("1.0", compilerArguments!!.apiVersion)
Assert.assertEquals("JVM 1.8", targetPlatformKind!!.description)
Assert.assertEquals("JVM 1.8", platform!!.description)
Assert.assertEquals("1.8", (compilerArguments as K2JVMCompilerArguments).jvmTarget)
}
@@ -687,7 +688,7 @@ class KotlinMavenImporterTest : MavenImportingTestCase() {
Assert.assertFalse(compilerArguments!!.autoAdvanceApiVersion)
Assert.assertEquals(true, compilerArguments!!.suppressWarnings)
Assert.assertEquals(LanguageFeature.State.ENABLED, coroutineSupport)
Assert.assertTrue(targetPlatformKind == TargetPlatformKind.JavaScript)
Assert.assertTrue(platform.isJavaScript)
with(compilerArguments as K2JSCompilerArguments) {
Assert.assertEquals(true, sourceMap)
Assert.assertEquals("commonjs", moduleKind)
@@ -842,7 +843,7 @@ class KotlinMavenImporterTest : MavenImportingTestCase() {
Assert.assertEquals("1.0", compilerArguments!!.apiVersion)
Assert.assertEquals(true, compilerArguments!!.suppressWarnings)
Assert.assertEquals(LanguageFeature.State.ENABLED, coroutineSupport)
Assert.assertEquals("JVM 1.8", targetPlatformKind!!.description)
Assert.assertEquals("JVM 1.8", platform!!.description)
Assert.assertEquals("1.8", (compilerArguments as K2JVMCompilerArguments).jvmTarget)
Assert.assertEquals("foobar.jar", (compilerArguments as K2JVMCompilerArguments).classpath)
Assert.assertEquals("-Xmulti-platform", compilerSettings!!.additionalArguments)
@@ -902,7 +903,7 @@ class KotlinMavenImporterTest : MavenImportingTestCase() {
assertImporterStatePresent()
with(facetSettings) {
Assert.assertEquals("JVM 1.8", targetPlatformKind!!.description)
Assert.assertEquals("JVM 1.8", platform!!.description)
Assert.assertEquals("1.8", (compilerArguments as K2JVMCompilerArguments).jvmTarget)
Assert.assertEquals(LanguageFeature.State.ENABLED, coroutineSupport)
Assert.assertEquals("c:/program files/jdk1.8", (compilerArguments as K2JVMCompilerArguments).classpath)
@@ -958,7 +959,7 @@ class KotlinMavenImporterTest : MavenImportingTestCase() {
assertImporterStatePresent()
with(facetSettings) {
Assert.assertEquals("JVM 1.8", targetPlatformKind!!.description)
Assert.assertEquals("JVM 1.8", platform!!.description)
Assert.assertEquals("1.8", (compilerArguments as K2JVMCompilerArguments).jvmTarget)
Assert.assertEquals(LanguageFeature.State.ENABLED, coroutineSupport)
Assert.assertEquals("c:/program files/jdk1.8", (compilerArguments as K2JVMCompilerArguments).classpath)
@@ -1012,7 +1013,7 @@ class KotlinMavenImporterTest : MavenImportingTestCase() {
assertModules("project")
assertImporterStatePresent()
Assert.assertEquals(TargetPlatformKind.Jvm[JvmTarget.JVM_1_6], facetSettings.targetPlatformKind)
Assert.assertEquals(JvmIdePlatformKind.Platform(JvmTarget.JVM_1_6), facetSettings.platform)
assertContentFolders("project", JavaSourceRootType.SOURCE, "src/main/kotlin")
assertContentFolders("project", JavaSourceRootType.TEST_SOURCE, "src/test/java")
@@ -1067,7 +1068,7 @@ class KotlinMavenImporterTest : MavenImportingTestCase() {
assertModules("project")
assertImporterStatePresent()
Assert.assertEquals(TargetPlatformKind.Jvm[JvmTarget.JVM_1_6], facetSettings.targetPlatformKind)
Assert.assertEquals(JvmIdePlatformKind.Platform(JvmTarget.JVM_1_6), facetSettings.platform)
}
fun testJvmDetectionByGoalWithCommonStdlib() {
@@ -1117,7 +1118,7 @@ class KotlinMavenImporterTest : MavenImportingTestCase() {
assertModules("project")
assertImporterStatePresent()
Assert.assertEquals(TargetPlatformKind.Jvm[JvmTarget.JVM_1_6], facetSettings.targetPlatformKind)
Assert.assertEquals(JvmIdePlatformKind.Platform(JvmTarget.JVM_1_6), facetSettings.platform)
assertContentFolders("project", JavaSourceRootType.SOURCE, "src/main/kotlin")
assertContentFolders("project", JavaSourceRootType.TEST_SOURCE, "src/test/java")
@@ -1172,7 +1173,7 @@ class KotlinMavenImporterTest : MavenImportingTestCase() {
assertModules("project")
assertImporterStatePresent()
Assert.assertEquals(TargetPlatformKind.JavaScript, facetSettings.targetPlatformKind)
Assert.assertTrue(facetSettings.platform.isJavaScript)
Assert.assertTrue(ModuleRootManager.getInstance(getModule("project")).sdk!!.sdkType is KotlinSdkType)
@@ -1229,7 +1230,7 @@ class KotlinMavenImporterTest : MavenImportingTestCase() {
assertModules("project")
assertImporterStatePresent()
Assert.assertEquals(TargetPlatformKind.JavaScript, facetSettings.targetPlatformKind)
Assert.assertTrue(facetSettings.platform.isJavaScript)
Assert.assertTrue(ModuleRootManager.getInstance(getModule("project")).sdk!!.sdkType is KotlinSdkType)
@@ -1286,7 +1287,7 @@ class KotlinMavenImporterTest : MavenImportingTestCase() {
assertModules("project")
assertImporterStatePresent()
Assert.assertEquals(TargetPlatformKind.JavaScript, facetSettings.targetPlatformKind)
Assert.assertTrue(facetSettings.platform.isJavaScript)
Assert.assertTrue(ModuleRootManager.getInstance(getModule("project")).sdk!!.sdkType is KotlinSdkType)
@@ -1348,7 +1349,7 @@ class KotlinMavenImporterTest : MavenImportingTestCase() {
assertModules("project")
assertImporterStatePresent()
Assert.assertEquals(TargetPlatformKind.JavaScript, facetSettings.targetPlatformKind)
Assert.assertTrue(facetSettings.platform.isJavaScript)
val rootManager = ModuleRootManager.getInstance(getModule("project"))
val libraries = rootManager.orderEntries.filterIsInstance<LibraryOrderEntry>().map { it.library as LibraryEx }
@@ -1402,7 +1403,7 @@ class KotlinMavenImporterTest : MavenImportingTestCase() {
assertModules("project")
assertImporterStatePresent()
Assert.assertEquals(TargetPlatformKind.Common, facetSettings.targetPlatformKind)
Assert.assertTrue(facetSettings.platform.isCommon)
Assert.assertTrue(ModuleRootManager.getInstance(getModule("project")).sdk!!.sdkType is KotlinSdkType)
@@ -1453,7 +1454,7 @@ class KotlinMavenImporterTest : MavenImportingTestCase() {
assertModules("project")
assertImporterStatePresent()
Assert.assertEquals(TargetPlatformKind.Common, facetSettings.targetPlatformKind)
Assert.assertTrue(facetSettings.platform.isCommon)
Assert.assertTrue(ModuleRootManager.getInstance(getModule("project")).sdk!!.sdkType is KotlinSdkType)
@@ -1504,7 +1505,7 @@ class KotlinMavenImporterTest : MavenImportingTestCase() {
assertModules("project")
assertImporterStatePresent()
Assert.assertEquals(TargetPlatformKind.Common, facetSettings.targetPlatformKind)
Assert.assertTrue(facetSettings.platform.isCommon)
val rootManager = ModuleRootManager.getInstance(getModule("project"))
val stdlib = rootManager.orderEntries.filterIsInstance<LibraryOrderEntry>().single().library
@@ -1565,7 +1566,7 @@ class KotlinMavenImporterTest : MavenImportingTestCase() {
assertModules("project")
assertImporterStatePresent()
Assert.assertEquals(TargetPlatformKind.Jvm[JvmTarget.JVM_1_6], facetSettings.targetPlatformKind)
Assert.assertEquals(JvmIdePlatformKind.Platform(JvmTarget.JVM_1_6), facetSettings.platform)
assertContentFolders("project", KotlinSourceRootType.Source, "src/main/kotlin")
assertContentFolders("project", KotlinSourceRootType.TestSource, "src/test/java")
@@ -1620,7 +1621,7 @@ class KotlinMavenImporterTest : MavenImportingTestCase() {
assertModules("project")
assertImporterStatePresent()
Assert.assertEquals(TargetPlatformKind.JavaScript, facetSettings.targetPlatformKind)
Assert.assertTrue(facetSettings.platform.isJavaScript)
assertContentFolders("project", KotlinSourceRootType.Source, "src/main/kotlin")
assertContentFolders("project", KotlinSourceRootType.TestSource, "src/test/java")
@@ -1675,7 +1676,7 @@ class KotlinMavenImporterTest : MavenImportingTestCase() {
assertModules("project")
assertImporterStatePresent()
Assert.assertEquals(TargetPlatformKind.Common, facetSettings.targetPlatformKind)
Assert.assertTrue(facetSettings.platform.isCommon)
assertContentFolders("project", KotlinSourceRootType.Source, "src/main/kotlin")
assertContentFolders("project", KotlinSourceRootType.TestSource, "src/test/java")
@@ -1889,7 +1890,7 @@ class KotlinMavenImporterTest : MavenImportingTestCase() {
assertImporterStatePresent()
with(facetSettings) {
Assert.assertEquals("JVM 1.8", targetPlatformKind!!.description)
Assert.assertEquals("JVM 1.8", platform!!.description)
Assert.assertEquals("1.1", languageLevel!!.description)
Assert.assertEquals("1.1", apiLevel!!.description)
Assert.assertEquals("1.8", (compilerArguments as K2JVMCompilerArguments).jvmTarget)
@@ -2112,7 +2113,7 @@ class KotlinMavenImporterTest : MavenImportingTestCase() {
assertImporterStatePresent()
with(facetSettings("myModule1")) {
Assert.assertEquals("JVM 1.8", targetPlatformKind!!.description)
Assert.assertEquals("JVM 1.8", platform!!.description)
Assert.assertEquals("1.1", languageLevel!!.description)
Assert.assertEquals("1.0", apiLevel!!.description)
Assert.assertEquals("1.8", (compilerArguments as K2JVMCompilerArguments).jvmTarget)
@@ -2123,7 +2124,7 @@ class KotlinMavenImporterTest : MavenImportingTestCase() {
}
with(facetSettings("myModule2")) {
Assert.assertEquals("JVM 1.8", targetPlatformKind!!.description)
Assert.assertEquals("JVM 1.8", platform!!.description)
Assert.assertEquals("1.1", languageLevel!!.description)
Assert.assertEquals("1.0", apiLevel!!.description)
Assert.assertEquals("1.8", (compilerArguments as K2JVMCompilerArguments).jvmTarget)
@@ -2134,7 +2135,7 @@ class KotlinMavenImporterTest : MavenImportingTestCase() {
}
with(facetSettings("myModule3")) {
Assert.assertEquals("JVM 1.8", targetPlatformKind!!.description)
Assert.assertEquals("JVM 1.8", platform!!.description)
Assert.assertEquals(LanguageVersion.LATEST_STABLE, languageLevel)
Assert.assertEquals(LanguageVersion.LATEST_STABLE, apiLevel)
Assert.assertEquals("1.8", (compilerArguments as K2JVMCompilerArguments).jvmTarget)
@@ -2373,20 +2374,20 @@ class KotlinMavenImporterTest : MavenImportingTestCase() {
assertImporterStatePresent()
with(facetSettings("my-common-module1")) {
Assert.assertEquals(TargetPlatformKind.Common.description, targetPlatformKind!!.description)
Assert.assertEquals(CommonIdePlatformKind.Platform.description, platform!!.description)
}
with(facetSettings("my-common-module2")) {
Assert.assertEquals(TargetPlatformKind.Common.description, targetPlatformKind!!.description)
Assert.assertEquals(CommonIdePlatformKind.Platform.description, platform!!.description)
}
with(facetSettings("my-jvm-module")) {
Assert.assertEquals(TargetPlatformKind.Jvm(JvmTarget.JVM_1_6).description, targetPlatformKind!!.description)
Assert.assertEquals(JvmIdePlatformKind.Platform(JvmTarget.JVM_1_6).description, platform!!.description)
Assert.assertEquals(listOf("my-common-module1", "my-common-module2"), implementedModuleNames)
}
with(facetSettings("my-js-module")) {
Assert.assertEquals(TargetPlatformKind.JavaScript.description, targetPlatformKind!!.description)
Assert.assertEquals(JsIdePlatformKind.Platform.description, platform!!.description)
Assert.assertEquals(listOf("my-common-module1"), implementedModuleNames)
}
}