[Gradle] Rename experimental annotations to opt-in annotations in DSL
Methods and accessors with old names are preserved in public API and marked as deprecated now #KT-38111 In Progress
This commit is contained in:
+3
@@ -18,7 +18,10 @@ interface LanguageSettingsBuilder : LanguageSettings {
|
|||||||
|
|
||||||
override val enabledLanguageFeatures: Set<String>
|
override val enabledLanguageFeatures: Set<String>
|
||||||
|
|
||||||
|
@Deprecated("Unsupported and will be removed in next major releases", replaceWith = ReplaceWith("optInAnnotation(name)"))
|
||||||
fun useExperimentalAnnotation(name: String)
|
fun useExperimentalAnnotation(name: String)
|
||||||
|
|
||||||
|
fun optInAnnotation(name: String)
|
||||||
|
|
||||||
override val experimentalAnnotationsInUse: Set<String>
|
override val experimentalAnnotationsInUse: Set<String>
|
||||||
}
|
}
|
||||||
+1
-1
@@ -165,7 +165,7 @@ class GradleProjectModuleBuilder(private val addInferredSourceSetVisibilityAsExp
|
|||||||
?: listOf(compilation.defaultSourceSetName)
|
?: listOf(compilation.defaultSourceSetName)
|
||||||
|
|
||||||
variantNames.forEach { variantName ->
|
variantNames.forEach { variantName ->
|
||||||
val variant = BasicKotlinModuleVariant(this@apply, variantName, DefaultLanguageSettingsBuilder())
|
val variant = BasicKotlinModuleVariant(this@apply, variantName, DefaultLanguageSettingsBuilder(project))
|
||||||
moduleByFragment[variant] = this@apply
|
moduleByFragment[variant] = this@apply
|
||||||
variantToCompilation[variant] = compilation
|
variantToCompilation[variant] = compilation
|
||||||
fragments.add(variant)
|
fragments.add(variant)
|
||||||
|
|||||||
+5
-1
@@ -48,7 +48,11 @@ class GradleKotlinDependencyGraphResolver(
|
|||||||
|
|
||||||
fun getKotlinModuleFromComponentResult(component: ResolvedComponentResult): KotlinModule =
|
fun getKotlinModuleFromComponentResult(component: ResolvedComponentResult): KotlinModule =
|
||||||
moduleResolver.resolveDependency(requestingModule, component.toModuleDependency())
|
moduleResolver.resolveDependency(requestingModule, component.toModuleDependency())
|
||||||
?: buildSyntheticPlainModule(component, component.variants.singleOrNull()?.displayName ?: "default")
|
?: buildSyntheticPlainModule(
|
||||||
|
component,
|
||||||
|
component.variants.singleOrNull()?.displayName ?: "default",
|
||||||
|
requestingModule.project
|
||||||
|
)
|
||||||
|
|
||||||
fun nodeFromModule(componentResult: ResolvedComponentResult, kotlinModule: KotlinModule): GradleDependencyGraphNode {
|
fun nodeFromModule(componentResult: ResolvedComponentResult, kotlinModule: KotlinModule): GradleDependencyGraphNode {
|
||||||
val id = kotlinModule.moduleIdentifier
|
val id = kotlinModule.moduleIdentifier
|
||||||
|
|||||||
+3
-2
@@ -117,11 +117,12 @@ class GradleModuleDependencyResolver(
|
|||||||
// TODO think about multi-variant stub modules for non-Kotlin modules which got more than one chosen variant
|
// TODO think about multi-variant stub modules for non-Kotlin modules which got more than one chosen variant
|
||||||
internal fun buildSyntheticPlainModule(
|
internal fun buildSyntheticPlainModule(
|
||||||
resolvedComponentResult: ResolvedComponentResult,
|
resolvedComponentResult: ResolvedComponentResult,
|
||||||
singleVariantName: String
|
singleVariantName: String,
|
||||||
|
project: Project
|
||||||
): ExternalPlainKotlinModule {
|
): ExternalPlainKotlinModule {
|
||||||
val moduleDependency = resolvedComponentResult.toModuleDependency()
|
val moduleDependency = resolvedComponentResult.toModuleDependency()
|
||||||
return ExternalPlainKotlinModule(BasicKotlinModule(moduleDependency.moduleIdentifier).apply {
|
return ExternalPlainKotlinModule(BasicKotlinModule(moduleDependency.moduleIdentifier).apply {
|
||||||
BasicKotlinModuleVariant(this@apply, singleVariantName, DefaultLanguageSettingsBuilder()).apply {
|
BasicKotlinModuleVariant(this@apply, singleVariantName, DefaultLanguageSettingsBuilder(project)).apply {
|
||||||
fragments.add(this)
|
fragments.add(this)
|
||||||
this.declaredModuleDependencies.addAll(
|
this.declaredModuleDependencies.addAll(
|
||||||
resolvedComponentResult.dependencies
|
resolvedComponentResult.dependencies
|
||||||
|
|||||||
+1
-1
@@ -37,7 +37,7 @@ open class KotlinGradleFragmentInternal @Inject constructor(
|
|||||||
// TODO pull up to KotlinModuleFragment
|
// TODO pull up to KotlinModuleFragment
|
||||||
// FIXME apply to compilation
|
// FIXME apply to compilation
|
||||||
// FIXME check for consistency
|
// FIXME check for consistency
|
||||||
override val languageSettings: LanguageSettingsBuilder = DefaultLanguageSettingsBuilder()
|
override val languageSettings: LanguageSettingsBuilder = DefaultLanguageSettingsBuilder(project)
|
||||||
|
|
||||||
override fun refines(other: KotlinGradleFragment) {
|
override fun refines(other: KotlinGradleFragment) {
|
||||||
checkCanRefine(other)
|
checkCanRefine(other)
|
||||||
|
|||||||
+6
-6
@@ -48,16 +48,16 @@ internal class FragmentConsistencyChecks<T>(
|
|||||||
consistencyConditionHint = unstableFeaturesHint
|
consistencyConditionHint = unstableFeaturesHint
|
||||||
)
|
)
|
||||||
|
|
||||||
private val experimentalAnnotationsInUseHint = "The dependent $unitName must use all experimental annotations that its dependency uses."
|
private val optInAnnotationsInUseHint = "The dependent $unitName must use all opt-in annotations that its dependency uses."
|
||||||
|
|
||||||
val experimentalAnnotationsCheck = ConsistencyCheck<T, Set<String>>(
|
val optInAnnotationsCheck = ConsistencyCheck<T, Set<String>>(
|
||||||
name = "set of experimental annotations in use",
|
name = "set of opt-in annotations in use",
|
||||||
getValue = { unit -> unit.languageSettings().experimentalAnnotationsInUse },
|
getValue = { unit -> unit.languageSettings().optInAnnotationsInUse },
|
||||||
leftExtendsRightConsistently = { left, right -> left.containsAll(right) },
|
leftExtendsRightConsistently = { left, right -> left.containsAll(right) },
|
||||||
consistencyConditionHint = experimentalAnnotationsInUseHint
|
consistencyConditionHint = optInAnnotationsInUseHint
|
||||||
)
|
)
|
||||||
|
|
||||||
val allChecks = listOf(languageVersionCheck, unstableFeaturesCheck, experimentalAnnotationsCheck)
|
val allChecks = listOf(languageVersionCheck, unstableFeaturesCheck, optInAnnotationsCheck)
|
||||||
}
|
}
|
||||||
|
|
||||||
internal class FragmentConsistencyChecker<T>(
|
internal class FragmentConsistencyChecker<T>(
|
||||||
|
|||||||
+1
-1
@@ -65,7 +65,7 @@ class DefaultKotlinSourceSet(
|
|||||||
filter.include("**/*.kts")
|
filter.include("**/*.kts")
|
||||||
}
|
}
|
||||||
|
|
||||||
override val languageSettings: LanguageSettingsBuilder = DefaultLanguageSettingsBuilder()
|
override val languageSettings: LanguageSettingsBuilder = DefaultLanguageSettingsBuilder(project)
|
||||||
|
|
||||||
override val resources: SourceDirectorySet = createDefaultSourceDirectorySet(project, "$name resources")
|
override val resources: SourceDirectorySet = createDefaultSourceDirectorySet(project, "$name resources")
|
||||||
|
|
||||||
|
|||||||
+28
-5
@@ -6,6 +6,7 @@
|
|||||||
package org.jetbrains.kotlin.gradle.plugin.sources
|
package org.jetbrains.kotlin.gradle.plugin.sources
|
||||||
|
|
||||||
import org.gradle.api.InvalidUserDataException
|
import org.gradle.api.InvalidUserDataException
|
||||||
|
import org.gradle.api.Project
|
||||||
import org.gradle.api.file.FileCollection
|
import org.gradle.api.file.FileCollection
|
||||||
import org.gradle.api.provider.Provider
|
import org.gradle.api.provider.Provider
|
||||||
import org.gradle.api.tasks.SourceTask
|
import org.gradle.api.tasks.SourceTask
|
||||||
@@ -17,11 +18,12 @@ import org.jetbrains.kotlin.gradle.plugin.LanguageSettingsBuilder
|
|||||||
import org.jetbrains.kotlin.gradle.plugin.statistics.KotlinBuildStatsService
|
import org.jetbrains.kotlin.gradle.plugin.statistics.KotlinBuildStatsService
|
||||||
import org.jetbrains.kotlin.gradle.tasks.AbstractKotlinCompile
|
import org.jetbrains.kotlin.gradle.tasks.AbstractKotlinCompile
|
||||||
import org.jetbrains.kotlin.gradle.tasks.AbstractKotlinNativeCompile
|
import org.jetbrains.kotlin.gradle.tasks.AbstractKotlinNativeCompile
|
||||||
|
import org.jetbrains.kotlin.gradle.utils.SingleWarningPerBuild
|
||||||
import org.jetbrains.kotlin.project.model.LanguageSettings
|
import org.jetbrains.kotlin.project.model.LanguageSettings
|
||||||
import org.jetbrains.kotlin.statistics.metrics.BooleanMetrics
|
import org.jetbrains.kotlin.statistics.metrics.BooleanMetrics
|
||||||
import org.jetbrains.kotlin.statistics.metrics.StringMetrics
|
import org.jetbrains.kotlin.statistics.metrics.StringMetrics
|
||||||
|
|
||||||
internal class DefaultLanguageSettingsBuilder : LanguageSettingsBuilder {
|
internal class DefaultLanguageSettingsBuilder(@Transient private val project: Project) : LanguageSettingsBuilder {
|
||||||
private var languageVersionImpl: LanguageVersion? = null
|
private var languageVersionImpl: LanguageVersion? = null
|
||||||
|
|
||||||
override var languageVersion: String?
|
override var languageVersion: String?
|
||||||
@@ -60,12 +62,33 @@ internal class DefaultLanguageSettingsBuilder : LanguageSettingsBuilder {
|
|||||||
enabledLanguageFeaturesImpl += languageFeature
|
enabledLanguageFeaturesImpl += languageFeature
|
||||||
}
|
}
|
||||||
|
|
||||||
private val experimentalAnnotationsInUseImpl = mutableSetOf<String>()
|
private val optInAnnotationsInUseImpl = mutableSetOf<String>()
|
||||||
|
|
||||||
override val experimentalAnnotationsInUse: Set<String> = experimentalAnnotationsInUseImpl
|
override val optInAnnotationsInUse: Set<String> = optInAnnotationsInUseImpl
|
||||||
|
|
||||||
|
override val experimentalAnnotationsInUse: Set<String>
|
||||||
|
get() {
|
||||||
|
SingleWarningPerBuild.deprecation(
|
||||||
|
project,
|
||||||
|
"Kotlin language settings property",
|
||||||
|
"experimentalAnnotationsInUse",
|
||||||
|
"optInAnnotationsInUse"
|
||||||
|
)
|
||||||
|
return optInAnnotationsInUse
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun optInAnnotation(name: String) {
|
||||||
|
optInAnnotationsInUseImpl += name
|
||||||
|
}
|
||||||
|
|
||||||
override fun useExperimentalAnnotation(name: String) {
|
override fun useExperimentalAnnotation(name: String) {
|
||||||
experimentalAnnotationsInUseImpl += name
|
SingleWarningPerBuild.deprecation(
|
||||||
|
project,
|
||||||
|
"Kotlin language settings function",
|
||||||
|
"useExperimentalAnnotation",
|
||||||
|
"optInAnnotation"
|
||||||
|
)
|
||||||
|
optInAnnotation(name)
|
||||||
}
|
}
|
||||||
|
|
||||||
/* A Kotlin task that is responsible for code analysis of the owner of this language settings builder. */
|
/* A Kotlin task that is responsible for code analysis of the owner of this language settings builder. */
|
||||||
@@ -114,7 +137,7 @@ internal fun applyLanguageSettingsToKotlinOptions(
|
|||||||
add("-XXLanguage:+$featureName")
|
add("-XXLanguage:+$featureName")
|
||||||
}
|
}
|
||||||
|
|
||||||
languageSettingsBuilder.experimentalAnnotationsInUse.forEach { annotationName ->
|
languageSettingsBuilder.optInAnnotationsInUse.forEach { annotationName ->
|
||||||
add("-Xopt-in=$annotationName")
|
add("-Xopt-in=$annotationName")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+7
-3
@@ -423,8 +423,12 @@ constructor(
|
|||||||
val enabledLanguageFeatures: Set<String>
|
val enabledLanguageFeatures: Set<String>
|
||||||
@Input get() = languageSettings.enabledLanguageFeatures
|
@Input get() = languageSettings.enabledLanguageFeatures
|
||||||
|
|
||||||
|
@Deprecated("Unsupported and will be removed in next major releases", replaceWith = ReplaceWith("optInAnnotationsInUse"))
|
||||||
val experimentalAnnotationsInUse: Set<String>
|
val experimentalAnnotationsInUse: Set<String>
|
||||||
@Input get() = languageSettings.experimentalAnnotationsInUse
|
@Internal get() = languageSettings.experimentalAnnotationsInUse
|
||||||
|
|
||||||
|
val optInAnnotationsInUse: Set<String>
|
||||||
|
@Input get() = languageSettings.optInAnnotationsInUse
|
||||||
// endregion.
|
// endregion.
|
||||||
|
|
||||||
// region Kotlin options.
|
// region Kotlin options.
|
||||||
@@ -457,7 +461,7 @@ constructor(
|
|||||||
enabledLanguageFeatures.forEach { featureName ->
|
enabledLanguageFeatures.forEach { featureName ->
|
||||||
add("-XXLanguage:+$featureName")
|
add("-XXLanguage:+$featureName")
|
||||||
}
|
}
|
||||||
experimentalAnnotationsInUse.forEach { annotationName ->
|
optInAnnotationsInUse.forEach { annotationName ->
|
||||||
add("-Xopt-in=$annotationName")
|
add("-Xopt-in=$annotationName")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -622,7 +626,7 @@ constructor(
|
|||||||
it.enabledLanguageFeatures.forEach { featureName ->
|
it.enabledLanguageFeatures.forEach { featureName ->
|
||||||
add("-XXLanguage:+$featureName")
|
add("-XXLanguage:+$featureName")
|
||||||
}
|
}
|
||||||
it.experimentalAnnotationsInUse.forEach { annotationName ->
|
it.optInAnnotationsInUse.forEach { annotationName ->
|
||||||
add("-Xopt-in=$annotationName")
|
add("-Xopt-in=$annotationName")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+5
@@ -35,4 +35,9 @@ internal object SingleWarningPerBuild {
|
|||||||
fun show(project: Project, warningText: String) = SingleActionPerBuild.run(project, ACTION_ID_SHOW_WARNING + warningText) {
|
fun show(project: Project, warningText: String) = SingleActionPerBuild.run(project, ACTION_ID_SHOW_WARNING + warningText) {
|
||||||
project.logger.warn(warningText)
|
project.logger.warn(warningText)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun deprecation(project: Project, context: String, target: String, replacement: String?) {
|
||||||
|
val replacementMessage = replacement?.let { " Please, use '$replacement' instead." } ?: ""
|
||||||
|
show(project, "Warning: $context '$target' is deprecated and will be removed in next major releases.$replacementMessage\n")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,5 +10,8 @@ interface LanguageSettings {
|
|||||||
val apiVersion: String?
|
val apiVersion: String?
|
||||||
val progressiveMode: Boolean
|
val progressiveMode: Boolean
|
||||||
val enabledLanguageFeatures: Set<String>
|
val enabledLanguageFeatures: Set<String>
|
||||||
|
|
||||||
|
@Deprecated("Unsupported and will be removed in next major releases", replaceWith = ReplaceWith("optInAnnotationsInUse"))
|
||||||
val experimentalAnnotationsInUse: Set<String>
|
val experimentalAnnotationsInUse: Set<String>
|
||||||
|
val optInAnnotationsInUse: Set<String>
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user