Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add extension to allow changing deeplinks.toml location #573

Merged
merged 1 commit into from
Oct 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion deeplinks-plugin/api/deeplinks-plugin.api
Original file line number Diff line number Diff line change
Expand Up @@ -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 <init> ()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 <init> ()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
Expand Down
Original file line number Diff line number Diff line change
@@ -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
}
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