From d74cd0d87891cc8d42b0a9d4d5fe2f698b3e053a Mon Sep 17 00:00:00 2001 From: Omico Date: Fri, 21 Apr 2023 15:51:56 -0700 Subject: [PATCH] Rename apply to register for GradmIntegrationsExtension --- docs/getting-started.md | 2 +- docs/zh-Hans/getting-started.md | 2 +- .../gradm-getting-started/gradm/build.gradle.kts | 2 +- .../integration/GradmIntegrationsExtension.kt | 15 +++++++++++++++ .../internal/GradmIntegrationsExtensionImpl.kt | 10 ++++++++-- 5 files changed, 26 insertions(+), 5 deletions(-) diff --git a/docs/getting-started.md b/docs/getting-started.md index f64cf582..2c76cee0 100644 --- a/docs/getting-started.md +++ b/docs/getting-started.md @@ -185,7 +185,7 @@ In `gradm/build.gradle.kts`: ```kotlin gradm { integrations { - apply("github") { + register("github") { // We can temporarily disable the integration, without delete the whole configuration. enabled = true // default: true configFilePath = "gradm.integration.github.yml" // default: "gradm.integration.github.yml" diff --git a/docs/zh-Hans/getting-started.md b/docs/zh-Hans/getting-started.md index 82be8f63..fc991500 100644 --- a/docs/zh-Hans/getting-started.md +++ b/docs/zh-Hans/getting-started.md @@ -180,7 +180,7 @@ gradm { ```kotlin gradm { integrations { - apply("github") { + register("github") { // 我们可以暂时禁用集成,而不删除整个配置。 enabled = true // 默认为 true configFilePath = "gradm.integration.github.yml" // 默认为 "gradm.integration.github.yml" diff --git a/examples/gradm-getting-started/gradm/build.gradle.kts b/examples/gradm-getting-started/gradm/build.gradle.kts index b4190128..c6492984 100644 --- a/examples/gradm-getting-started/gradm/build.gradle.kts +++ b/examples/gradm-getting-started/gradm/build.gradle.kts @@ -18,7 +18,7 @@ gradm { indent = 2 // default: 2 } integrations { - apply("github") { + register("github") { enabled = true // default: true configFilePath = "gradm.integration.github.yml" // default: "gradm.integration.github.yml" } diff --git a/gradm-gradle-plugin/src/main/kotlin/me/omico/gradm/integration/GradmIntegrationsExtension.kt b/gradm-gradle-plugin/src/main/kotlin/me/omico/gradm/integration/GradmIntegrationsExtension.kt index 031a2936..94236fde 100644 --- a/gradm-gradle-plugin/src/main/kotlin/me/omico/gradm/integration/GradmIntegrationsExtension.kt +++ b/gradm-gradle-plugin/src/main/kotlin/me/omico/gradm/integration/GradmIntegrationsExtension.kt @@ -18,7 +18,22 @@ package me.omico.gradm.integration import org.gradle.api.Action import org.gradle.api.plugins.ExtensionAware +// TODO Remove deprecated methods in Gradm 5.0.0. interface GradmIntegrationsExtension : ExtensionAware { + @Deprecated( + message = "Use `apply` instead. This method will be removed in Gradm 5.0.0.", + replaceWith = ReplaceWith("apply(id)"), + level = DeprecationLevel.WARNING, + ) fun apply(id: String) + + @Deprecated( + message = "Use `apply` instead. This method will be removed in Gradm 5.0.0.", + replaceWith = ReplaceWith("apply(id, configure)"), + level = DeprecationLevel.WARNING, + ) fun apply(id: String, configure: Action) + + fun register(id: String) + fun register(id: String, configure: Action) } diff --git a/gradm-gradle-plugin/src/main/kotlin/me/omico/gradm/integration/internal/GradmIntegrationsExtensionImpl.kt b/gradm-gradle-plugin/src/main/kotlin/me/omico/gradm/integration/internal/GradmIntegrationsExtensionImpl.kt index c7fa5ca0..ac8d405c 100644 --- a/gradm-gradle-plugin/src/main/kotlin/me/omico/gradm/integration/internal/GradmIntegrationsExtensionImpl.kt +++ b/gradm-gradle-plugin/src/main/kotlin/me/omico/gradm/integration/internal/GradmIntegrationsExtensionImpl.kt @@ -22,8 +22,14 @@ import me.omico.gradm.integration.GradmIntegrationsExtension import org.gradle.api.Action internal abstract class GradmIntegrationsExtensionImpl : GradmIntegrationsExtension { - override fun apply(id: String) = apply(id) {} - override fun apply(id: String, configure: Action) = + @Suppress("OVERRIDE_DEPRECATION") + override fun apply(id: String) = register(id) + + @Suppress("OVERRIDE_DEPRECATION") + override fun apply(id: String, configure: Action) = register(id, configure) + + override fun register(id: String) = register(id) {} + override fun register(id: String, configure: Action) = GradmIntegrationExtensionImpl(id) .apply(configure::execute) .toConfiguration()