Check bad root presence before checking platform (KT-30442)
Detect platform based on libraries content is a long operation and should not be called from `isConversionNeeded`. Do other checks before it.
This commit is contained in:
+13
-10
@@ -45,10 +45,10 @@ import org.jetbrains.kotlin.utils.PathUtil
|
|||||||
class KotlinNonJvmSourceRootConverterProvider : ConverterProvider("kotlin-non-jvm-source-roots") {
|
class KotlinNonJvmSourceRootConverterProvider : ConverterProvider("kotlin-non-jvm-source-roots") {
|
||||||
companion object {
|
companion object {
|
||||||
private val rootTypesToMigrate: List<JpsModuleSourceRootType<*>> = listOf(
|
private val rootTypesToMigrate: List<JpsModuleSourceRootType<*>> = listOf(
|
||||||
JavaSourceRootType.SOURCE,
|
JavaSourceRootType.SOURCE,
|
||||||
JavaSourceRootType.TEST_SOURCE,
|
JavaSourceRootType.TEST_SOURCE,
|
||||||
JavaResourceRootType.RESOURCE,
|
JavaResourceRootType.RESOURCE,
|
||||||
JavaResourceRootType.TEST_RESOURCE
|
JavaResourceRootType.TEST_RESOURCE
|
||||||
)
|
)
|
||||||
|
|
||||||
private val TargetPlatform.stdlibDetector: ((Array<VirtualFile>) -> Boolean)?
|
private val TargetPlatform.stdlibDetector: ((Array<VirtualFile>) -> Boolean)?
|
||||||
@@ -166,8 +166,8 @@ class KotlinNonJvmSourceRootConverterProvider : ConverterProvider("kotlin-non-jv
|
|||||||
|
|
||||||
private fun ModuleSettings.detectPlatform(): TargetPlatform {
|
private fun ModuleSettings.detectPlatform(): TargetPlatform {
|
||||||
return detectPlatformByFacet()
|
return detectPlatformByFacet()
|
||||||
?: detectPlatformByDependencies()
|
?: detectPlatformByDependencies()
|
||||||
?: JvmPlatform
|
?: JvmPlatform
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun ModuleSettings.getSourceFolderElements(): List<Element> {
|
private fun ModuleSettings.getSourceFolderElements(): List<Element> {
|
||||||
@@ -188,12 +188,15 @@ class KotlinNonJvmSourceRootConverterProvider : ConverterProvider("kotlin-non-jv
|
|||||||
override fun isConversionNeeded(settings: ModuleSettings): Boolean {
|
override fun isConversionNeeded(settings: ModuleSettings): Boolean {
|
||||||
if (settings.isExternalModule()) return false
|
if (settings.isExternalModule()) return false
|
||||||
|
|
||||||
val targetPlatform = settings.detectPlatform()
|
val hasMigrationRoots = settings.getSourceFolderElements().any {
|
||||||
if (targetPlatform == JvmPlatform) return false
|
|
||||||
|
|
||||||
return settings.getSourceFolderElements().any {
|
|
||||||
JpsModuleRootModelSerializer.loadSourceRoot(it).rootType in rootTypesToMigrate
|
JpsModuleRootModelSerializer.loadSourceRoot(it).rootType in rootTypesToMigrate
|
||||||
}
|
}
|
||||||
|
if (!hasMigrationRoots) {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
val targetPlatform = settings.detectPlatform()
|
||||||
|
return (targetPlatform != JvmPlatform)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun process(settings: ModuleSettings) {
|
override fun process(settings: ModuleSettings) {
|
||||||
|
|||||||
Reference in New Issue
Block a user