[Gradle] Migrate extraProperties.getOrPut usages to *StoredProperty

KT-61634
This commit is contained in:
Sebastian Sellmair
2023-10-13 14:29:54 +02:00
committed by Space Team
parent ecbd741e40
commit a8e637205c
20 changed files with 78 additions and 88 deletions
@@ -278,8 +278,10 @@ public abstract interface class org/jetbrains/kotlin/gradle/dsl/KotlinMultiplatf
public abstract fun languageSettings (Lorg/gradle/api/NamedDomainObjectProvider;Lkotlin/jvm/functions/Function1;)V
}
public class org/jetbrains/kotlin/gradle/dsl/KotlinProjectExtension : org/jetbrains/kotlin/gradle/dsl/KotlinTopLevelExtension, org/jetbrains/kotlin/gradle/plugin/KotlinSourceSetContainer {
public class org/jetbrains/kotlin/gradle/dsl/KotlinProjectExtension : org/jetbrains/kotlin/gradle/dsl/KotlinTopLevelExtension, org/jetbrains/kotlin/gradle/plugin/KotlinSourceSetContainer, org/jetbrains/kotlin/tooling/core/HasMutableExtras {
public fun <init> (Lorg/gradle/api/Project;)V
public synthetic fun getExtras ()Lorg/jetbrains/kotlin/tooling/core/Extras;
public final fun getExtras ()Lorg/jetbrains/kotlin/tooling/core/MutableExtras;
public fun getSourceSets ()Lorg/gradle/api/NamedDomainObjectContainer;
}
@@ -26,6 +26,9 @@ import org.jetbrains.kotlin.gradle.tasks.withType
import org.jetbrains.kotlin.gradle.utils.castIsolatedKotlinPluginClassLoaderAware
import org.jetbrains.kotlin.gradle.utils.configureExperimentalTryK2
import org.jetbrains.kotlin.konan.target.CompilerOutputKind
import org.jetbrains.kotlin.tooling.core.HasMutableExtras
import org.jetbrains.kotlin.tooling.core.MutableExtras
import org.jetbrains.kotlin.tooling.core.mutableExtrasOf
import javax.inject.Inject
import kotlin.reflect.KClass
@@ -159,7 +162,9 @@ internal fun KotlinTopLevelExtension.explicitApiModeAsCompilerArg(): String? {
}
@KotlinGradlePluginDsl
open class KotlinProjectExtension @Inject constructor(project: Project) : KotlinTopLevelExtension(project), KotlinSourceSetContainer {
open class KotlinProjectExtension @Inject constructor(project: Project) : KotlinTopLevelExtension(project), KotlinSourceSetContainer, HasMutableExtras {
final override val extras: MutableExtras = mutableExtrasOf()
override var sourceSets: NamedDomainObjectContainer<KotlinSourceSet>
@Suppress("UNCHECKED_CAST")
get() = DslObject(this).extensions.getByName("sourceSets") as NamedDomainObjectContainer<KotlinSourceSet>
@@ -9,7 +9,7 @@ import org.gradle.api.Project
import org.gradle.api.provider.Property
import org.jetbrains.kotlin.gradle.plugin.KotlinPluginLifecycle.*
import org.jetbrains.kotlin.gradle.utils.Future
import org.jetbrains.kotlin.gradle.utils.getOrPut
import org.jetbrains.kotlin.gradle.utils.projectStoredProperty
import kotlin.coroutines.*
/*
@@ -106,10 +106,9 @@ internal fun Project.launchInRequiredStage(stage: Stage, block: suspend KotlinPl
* Universal way of retrieving the current lifecycle
* Also: See [currentKotlinPluginLifecycle]
*/
internal val Project.kotlinPluginLifecycle: KotlinPluginLifecycle
get() = extraProperties.getOrPut(KotlinPluginLifecycle::class.java.name) {
KotlinPluginLifecycleImpl(project)
}
internal val Project.kotlinPluginLifecycle: KotlinPluginLifecycle by projectStoredProperty {
KotlinPluginLifecycleImpl(project)
}
/**
* Future that will be completed once the project is considered 'Configured'
@@ -413,11 +413,9 @@ fun getKotlinPluginVersion(logger: Logger): String {
return kotlinPluginVersionFromResources.value
}
val Project.kotlinToolingVersion: KotlinToolingVersion
get() = extensions.extraProperties.getOrPut("kotlinToolingVersion") {
KotlinToolingVersion(getKotlinPluginVersion())
}
val Project.kotlinToolingVersion: KotlinToolingVersion by projectStoredProperty {
KotlinToolingVersion(getKotlinPluginVersion())
}
private fun loadKotlinPluginVersionFromResourcesOf(any: Any) =
any.loadPropertyFromResources("project.properties", "project.version")
@@ -57,7 +57,6 @@ import org.jetbrains.kotlin.gradle.tasks.KotlinCompilerExecutionStrategy
import org.jetbrains.kotlin.gradle.utils.NativeCompilerDownloader
import org.jetbrains.kotlin.gradle.utils.loadProperty
import org.jetbrains.kotlin.gradle.utils.localProperties
import org.jetbrains.kotlin.gradle.utils.storedProjectProperty
import org.jetbrains.kotlin.konan.target.KonanTarget
import org.jetbrains.kotlin.konan.target.presetName
import org.jetbrains.kotlin.statistics.metrics.StringMetrics
@@ -8,9 +8,7 @@ package org.jetbrains.kotlin.gradle.plugin.ide
import org.gradle.api.Project
import org.gradle.api.logging.Logger
import org.gradle.api.logging.Logging
import org.jetbrains.kotlin.gradle.dsl.kotlinExtension
import org.jetbrains.kotlin.gradle.plugin.extraProperties
import org.jetbrains.kotlin.gradle.utils.getOrPut
import org.jetbrains.kotlin.gradle.utils.projectStoredProperty
interface IdeCompilerArgumentsResolver {
fun resolveCompilerArguments(any: Any): List<String>?
@@ -20,12 +18,11 @@ interface IdeCompilerArgumentsResolver {
@JvmStatic
fun instance(project: Project): IdeCompilerArgumentsResolver {
return project.extraProperties.getOrPut(IdeCompilerArgumentsResolver::class.java.name) {
IdeCompilerArgumentsResolverImpl()
}
return project.kotlinIdeCompilerArgumentsResolver
}
}
}
internal val Project.kotlinIdeCompilerArgumentsResolver: IdeCompilerArgumentsResolver get() = IdeCompilerArgumentsResolver.instance(project)
internal val Project.kotlinIdeCompilerArgumentsResolver: IdeCompilerArgumentsResolver by projectStoredProperty {
IdeCompilerArgumentsResolverImpl()
}
@@ -19,14 +19,13 @@ import org.jetbrains.kotlin.gradle.plugin.KotlinPlatformType
import org.jetbrains.kotlin.gradle.plugin.KotlinPlatformType.*
import org.jetbrains.kotlin.gradle.plugin.KotlinSourceSet
import org.jetbrains.kotlin.gradle.plugin.KotlinTarget
import org.jetbrains.kotlin.gradle.plugin.extraProperties
import org.jetbrains.kotlin.gradle.plugin.ide.IdeMultiplatformImport.SourceSetConstraint
import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeCompilation
import org.jetbrains.kotlin.gradle.plugin.sources.internal
import org.jetbrains.kotlin.gradle.targets.metadata.isNativeSourceSet
import org.jetbrains.kotlin.gradle.targets.metadata.isSingleKotlinTargetSourceSet
import org.jetbrains.kotlin.gradle.targets.metadata.isSinglePlatformTypeSourceSet
import org.jetbrains.kotlin.gradle.utils.getOrPut
import org.jetbrains.kotlin.gradle.utils.projectStoredProperty
import org.jetbrains.kotlin.tooling.core.Extras
import org.jetbrains.kotlin.tooling.core.HasMutableExtras
@@ -317,14 +316,14 @@ interface IdeMultiplatformImport {
@JvmStatic
fun instance(project: Project): IdeMultiplatformImport {
return project.extraProperties.getOrPut(IdeMultiplatformImport::class.java.name) {
IdeMultiplatformImport(project.kotlinExtension)
}
return project.kotlinIdeMultiplatformImport
}
}
}
internal val Project.kotlinIdeMultiplatformImport: IdeMultiplatformImport get() = IdeMultiplatformImport.instance(project)
internal val Project.kotlinIdeMultiplatformImport: IdeMultiplatformImport by projectStoredProperty {
IdeMultiplatformImport(project.kotlinExtension)
}
/**
* Convenience shortcut method for
@@ -6,13 +6,12 @@
package org.jetbrains.kotlin.gradle.plugin.ide
import org.gradle.api.Project
import org.jetbrains.kotlin.gradle.utils.getOrPut
import org.jetbrains.kotlin.gradle.utils.projectStoredProperty
internal val Project.kotlinIdeMultiplatformImportStatistics: IdeMultiplatformImportStatistics
get() = extensions.extraProperties.getOrPut(IdeMultiplatformImportStatistics::class.java.name) {
IdeMultiplatformImportStatistics()
}
internal val Project.kotlinIdeMultiplatformImportStatistics: IdeMultiplatformImportStatistics by projectStoredProperty {
IdeMultiplatformImportStatistics()
}
/**
* Simple implementation to track dependency resolution bottlenecks.
@@ -75,6 +75,7 @@ internal sealed class MetadataDependencyResolution(
abstract class ProjectMetadataProvider : MetadataProvider() {
enum class MetadataConsumer { Ide, Cli }
abstract fun getSourceSetCompiledMetadata(sourceSetName: String): FileCollection?
}
}
@@ -317,12 +318,9 @@ internal class GranularMetadataTransformation(
}
private val Project.allProjectsData: Map<String, GranularMetadataTransformation.ProjectData>
get() = rootProject
.extraProperties
.getOrPut("all${GranularMetadataTransformation.ProjectData::class.java.simpleName}") {
collectAllProjectsData()
}
private val Project.allProjectsData: Map<String, GranularMetadataTransformation.ProjectData> by projectStoredProperty {
collectAllProjectsData()
}
private fun Project.collectAllProjectsData(): Map<String, GranularMetadataTransformation.ProjectData> {
return rootProject.allprojects.associateBy { it.path }.mapValues { (path, currentProject) ->
@@ -14,7 +14,7 @@ import org.jetbrains.kotlin.gradle.plugin.KotlinTargetComponent
import org.jetbrains.kotlin.gradle.plugin.await
import org.jetbrains.kotlin.gradle.plugin.mpp.external.DecoratedExternalKotlinTarget
import org.jetbrains.kotlin.gradle.plugin.mpp.external.ExternalKotlinTargetImpl
import org.jetbrains.kotlin.gradle.utils.futureExtension
import org.jetbrains.kotlin.gradle.utils.extrasStoredFuture
import org.jetbrains.kotlin.tooling.core.HasMutableExtras
internal interface InternalKotlinTarget : KotlinTarget, HasMutableExtras {
@@ -39,7 +39,7 @@ internal val InternalKotlinTarget.compilerOptions: KotlinCommonCompilerOptions
else -> throw IllegalStateException("Unexpected 'KotlinTarget' type: ${this.javaClass}")
}
internal val InternalKotlinTarget.isSourcesPublishableFuture by futureExtension("isSourcesPublishableFuture") {
internal val InternalKotlinTarget.isSourcesPublishableFuture by extrasStoredFuture {
KotlinPluginLifecycle.Stage.AfterFinaliseDsl.await()
isSourcesPublishable
}
@@ -15,17 +15,17 @@ import org.gradle.api.tasks.Input
import org.gradle.api.tasks.Internal
import org.gradle.api.tasks.Nested
import org.jetbrains.kotlin.gradle.dsl.KotlinMultiplatformExtension
import org.jetbrains.kotlin.gradle.utils.currentBuildId
import org.jetbrains.kotlin.gradle.plugin.sources.KotlinDependencyScope
import org.jetbrains.kotlin.gradle.plugin.sources.sourceSetDependencyConfigurationByScope
import org.jetbrains.kotlin.gradle.targets.metadata.dependsOnClosureWithInterCompilationDependencies
import org.jetbrains.kotlin.gradle.targets.metadata.getPublishedPlatformCompilations
import org.jetbrains.kotlin.gradle.targets.metadata.isNativeSourceSet
import org.jetbrains.kotlin.gradle.targets.native.internal.CInteropCommonizerCompositeMetadataJarBundling.cinteropMetadataDirectoryPath
import org.jetbrains.kotlin.gradle.utils.*
import org.jetbrains.kotlin.gradle.utils.buildPathCompat
import org.jetbrains.kotlin.gradle.utils.compositeBuildRootProject
import org.jetbrains.kotlin.gradle.utils.currentBuildId
import org.jetbrains.kotlin.gradle.utils.future
import org.jetbrains.kotlin.gradle.utils.getOrPut
import org.w3c.dom.Document
import org.w3c.dom.Element
import org.w3c.dom.Node
@@ -153,11 +153,9 @@ data class KotlinProjectStructureMetadata(
}
}
internal val KotlinMultiplatformExtension.kotlinProjectStructureMetadata: KotlinProjectStructureMetadata
get() = project.extensions.extraProperties.getOrPut("org.jetbrains.kotlin.gradle.plugin.mpp.kotlinProjectStructureMetadata") {
buildKotlinProjectStructureMetadata(this)
}
internal val KotlinMultiplatformExtension.kotlinProjectStructureMetadata: KotlinProjectStructureMetadata by extrasStoredProperty {
buildKotlinProjectStructureMetadata(this)
}
/**
* Return the name of the variant, taking into account that external targets might pass `.*-published` whereas
@@ -10,11 +10,10 @@ import org.gradle.api.artifacts.result.ResolvedDependencyResult
import org.jetbrains.kotlin.gradle.dsl.multiplatformExtensionOrNull
import org.jetbrains.kotlin.gradle.plugin.KotlinCompilation
import org.jetbrains.kotlin.gradle.plugin.KotlinPlatformType
import org.jetbrains.kotlin.gradle.plugin.extraProperties
import org.jetbrains.kotlin.gradle.plugin.mpp.SourceSetVisibilityProvider.PlatformCompilationData
import org.jetbrains.kotlin.gradle.utils.LazyResolvedConfiguration
import org.jetbrains.kotlin.gradle.utils.dependencyArtifactsOrNull
import org.jetbrains.kotlin.gradle.utils.getOrPut
import org.jetbrains.kotlin.gradle.utils.projectStoredProperty
import java.io.File
private typealias KotlinSourceSetName = String
@@ -29,12 +28,12 @@ internal data class SourceSetVisibilityResult(
* For some of the [visibleSourceSetNames], additional artifacts may be present that
* the consumer should read the compiled source set metadata from.
*/
val hostSpecificMetadataArtifactBySourceSet: Map<String, File>
val hostSpecificMetadataArtifactBySourceSet: Map<String, File>,
)
private val Project.allPlatformCompilationData: List<PlatformCompilationData>
get() = extraProperties
.getOrPut("all${PlatformCompilationData::class.java.simpleName}") { collectAllPlatformCompilationData() }
private val Project.allPlatformCompilationData: List<PlatformCompilationData> by projectStoredProperty {
collectAllPlatformCompilationData()
}
private fun Project.collectAllPlatformCompilationData(): List<PlatformCompilationData> {
val multiplatformExtension = multiplatformExtensionOrNull ?: return emptyList()
@@ -63,7 +62,7 @@ internal class SourceSetVisibilityProvider(
class PlatformCompilationData(
val allSourceSets: Set<KotlinSourceSetName>,
val resolvedDependenciesConfiguration: LazyResolvedConfiguration,
val hostSpecificMetadataConfiguration: LazyResolvedConfiguration?
val hostSpecificMetadataConfiguration: LazyResolvedConfiguration?,
)
/**
@@ -82,7 +81,7 @@ internal class SourceSetVisibilityProvider(
visibleFromSourceSet: KotlinSourceSetName,
resolvedRootMppDependency: ResolvedDependencyResult,
dependencyProjectStructureMetadata: KotlinProjectStructureMetadata,
resolvedToOtherProject: Boolean
resolvedToOtherProject: Boolean,
): SourceSetVisibilityResult {
val resolvedRootMppDependencyId = resolvedRootMppDependency.selected.id
@@ -7,16 +7,14 @@ package org.jetbrains.kotlin.gradle.plugin.mpp.compilationImpl
import org.gradle.api.Project
import org.gradle.api.artifacts.Dependency
import org.gradle.api.file.FileCollection
import org.gradle.api.tasks.SourceSet
import org.jetbrains.kotlin.gradle.plugin.KotlinPlatformType.jvm
import org.jetbrains.kotlin.gradle.plugin.KotlinTarget
import org.jetbrains.kotlin.gradle.plugin.launch
import org.jetbrains.kotlin.gradle.plugin.mpp.*
import org.jetbrains.kotlin.gradle.plugin.mpp.InternalKotlinCompilation
import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinWithJavaTarget
import org.jetbrains.kotlin.gradle.plugin.mpp.isMain
import org.jetbrains.kotlin.gradle.plugin.mpp.isTest
import org.jetbrains.kotlin.gradle.targets.jvm.KotlinJvmTarget
import org.jetbrains.kotlin.gradle.utils.Future
import org.jetbrains.kotlin.gradle.utils.filesProvider
import org.jetbrains.kotlin.gradle.utils.future
import org.jetbrains.kotlin.gradle.utils.listProperty
@@ -19,12 +19,12 @@ import org.jetbrains.kotlin.gradle.plugin.mpp.addSourcesToKotlinCompileTask
import org.jetbrains.kotlin.gradle.plugin.sources.defaultSourceSetLanguageSettingsChecker
import org.jetbrains.kotlin.gradle.tasks.KotlinNativeCompile
import org.jetbrains.kotlin.gradle.utils.addExtendsFromRelation
import org.jetbrains.kotlin.gradle.utils.extrasStoredProperty
import org.jetbrains.kotlin.gradle.utils.whenKaptEnabled
import org.jetbrains.kotlin.tooling.core.extrasFactoryProperty
import java.util.concurrent.Callable
internal class KotlinCompilationSourceSetInclusion(
private val addSourcesToCompileTask: AddSourcesToCompileTask = DefaultAddSourcesToCompileTask
private val addSourcesToCompileTask: AddSourcesToCompileTask = DefaultAddSourcesToCompileTask,
) {
fun include(compilation: InternalKotlinCompilation<*>, sourceSet: KotlinSourceSet) {
@@ -81,7 +81,7 @@ internal class KotlinCompilationSourceSetInclusion(
* to avoid re-processing of unnecessary source sets!
*/
val InternalKotlinCompilation<*>.includedSourceSets: MutableSet<KotlinSourceSet>
by extrasFactoryProperty(KotlinCompilationSourceSetInclusion::class.java.name, { hashSetOf() })
by extrasStoredProperty { hashSetOf() }
}
@@ -91,7 +91,7 @@ internal class KotlinCompilationSourceSetInclusion(
object DefaultAddSourcesToCompileTask : AddSourcesToCompileTask {
override fun addSources(
compilation: KotlinCompilation<*>, sourceSet: KotlinSourceSet, addAsCommonSources: Lazy<Boolean>
compilation: KotlinCompilation<*>, sourceSet: KotlinSourceSet, addAsCommonSources: Lazy<Boolean>,
) {
addSourcesToKotlinCompileTask(
project = compilation.project,
@@ -137,7 +137,7 @@ internal class KotlinCompilationSourceSetInclusion(
* and compiles them together.
*/
class AddSourcesWithoutDependsOnClosure(
private val delegate: AddSourcesToCompileTask = DefaultAddSourcesToCompileTask
private val delegate: AddSourcesToCompileTask = DefaultAddSourcesToCompileTask,
) : AddSourcesToCompileTask {
override fun addSources(compilation: KotlinCompilation<*>, sourceSet: KotlinSourceSet, addAsCommonSources: Lazy<Boolean>) {
if (sourceSet !in compilation.kotlinSourceSets) return
@@ -12,7 +12,7 @@ import org.jetbrains.kotlin.gradle.plugin.mpp.*
import org.jetbrains.kotlin.gradle.targets.metadata.dependsOnClosureWithInterCompilationDependencies
import org.jetbrains.kotlin.gradle.utils.contains
import org.jetbrains.kotlin.gradle.utils.currentBuild
import org.jetbrains.kotlin.tooling.core.extrasNullableLazyProperty
import org.jetbrains.kotlin.gradle.utils.extrasStoredProperty
/**
* Returns [GranularMetadataTransformation] for all requested compile dependencies
@@ -21,9 +21,9 @@ import org.jetbrains.kotlin.tooling.core.extrasNullableLazyProperty
* Used only for IDE import (w/o KGP based dependency resolution).
* Scheduled for removal after 1.9.20
*/
internal val InternalKotlinSourceSet.metadataTransformation: GranularMetadataTransformation? by extrasNullableLazyProperty lazy@{
internal val InternalKotlinSourceSet.metadataTransformation: GranularMetadataTransformation? by extrasStoredProperty property@{
// Create only for source sets in multiplatform plugin
project.multiplatformExtensionOrNull ?: return@lazy null
project.multiplatformExtensionOrNull ?: return@property null
val parentSourceSetVisibilityProvider = ParentSourceSetVisibilityProvider { componentIdentifier ->
dependsOnClosureWithInterCompilationDependencies(this).filterIsInstance<DefaultKotlinSourceSet>()
@@ -399,7 +399,7 @@ internal fun Project.createGenerateProjectStructureMetadataTask(): TaskProvider<
task.description = "Generates serialized project structure metadata of the current project (for tooling)"
}
internal val KotlinSourceSet.isNativeSourceSet: Future<Boolean> by futureExtension("isNativeSourceSet") {
internal val KotlinSourceSet.isNativeSourceSet: Future<Boolean> by extrasStoredFuture {
val compilations = internal.awaitPlatformCompilations()
compilations.isNotEmpty() && compilations.all { it.platformType == KotlinPlatformType.native }
}
@@ -12,8 +12,8 @@ import org.jetbrains.kotlin.gradle.dsl.multiplatformExtensionOrNull
import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinSharedNativeCompilation
import org.jetbrains.kotlin.gradle.utils.Future
import org.jetbrains.kotlin.gradle.utils.appendLine
import org.jetbrains.kotlin.gradle.utils.getOrPut
import org.jetbrains.kotlin.gradle.utils.lazyFuture
import org.jetbrains.kotlin.gradle.utils.projectStoredProperty
/**
* Represents a group of cinterops and targets that can be passed to a single invocation to the commonizer.
@@ -46,10 +46,9 @@ internal data class CInteropCommonizerGroup(
/**
* Represents all collected [CInteropCommonizerGroup] gruops for the given project
*/
internal val Project.kotlinCInteropGroups: Future<Set<CInteropCommonizerGroup>>
get() = extensions.extraProperties.getOrPut("org.jetbrains.kotlin.gradle.targets.native.internal.kotlinCInteropGroups") {
lazyFuture { collectCInteropGroups() }
}
internal val Project.kotlinCInteropGroups: Future<Set<CInteropCommonizerGroup>> by projectStoredProperty {
lazyFuture { collectCInteropGroups() }
}
private suspend fun Project.collectCInteropGroups(): Set<CInteropCommonizerGroup> {
val dependents = allCinteropCommonizerDependents()
@@ -20,17 +20,17 @@ import org.jetbrains.kotlin.gradle.plugin.sources.awaitPlatformCompilations
import org.jetbrains.kotlin.gradle.plugin.sources.internal
import org.jetbrains.kotlin.gradle.utils.Future
import org.jetbrains.kotlin.gradle.utils.future
import org.jetbrains.kotlin.gradle.utils.futureExtension
import org.jetbrains.kotlin.gradle.utils.extrasStoredFuture
import org.jetbrains.kotlin.tooling.core.UnsafeApi
internal val KotlinSourceSet.commonizerTarget: Future<CommonizerTarget?> by futureExtension {
internal val KotlinSourceSet.commonizerTarget: Future<CommonizerTarget?> by extrasStoredFuture {
inferCommonizerTarget(internal.awaitPlatformCompilations())
}
internal val KotlinSourceSet.sharedCommonizerTarget: Future<SharedCommonizerTarget?>
get() = project.future { commonizerTarget.await() as? SharedCommonizerTarget }
internal val KotlinCompilation<*>.commonizerTarget: Future<CommonizerTarget?> by futureExtension {
internal val KotlinCompilation<*>.commonizerTarget: Future<CommonizerTarget?> by extrasStoredFuture {
KotlinPluginLifecycle.Stage.AfterFinaliseRefinesEdges.await()
@OptIn(UnsafeApi::class)
inferCommonizerTarget(this)
@@ -11,13 +11,13 @@ import org.gradle.api.artifacts.component.ComponentIdentifier
import org.gradle.api.artifacts.result.ResolvedComponentResult
import org.gradle.api.internal.project.ProjectInternal
import org.gradle.internal.build.BuildState
import org.jetbrains.kotlin.gradle.plugin.extraProperties
internal fun Project.currentBuildId(): BuildIdentifier =
(project as ProjectInternal).services.get(BuildState::class.java).buildIdentifier
internal val Project.currentBuild: CurrentBuildIdentifier
get() = extraProperties.getOrPut("org.jetbrains.kotlin.gradle.utils.currentBuild") { CurrentBuildIdentifierImpl(this.currentBuildId()) }
internal val Project.currentBuild: CurrentBuildIdentifier by projectStoredProperty {
CurrentBuildIdentifierImpl(this.currentBuildId())
}
/**
* Utility that can be used to test if a certain project or [ComponentIdentifier] belongs
@@ -11,13 +11,12 @@ import org.jetbrains.kotlin.gradle.plugin.KotlinPluginLifecycle
import org.jetbrains.kotlin.gradle.plugin.KotlinPluginLifecycle.CoroutineStart.Undispatched
import org.jetbrains.kotlin.gradle.plugin.KotlinPluginLifecycle.IllegalLifecycleException
import org.jetbrains.kotlin.gradle.plugin.kotlinPluginLifecycle
import org.jetbrains.kotlin.tooling.core.ExtrasLazyProperty
import org.jetbrains.kotlin.tooling.core.HasMutableExtras
import org.jetbrains.kotlin.tooling.core.extrasLazyProperty
import java.io.Serializable
import kotlin.coroutines.Continuation
import kotlin.coroutines.resume
import kotlin.coroutines.suspendCoroutine
import kotlin.properties.ReadOnlyProperty
/**
* See [KotlinPluginLifecycle]:
@@ -67,12 +66,12 @@ internal fun CompletableFuture<Unit>.complete() = complete(Unit)
* Extend a given [Receiver] with data produced by [block]:
* This uses the [HasMutableExtras] infrastructure to store/share the produced future entity to the given [Receiver]
* Note: The [block] will be lazily launched on first access to this extension!
* @param name: The name of the extras key being used to store the future (see [extrasLazyProperty])
* @see extrasStoredProperty
*/
internal inline fun <Receiver, reified T> futureExtension(
name: String? = null, noinline block: suspend Receiver.() -> T,
): ExtrasLazyProperty<Receiver, Future<T>> where Receiver : HasMutableExtras, Receiver : HasProject {
return extrasLazyProperty<Receiver, Future<T>>(name) {
internal inline fun <Receiver, reified T> extrasStoredFuture(
noinline block: suspend Receiver.() -> T,
): ReadOnlyProperty<Receiver, Future<T>> where Receiver : HasMutableExtras, Receiver : HasProject {
return extrasStoredProperty {
project.future { block() }
}
}
@@ -91,6 +90,7 @@ internal val <T> Future<T>.lenient: LenientFuture<T> get() = LenientFutureImpl(t
* ```
*
* basically creating a future, which is launched lazily
* (on first call to on any of the returned Future's method)
*/
internal fun <T> Project.lazyFuture(block: suspend Project.() -> T): Future<T> = LazyFutureImpl(lazy { future { block() } })