[Gradle] Share utils in IdeMetadataDependencyResolvers with IdeJvmAndAndroidSourceDependencyResolver
KT-55112
This commit is contained in:
committed by
Space Team
parent
cda82b47e0
commit
90248f4e44
+2
-6
@@ -15,17 +15,13 @@ import org.jetbrains.kotlin.gradle.plugin.ide.IdeDependencyResolver
|
||||
import org.jetbrains.kotlin.gradle.plugin.ide.IdeaKotlinSourceCoordinates
|
||||
import org.jetbrains.kotlin.gradle.plugin.mpp.MetadataDependencyResolution
|
||||
import org.jetbrains.kotlin.gradle.plugin.sources.DefaultKotlinSourceSet
|
||||
import org.jetbrains.kotlin.gradle.plugin.sources.KotlinDependencyScope.*
|
||||
import org.jetbrains.kotlin.gradle.plugin.sources.internal
|
||||
|
||||
object IdeJvmAndAndroidSourceDependencyResolver : IdeDependencyResolver {
|
||||
override fun resolve(sourceSet: KotlinSourceSet): Set<IdeaKotlinDependency> {
|
||||
if (!sourceSet.isJvmAndAndroid) return emptySet()
|
||||
if (sourceSet !is DefaultKotlinSourceSet) return emptySet()
|
||||
return sourceSet.dependencyTransformations[API_SCOPE]?.metadataDependencyResolutions?.toList().orEmpty()
|
||||
.plus(sourceSet.dependencyTransformations[IMPLEMENTATION_SCOPE]?.metadataDependencyResolutions?.toList().orEmpty())
|
||||
.plus(sourceSet.dependencyTransformations[COMPILE_ONLY_SCOPE]?.metadataDependencyResolutions?.toList().orEmpty())
|
||||
.filterIsInstance<MetadataDependencyResolution.ChooseVisibleSourceSets>()
|
||||
return sourceSet.resolveMetadata<MetadataDependencyResolution.ChooseVisibleSourceSets>()
|
||||
.flatMap { chooseVisibleSourceSets ->
|
||||
val projectDependency = chooseVisibleSourceSets.projectDependency ?: return@flatMap emptyList<IdeaKotlinDependency>()
|
||||
val kotlin = projectDependency.multiplatformExtensionOrNull ?: return@flatMap emptyList<IdeaKotlinDependency>()
|
||||
@@ -38,4 +34,4 @@ object IdeJvmAndAndroidSourceDependencyResolver : IdeDependencyResolver {
|
||||
|
||||
private val KotlinSourceSet.isJvmAndAndroid: Boolean
|
||||
get() = internal.compilations.map { it.platformType }.toSet() == setOf(KotlinPlatformType.androidJvm, KotlinPlatformType.jvm)
|
||||
}
|
||||
}
|
||||
|
||||
+39
@@ -0,0 +1,39 @@
|
||||
/*
|
||||
* Copyright 2010-2022 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||
*/
|
||||
|
||||
package org.jetbrains.kotlin.gradle.plugin.ide.dependencyResolvers
|
||||
|
||||
import org.gradle.api.artifacts.component.ModuleComponentIdentifier
|
||||
import org.jetbrains.kotlin.gradle.idea.tcs.IdeaKotlinDependency
|
||||
import org.jetbrains.kotlin.gradle.idea.tcs.IdeaKotlinResolvedBinaryDependency
|
||||
import org.jetbrains.kotlin.gradle.plugin.KotlinSourceSet
|
||||
import org.jetbrains.kotlin.gradle.plugin.ide.IdeDependencyResolver
|
||||
import org.jetbrains.kotlin.gradle.plugin.ide.IdeaKotlinBinaryCoordinates
|
||||
import org.jetbrains.kotlin.gradle.plugin.mpp.MetadataDependencyResolution
|
||||
import org.jetbrains.kotlin.gradle.plugin.mpp.resolvableMetadataConfiguration
|
||||
import org.jetbrains.kotlin.gradle.plugin.sources.project
|
||||
|
||||
object IdeOriginalMetadataDependencyResolver : IdeDependencyResolver {
|
||||
override fun resolve(sourceSet: KotlinSourceSet): Set<IdeaKotlinDependency> {
|
||||
val metadataDependenciesConfiguration = resolvableMetadataConfiguration(sourceSet.project, listOf(sourceSet),)
|
||||
|
||||
val keptOriginalDependencyResolutionIds = sourceSet.resolveMetadata<MetadataDependencyResolution.KeepOriginalDependency>()
|
||||
.map { it.dependency.id }.toSet()
|
||||
|
||||
val artifactsView = metadataDependenciesConfiguration.incoming.artifactView { view ->
|
||||
view.componentFilter { id -> id in keptOriginalDependencyResolutionIds }
|
||||
view.isLenient = true
|
||||
}
|
||||
|
||||
return artifactsView.artifacts.mapNotNull { artifact ->
|
||||
val moduleId = artifact.id.componentIdentifier as? ModuleComponentIdentifier ?: return@mapNotNull null
|
||||
IdeaKotlinResolvedBinaryDependency(
|
||||
binaryType = IdeaKotlinDependency.CLASSPATH_BINARY_TYPE,
|
||||
binaryFile = artifact.file,
|
||||
coordinates = IdeaKotlinBinaryCoordinates(moduleId)
|
||||
)
|
||||
}.toSet()
|
||||
}
|
||||
}
|
||||
+2
-49
@@ -5,29 +5,22 @@
|
||||
|
||||
package org.jetbrains.kotlin.gradle.plugin.ide.dependencyResolvers
|
||||
|
||||
import org.gradle.api.artifacts.component.ModuleComponentIdentifier
|
||||
import org.jetbrains.kotlin.gradle.idea.tcs.IdeaKotlinBinaryCoordinates
|
||||
import org.jetbrains.kotlin.gradle.idea.tcs.IdeaKotlinDependency
|
||||
import org.jetbrains.kotlin.gradle.idea.tcs.IdeaKotlinResolvedBinaryDependency
|
||||
import org.jetbrains.kotlin.gradle.plugin.KotlinSourceSet
|
||||
import org.jetbrains.kotlin.gradle.plugin.ide.IdeDependencyResolver
|
||||
import org.jetbrains.kotlin.gradle.plugin.ide.IdeaKotlinBinaryCoordinates
|
||||
import org.jetbrains.kotlin.gradle.plugin.mpp.MetadataDependencyResolution
|
||||
import org.jetbrains.kotlin.gradle.plugin.mpp.MetadataDependencyResolution.ChooseVisibleSourceSets
|
||||
import org.jetbrains.kotlin.gradle.plugin.mpp.MetadataDependencyResolution.ChooseVisibleSourceSets.MetadataProvider.ArtifactMetadataProvider
|
||||
import org.jetbrains.kotlin.gradle.plugin.mpp.MetadataDependencyResolution.KeepOriginalDependency
|
||||
import org.jetbrains.kotlin.gradle.plugin.mpp.kotlinTransformedMetadataLibraryDirectoryForIde
|
||||
import org.jetbrains.kotlin.gradle.plugin.mpp.read
|
||||
import org.jetbrains.kotlin.gradle.plugin.mpp.resolvableMetadataConfiguration
|
||||
import org.jetbrains.kotlin.gradle.plugin.sources.DefaultKotlinSourceSet
|
||||
import org.jetbrains.kotlin.gradle.plugin.sources.KotlinDependencyScope.*
|
||||
import org.jetbrains.kotlin.gradle.plugin.sources.internal
|
||||
import org.jetbrains.kotlin.gradle.plugin.sources.project
|
||||
import org.jetbrains.kotlin.tooling.core.mutableExtrasOf
|
||||
|
||||
internal object IdeTransformedMetadataDependencyResolver : IdeDependencyResolver {
|
||||
override fun resolve(sourceSet: KotlinSourceSet): Set<IdeaKotlinDependency> =
|
||||
collectMetadataDependencyResolutions<ChooseVisibleSourceSets>(sourceSet)
|
||||
sourceSet.resolveMetadata<ChooseVisibleSourceSets>()
|
||||
.flatMap { resolution -> resolve(sourceSet, resolution) }
|
||||
.toSet()
|
||||
|
||||
@@ -62,44 +55,4 @@ internal object IdeTransformedMetadataDependencyResolver : IdeDependencyResolver
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
object IdeOriginalMetadataDependencyResolver : IdeDependencyResolver {
|
||||
override fun resolve(sourceSet: KotlinSourceSet): Set<IdeaKotlinDependency> {
|
||||
val metadataDependenciesConfiguration = resolvableMetadataConfiguration(
|
||||
sourceSet.project,
|
||||
listOf(sourceSet),
|
||||
metadataDependencyScopes,
|
||||
)
|
||||
|
||||
val keptOriginalDependencyResolutionIds = collectMetadataDependencyResolutions<KeepOriginalDependency>(sourceSet)
|
||||
.map { it.dependency.id }.toSet()
|
||||
|
||||
val artifactsView = metadataDependenciesConfiguration.incoming.artifactView { view ->
|
||||
view.componentFilter { id -> id in keptOriginalDependencyResolutionIds }
|
||||
view.isLenient = true
|
||||
}
|
||||
|
||||
return artifactsView.artifacts.mapNotNull { artifact ->
|
||||
val moduleId = artifact.id.componentIdentifier as? ModuleComponentIdentifier ?: return@mapNotNull null
|
||||
IdeaKotlinResolvedBinaryDependency(
|
||||
binaryType = IdeaKotlinDependency.CLASSPATH_BINARY_TYPE,
|
||||
binaryFile = artifact.file,
|
||||
coordinates = IdeaKotlinBinaryCoordinates(moduleId)
|
||||
)
|
||||
}.toSet()
|
||||
}
|
||||
}
|
||||
|
||||
private inline fun <reified T : MetadataDependencyResolution> collectMetadataDependencyResolutions(sourceSet: KotlinSourceSet): List<T> {
|
||||
if (sourceSet !is DefaultKotlinSourceSet) return emptyList()
|
||||
return metadataDependencyScopes.flatMap { scope ->
|
||||
sourceSet.dependencyTransformations[scope]?.metadataDependencyResolutions?.toList().orEmpty()
|
||||
}.filterIsInstance<T>()
|
||||
}
|
||||
|
||||
private val metadataDependencyScopes = listOf(
|
||||
API_SCOPE,
|
||||
IMPLEMENTATION_SCOPE,
|
||||
COMPILE_ONLY_SCOPE,
|
||||
)
|
||||
}
|
||||
+21
@@ -0,0 +1,21 @@
|
||||
/*
|
||||
* Copyright 2010-2022 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||
*/
|
||||
|
||||
package org.jetbrains.kotlin.gradle.plugin.ide.dependencyResolvers
|
||||
|
||||
import org.jetbrains.kotlin.gradle.plugin.KotlinSourceSet
|
||||
import org.jetbrains.kotlin.gradle.plugin.mpp.MetadataDependencyResolution
|
||||
import org.jetbrains.kotlin.gradle.plugin.sources.DefaultKotlinSourceSet
|
||||
import org.jetbrains.kotlin.gradle.plugin.sources.KotlinDependencyScope
|
||||
import org.jetbrains.kotlin.gradle.plugin.sources.KotlinDependencyScope.*
|
||||
|
||||
internal inline fun <reified T : MetadataDependencyResolution> KotlinSourceSet.resolveMetadata(
|
||||
scopes: Set<KotlinDependencyScope> = setOf(API_SCOPE, IMPLEMENTATION_SCOPE, COMPILE_ONLY_SCOPE)
|
||||
): List<T> {
|
||||
if (this !is DefaultKotlinSourceSet) return emptyList()
|
||||
return scopes
|
||||
.flatMap { scope -> dependencyTransformations[scope]?.metadataDependencyResolutions?.toList().orEmpty() }
|
||||
.filterIsInstance<T>()
|
||||
}
|
||||
+6
-2
@@ -308,8 +308,12 @@ internal fun ResolvedComponentResult.toProjectOrNull(currentProject: Project): P
|
||||
internal fun resolvableMetadataConfiguration(
|
||||
project: Project,
|
||||
sourceSets: Iterable<KotlinSourceSet>,
|
||||
scopes: Iterable<KotlinDependencyScope>
|
||||
) = resolvableMetadataConfiguration(
|
||||
scopes: Iterable<KotlinDependencyScope> = setOf(
|
||||
KotlinDependencyScope.API_SCOPE,
|
||||
KotlinDependencyScope.IMPLEMENTATION_SCOPE,
|
||||
KotlinDependencyScope.COMPILE_ONLY_SCOPE
|
||||
)
|
||||
): Configuration = resolvableMetadataConfiguration(
|
||||
project,
|
||||
commonMetadataDependenciesConfigurationForScopes(project, scopes),
|
||||
sourceSets.flatMapTo(mutableListOf()) { requestedDependencies(project, it, scopes) }
|
||||
|
||||
Reference in New Issue
Block a user