Skip to content

Commit

Permalink
add extension to allow changing deeplinks.toml location
Browse files Browse the repository at this point in the history
  • Loading branch information
gabrielittner committed Oct 17, 2023
1 parent 1e7f19f commit 198f9b3
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -12,31 +11,24 @@ import org.gradle.api.Project
*/
public abstract class DeeplinksPlugin : Plugin<Project> {
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,
Expand Down

0 comments on commit 198f9b3

Please sign in to comment.