From 3dacf00910c7fde3f8cae5622a6b37f1ae61b54a Mon Sep 17 00:00:00 2001 From: Gabriel Ittner Date: Tue, 17 Oct 2023 14:07:45 +0200 Subject: [PATCH] add extension to allow changing deeplinks.toml location --- deeplinks-plugin/api/deeplinks-plugin.api | 7 +++++- .../deeplinks/plugin/DeepLinksExtension.kt | 7 ++++++ .../DeeplinksManifestConfiguratorTask.kt | 4 ++-- .../deeplinks/plugin/DeeplinksPlugin.kt | 24 +++++++------------ 4 files changed, 23 insertions(+), 19 deletions(-) create mode 100644 deeplinks-plugin/src/main/kotlin/com/freeletics/khonshu/deeplinks/plugin/DeepLinksExtension.kt diff --git a/deeplinks-plugin/api/deeplinks-plugin.api b/deeplinks-plugin/api/deeplinks-plugin.api index 88dac0e72..794a9f30d 100644 --- a/deeplinks-plugin/api/deeplinks-plugin.api +++ b/deeplinks-plugin/api/deeplinks-plugin.api @@ -69,9 +69,14 @@ public final class com/freeletics/khonshu/deeplinks/plugin/DeepLinkDefinitions$C public final fun serializer ()Lkotlinx/serialization/KSerializer; } +public abstract class com/freeletics/khonshu/deeplinks/plugin/DeepLinksExtension { + public fun ()V + public abstract fun getDeepLinkDefinitionsFile ()Lorg/gradle/api/file/RegularFileProperty; +} + public abstract class com/freeletics/khonshu/deeplinks/plugin/DeeplinksManifestConfiguratorTask : org/gradle/api/DefaultTask { public fun ()V - public abstract fun getDeeplinksConfigurationFile ()Lorg/gradle/api/file/RegularFileProperty; + public abstract fun getDeepLinkDefinitionsFile ()Lorg/gradle/api/file/RegularFileProperty; public abstract fun getMergedManifest ()Lorg/gradle/api/file/RegularFileProperty; public abstract fun getUpdatedManifest ()Lorg/gradle/api/file/RegularFileProperty; public final fun taskAction ()V diff --git a/deeplinks-plugin/src/main/kotlin/com/freeletics/khonshu/deeplinks/plugin/DeepLinksExtension.kt b/deeplinks-plugin/src/main/kotlin/com/freeletics/khonshu/deeplinks/plugin/DeepLinksExtension.kt new file mode 100644 index 000000000..95afa6522 --- /dev/null +++ b/deeplinks-plugin/src/main/kotlin/com/freeletics/khonshu/deeplinks/plugin/DeepLinksExtension.kt @@ -0,0 +1,7 @@ +package com.freeletics.khonshu.deeplinks.plugin + +import org.gradle.api.file.RegularFileProperty + +public abstract class DeepLinksExtension() { + public abstract val deepLinkDefinitionsFile: RegularFileProperty +} diff --git a/deeplinks-plugin/src/main/kotlin/com/freeletics/khonshu/deeplinks/plugin/DeeplinksManifestConfiguratorTask.kt b/deeplinks-plugin/src/main/kotlin/com/freeletics/khonshu/deeplinks/plugin/DeeplinksManifestConfiguratorTask.kt index 121c05663..be5f0f257 100644 --- a/deeplinks-plugin/src/main/kotlin/com/freeletics/khonshu/deeplinks/plugin/DeeplinksManifestConfiguratorTask.kt +++ b/deeplinks-plugin/src/main/kotlin/com/freeletics/khonshu/deeplinks/plugin/DeeplinksManifestConfiguratorTask.kt @@ -9,7 +9,7 @@ import org.gradle.api.tasks.TaskAction public abstract class DeeplinksManifestConfiguratorTask : DefaultTask() { @get:InputFile - public abstract val deeplinksConfigurationFile: RegularFileProperty + public abstract val deepLinkDefinitionsFile: RegularFileProperty @get:InputFile public abstract val mergedManifest: RegularFileProperty @@ -19,7 +19,7 @@ public abstract class DeeplinksManifestConfiguratorTask : DefaultTask() { @TaskAction public fun taskAction() { - val configurationFile = deeplinksConfigurationFile.get().asFile + val configurationFile = deepLinkDefinitionsFile.get().asFile val inputManifest = mergedManifest.get().asFile val outputManifest = updatedManifest.get().asFile diff --git a/deeplinks-plugin/src/main/kotlin/com/freeletics/khonshu/deeplinks/plugin/DeeplinksPlugin.kt b/deeplinks-plugin/src/main/kotlin/com/freeletics/khonshu/deeplinks/plugin/DeeplinksPlugin.kt index 5f1efc5ee..d1c5b143a 100644 --- a/deeplinks-plugin/src/main/kotlin/com/freeletics/khonshu/deeplinks/plugin/DeeplinksPlugin.kt +++ b/deeplinks-plugin/src/main/kotlin/com/freeletics/khonshu/deeplinks/plugin/DeeplinksPlugin.kt @@ -2,7 +2,6 @@ package com.freeletics.khonshu.deeplinks.plugin import com.android.build.api.artifact.SingleArtifact import com.android.build.api.variant.AndroidComponentsExtension -import java.io.File import org.gradle.api.Plugin import org.gradle.api.Project @@ -12,31 +11,24 @@ import org.gradle.api.Project */ public abstract class DeeplinksPlugin : Plugin { override fun apply(project: Project) { - val configurationFile = File(project.projectDir, "deeplinks.toml") - if (!configurationFile.exists()) { - // configuration file doesn't exist -> skipping - return - } + val extension = project.extensions.create("deepLinks", DeepLinksExtension::class.java) + extension.deepLinkDefinitionsFile.convention(project.layout.projectDirectory.file("deeplinks.toml")) project.plugins.withId("com.android.library") { - setupDeeplinksManifestConfigurator(project, configurationFile) + setupDeeplinksManifestConfigurator(project, extension) } project.plugins.withId("com.android.application") { - setupDeeplinksManifestConfigurator(project, configurationFile) + setupDeeplinksManifestConfigurator(project, extension) } } - private fun setupDeeplinksManifestConfigurator(project: Project, configurationFile: File) { + private fun setupDeeplinksManifestConfigurator(project: Project, extension: DeepLinksExtension) { val androidComponents = project.extensions.getByType(AndroidComponentsExtension::class.java) androidComponents.onVariants { variant -> - val manifestUpdater = project.tasks.register( - variant.name + "DeeplinksManifestConfigurator", - DeeplinksManifestConfiguratorTask::class.java, - ) { - it.deeplinksConfigurationFile.set( - configurationFile, - ) + val name = "${variant.name}DeeplinksManifestConfigurator" + val manifestUpdater = project.tasks.register(name, DeeplinksManifestConfiguratorTask::class.java) { + it.deepLinkDefinitionsFile.set(extension.deepLinkDefinitionsFile) } variant.artifacts.use(manifestUpdater).wiredWithFiles( DeeplinksManifestConfiguratorTask::mergedManifest,