Kotlin Facet: Fix platform detection in android-gradle projects
Sort candidate library names by descending length. Suppress common library if platform-specific one is also present #KT-16827 Fixed
This commit is contained in:
+4
-1
@@ -44,7 +44,10 @@ class PlatformAndroidGradleDetector : KotlinPlatformGradleDetector {
|
|||||||
.flatMap { it.data.jarLibraryDependencies.asSequence() }
|
.flatMap { it.data.jarLibraryDependencies.asSequence() }
|
||||||
.forEach {
|
.forEach {
|
||||||
val libraryName = it.name
|
val libraryName = it.name
|
||||||
if (libraryName.substringBeforeLast("-") in libraryIds) return libraryName.substringAfterLast("-")
|
for (libraryId in libraryIds) {
|
||||||
|
val prefix = "$libraryId-"
|
||||||
|
if (libraryName.startsWith(prefix)) return libraryName.substringAfter(prefix)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
|
|||||||
+2
-1
@@ -99,7 +99,8 @@ private fun detectPlatformByPlugin(moduleNode: DataNode<ModuleData>): TargetPlat
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun detectPlatformByLibrary(moduleNode: DataNode<ModuleData>): TargetPlatformKind<*>? {
|
private fun detectPlatformByLibrary(moduleNode: DataNode<ModuleData>): TargetPlatformKind<*>? {
|
||||||
return TargetPlatformKind.ALL_PLATFORMS.firstOrNull { moduleNode.getResolvedKotlinStdlibVersionByModuleData(it.mavenLibraryIds) != null }
|
val detectedPlatforms = mavenLibraryIdToPlatform.entries.filter { moduleNode.getResolvedKotlinStdlibVersionByModuleData(listOf(it.key)) != null }.map { it.value }.distinct()
|
||||||
|
return detectedPlatforms.singleOrNull() ?: detectedPlatforms.firstOrNull { it != TargetPlatformKind.Common }
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun configureFacetByGradleModule(
|
private fun configureFacetByGradleModule(
|
||||||
|
|||||||
@@ -101,6 +101,13 @@ val TargetPlatformKind<*>.mavenLibraryIds: List<String>
|
|||||||
is TargetPlatformKind.Common -> listOf(MAVEN_COMMON_STDLIB_ID)
|
is TargetPlatformKind.Common -> listOf(MAVEN_COMMON_STDLIB_ID)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
val mavenLibraryIdToPlatform: Map<String, TargetPlatformKind<*>> by lazy {
|
||||||
|
TargetPlatformKind.ALL_PLATFORMS
|
||||||
|
.flatMap { platform -> platform.mavenLibraryIds.map { it to platform } }
|
||||||
|
.sortedByDescending { it.first.length }
|
||||||
|
.toMap()
|
||||||
|
}
|
||||||
|
|
||||||
fun Module.getOrCreateFacet(modelsProvider: IdeModifiableModelsProvider, useProjectSettings: Boolean): KotlinFacet {
|
fun Module.getOrCreateFacet(modelsProvider: IdeModifiableModelsProvider, useProjectSettings: Boolean): KotlinFacet {
|
||||||
val facetModel = modelsProvider.getModifiableFacetModel(this)
|
val facetModel = modelsProvider.getModifiableFacetModel(this)
|
||||||
|
|
||||||
|
|||||||
+2
-2
@@ -91,12 +91,12 @@ class GradleFacetImportTest_3_3 : GradleImportingTestCase() {
|
|||||||
repositories {
|
repositories {
|
||||||
mavenCentral()
|
mavenCentral()
|
||||||
maven {
|
maven {
|
||||||
url 'http://dl.bintray.com/kotlin/kotlin-eap-1.1'
|
url 'http://dl.bintray.com/kotlin/kotlin-dev'
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:1.1.0")
|
classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:1.1.2-eap-44")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user