Import Android modules only if Android Plugin for IDEA is missing
This commit is contained in:
+16
-7
@@ -7,6 +7,8 @@ package org.jetbrains.kotlin.idea.configuration
|
|||||||
|
|
||||||
import com.google.common.graph.GraphBuilder
|
import com.google.common.graph.GraphBuilder
|
||||||
import com.google.common.graph.Graphs
|
import com.google.common.graph.Graphs
|
||||||
|
import com.intellij.ide.plugins.PluginManager
|
||||||
|
import com.intellij.openapi.extensions.PluginId
|
||||||
import com.intellij.openapi.externalSystem.model.DataNode
|
import com.intellij.openapi.externalSystem.model.DataNode
|
||||||
import com.intellij.openapi.externalSystem.model.ProjectKeys
|
import com.intellij.openapi.externalSystem.model.ProjectKeys
|
||||||
import com.intellij.openapi.externalSystem.model.project.*
|
import com.intellij.openapi.externalSystem.model.project.*
|
||||||
@@ -34,7 +36,6 @@ import org.jetbrains.kotlin.config.ExternalSystemTestTask
|
|||||||
import org.jetbrains.kotlin.config.LanguageFeature
|
import org.jetbrains.kotlin.config.LanguageFeature
|
||||||
import org.jetbrains.kotlin.gradle.*
|
import org.jetbrains.kotlin.gradle.*
|
||||||
import org.jetbrains.kotlin.idea.configuration.GradlePropertiesFileFacade.Companion.KOTLIN_NOT_IMPORTED_COMMON_SOURCE_SETS_SETTING
|
import org.jetbrains.kotlin.idea.configuration.GradlePropertiesFileFacade.Companion.KOTLIN_NOT_IMPORTED_COMMON_SOURCE_SETS_SETTING
|
||||||
import org.jetbrains.kotlin.idea.configuration.KotlinMPPGradleProjectResolver.Companion.fullName
|
|
||||||
import org.jetbrains.kotlin.idea.platform.IdePlatformKindTooling
|
import org.jetbrains.kotlin.idea.platform.IdePlatformKindTooling
|
||||||
import org.jetbrains.kotlin.util.removeSuffixIfPresent
|
import org.jetbrains.kotlin.util.removeSuffixIfPresent
|
||||||
import org.jetbrains.kotlin.utils.addToStdlib.firstNotNullResult
|
import org.jetbrains.kotlin.utils.addToStdlib.firstNotNullResult
|
||||||
@@ -64,6 +65,10 @@ open class KotlinMPPGradleProjectResolver : AbstractProjectResolverExtension() {
|
|||||||
return setOf(KotlinMPPGradleModel::class.java)
|
return setOf(KotlinMPPGradleModel::class.java)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun getExtraCommandLineArgs(): List<String> {
|
||||||
|
return if (!androidPluginPresent) listOf("-Pkotlin.include.android.dependencies=true") else emptyList()
|
||||||
|
}
|
||||||
|
|
||||||
override fun createModule(gradleModule: IdeaModule, projectDataNode: DataNode<ProjectData>): DataNode<ModuleData> {
|
override fun createModule(gradleModule: IdeaModule, projectDataNode: DataNode<ProjectData>): DataNode<ModuleData> {
|
||||||
return super.createModule(gradleModule, projectDataNode).also {
|
return super.createModule(gradleModule, projectDataNode).also {
|
||||||
initializeModuleData(gradleModule, it, projectDataNode, resolverCtx)
|
initializeModuleData(gradleModule, it, projectDataNode, resolverCtx)
|
||||||
@@ -225,6 +230,7 @@ open class KotlinMPPGradleProjectResolver : AbstractProjectResolverExtension() {
|
|||||||
val proxyObjectCloningCache = WeakHashMap<Any, Any>()
|
val proxyObjectCloningCache = WeakHashMap<Any, Any>()
|
||||||
|
|
||||||
private var nativeDebugAdvertised = false
|
private var nativeDebugAdvertised = false
|
||||||
|
private val androidPluginPresent = PluginManager.getPlugin(PluginId.findId("org.jetbrains.android"))?.isEnabled ?: false
|
||||||
|
|
||||||
fun initializeModuleData(
|
fun initializeModuleData(
|
||||||
gradleModule: IdeaModule,
|
gradleModule: IdeaModule,
|
||||||
@@ -276,7 +282,7 @@ open class KotlinMPPGradleProjectResolver : AbstractProjectResolverExtension() {
|
|||||||
|
|
||||||
val sourceSetToCompilationData = LinkedHashMap<KotlinSourceSet, MutableSet<GradleSourceSetData>>()
|
val sourceSetToCompilationData = LinkedHashMap<KotlinSourceSet, MutableSet<GradleSourceSetData>>()
|
||||||
for (target in mppModel.targets) {
|
for (target in mppModel.targets) {
|
||||||
// if (target.platform == KotlinPlatform.ANDROID) continue
|
if (androidPluginPresent && target.platform == KotlinPlatform.ANDROID) continue
|
||||||
if (target.name == KotlinTarget.METADATA_TARGET_NAME) continue
|
if (target.name == KotlinTarget.METADATA_TARGET_NAME) continue
|
||||||
val targetData = KotlinTargetData(target.name).also {
|
val targetData = KotlinTargetData(target.name).also {
|
||||||
it.archiveFile = target.jar?.archiveFile
|
it.archiveFile = target.jar?.archiveFile
|
||||||
@@ -350,7 +356,7 @@ open class KotlinMPPGradleProjectResolver : AbstractProjectResolverExtension() {
|
|||||||
|
|
||||||
val ignoreCommonSourceSets by lazy { externalProject.notImportedCommonSourceSets() }
|
val ignoreCommonSourceSets by lazy { externalProject.notImportedCommonSourceSets() }
|
||||||
for (sourceSet in mppModel.sourceSets.values) {
|
for (sourceSet in mppModel.sourceSets.values) {
|
||||||
// if (sourceSet.actualPlatforms.platforms.singleOrNull() == KotlinPlatform.ANDROID) continue
|
if (androidPluginPresent && sourceSet.actualPlatforms.platforms.singleOrNull() == KotlinPlatform.ANDROID) continue
|
||||||
if (sourceSet.actualPlatforms.supports(KotlinPlatform.COMMON) && ignoreCommonSourceSets) continue
|
if (sourceSet.actualPlatforms.supports(KotlinPlatform.COMMON) && ignoreCommonSourceSets) continue
|
||||||
val moduleId = getKotlinModuleId(gradleModule, sourceSet, resolverCtx)
|
val moduleId = getKotlinModuleId(gradleModule, sourceSet, resolverCtx)
|
||||||
val existingSourceSetDataNode = sourceSetMap[moduleId]?.first
|
val existingSourceSetDataNode = sourceSetMap[moduleId]?.first
|
||||||
@@ -448,7 +454,10 @@ open class KotlinMPPGradleProjectResolver : AbstractProjectResolverExtension() {
|
|||||||
.toMap()
|
.toMap()
|
||||||
if (resolverCtx.getExtraProject(gradleModule, ExternalProject::class.java) == null) return
|
if (resolverCtx.getExtraProject(gradleModule, ExternalProject::class.java) == null) return
|
||||||
processSourceSets(gradleModule, mppModel, ideModule, resolverCtx) { dataNode, sourceSet ->
|
processSourceSets(gradleModule, mppModel, ideModule, resolverCtx) { dataNode, sourceSet ->
|
||||||
if (dataNode == null /*|| sourceSet.actualPlatforms.platforms.singleOrNull() == KotlinPlatform.ANDROID*/) return@processSourceSets
|
if (dataNode == null || androidPluginPresent &&
|
||||||
|
sourceSet.actualPlatforms.platforms.singleOrNull() == KotlinPlatform.ANDROID
|
||||||
|
) return@processSourceSets
|
||||||
|
|
||||||
createContentRootData(
|
createContentRootData(
|
||||||
sourceSet.sourceDirs,
|
sourceSet.sourceDirs,
|
||||||
sourceSet.sourceType,
|
sourceSet.sourceType,
|
||||||
@@ -558,7 +567,7 @@ open class KotlinMPPGradleProjectResolver : AbstractProjectResolverExtension() {
|
|||||||
}
|
}
|
||||||
val closedSourceSetGraph = Graphs.transitiveClosure(sourceSetGraph)
|
val closedSourceSetGraph = Graphs.transitiveClosure(sourceSetGraph)
|
||||||
for (sourceSet in closedSourceSetGraph.nodes()) {
|
for (sourceSet in closedSourceSetGraph.nodes()) {
|
||||||
val isAndroid = false //sourceSet.actualPlatforms.platforms.singleOrNull() == KotlinPlatform.ANDROID
|
val isAndroid = androidPluginPresent && sourceSet.actualPlatforms.platforms.singleOrNull() == KotlinPlatform.ANDROID
|
||||||
val fromDataNode = if (isAndroid) {
|
val fromDataNode = if (isAndroid) {
|
||||||
ideModule
|
ideModule
|
||||||
} else {
|
} else {
|
||||||
@@ -578,7 +587,7 @@ open class KotlinMPPGradleProjectResolver : AbstractProjectResolverExtension() {
|
|||||||
sourceSetInfo.addSourceSets(dependeeSourceSets, selfName, gradleModule, resolverCtx)
|
sourceSetInfo.addSourceSets(dependeeSourceSets, selfName, gradleModule, resolverCtx)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// if (sourceSet.actualPlatforms.platforms.singleOrNull() == KotlinPlatform.ANDROID) continue
|
if (androidPluginPresent && sourceSet.actualPlatforms.platforms.singleOrNull() == KotlinPlatform.ANDROID) continue
|
||||||
for (dependeeSourceSet in dependeeSourceSets) {
|
for (dependeeSourceSet in dependeeSourceSets) {
|
||||||
val toDataNode = getSiblingKotlinModuleData(dependeeSourceSet, gradleModule, ideModule, resolverCtx) ?: continue
|
val toDataNode = getSiblingKotlinModuleData(dependeeSourceSet, gradleModule, ideModule, resolverCtx) ?: continue
|
||||||
addDependency(fromDataNode, toDataNode, dependeeSourceSet.isTestModule)
|
addDependency(fromDataNode, toDataNode, dependeeSourceSet.isTestModule)
|
||||||
@@ -747,7 +756,7 @@ open class KotlinMPPGradleProjectResolver : AbstractProjectResolverExtension() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
for (target in mppModel.targets) {
|
for (target in mppModel.targets) {
|
||||||
// if (target.platform == KotlinPlatform.ANDROID) continue
|
if (androidPluginPresent && target.platform == KotlinPlatform.ANDROID) continue
|
||||||
for (compilation in target.compilations) {
|
for (compilation in target.compilations) {
|
||||||
val moduleId = getKotlinModuleId(gradleModule, compilation, resolverCtx)
|
val moduleId = getKotlinModuleId(gradleModule, compilation, resolverCtx)
|
||||||
val moduleDataNode = sourceSetsMap[moduleId] ?: continue
|
val moduleDataNode = sourceSetsMap[moduleId] ?: continue
|
||||||
|
|||||||
@@ -140,10 +140,7 @@ class KotlinMPPGradleModelBuilder : ModelBuilderService {
|
|||||||
@Suppress("UNCHECKED_CAST")
|
@Suppress("UNCHECKED_CAST")
|
||||||
val sourceSets =
|
val sourceSets =
|
||||||
(getSourceSets(kotlinExt) as? NamedDomainObjectContainer<Named>)?.asMap?.values ?: emptyList<Named>()
|
(getSourceSets(kotlinExt) as? NamedDomainObjectContainer<Named>)?.asMap?.values ?: emptyList<Named>()
|
||||||
|
val androidDeps = buildAndroidDeps(kotlinExt, project)
|
||||||
val getAndroidSourceSetDependencies = kotlinExt.javaClass.getMethodOrNull("getAndroidSourceSetDependencies", Project::class.java)
|
|
||||||
@Suppress("UNCHECKED_CAST") val androidDeps =
|
|
||||||
getAndroidSourceSetDependencies?.let { it(kotlinExt, project) } as Map<String, List<File>>?
|
|
||||||
|
|
||||||
// Some performance optimisation: do not build metadata dependencies if source set is not common
|
// Some performance optimisation: do not build metadata dependencies if source set is not common
|
||||||
val doBuildMetadataDependencies =
|
val doBuildMetadataDependencies =
|
||||||
@@ -173,6 +170,18 @@ class KotlinMPPGradleModelBuilder : ModelBuilderService {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun buildAndroidDeps(kotlinExt: Any, project: Project): Map<String, List<File>>? {
|
||||||
|
val includeAndroidDeps = project.properties["kotlin.include.android.dependencies"]?.toString()?.toBoolean() == true
|
||||||
|
if (includeAndroidDeps) {
|
||||||
|
val getAndroidSourceSetDependencies =
|
||||||
|
kotlinExt.javaClass.getMethodOrNull("getAndroidSourceSetDependencies", Project::class.java)
|
||||||
|
@Suppress("UNCHECKED_CAST")
|
||||||
|
return getAndroidSourceSetDependencies?.let { it(kotlinExt, project) } as Map<String, List<File>>?
|
||||||
|
} else {
|
||||||
|
return emptyMap()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private fun buildSourceSet(
|
private fun buildSourceSet(
|
||||||
gradleSourceSet: Named,
|
gradleSourceSet: Named,
|
||||||
dependencyResolver: DependencyResolver,
|
dependencyResolver: DependencyResolver,
|
||||||
|
|||||||
Reference in New Issue
Block a user