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 3dacf00
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 19 deletions.
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

0 comments on commit 3dacf00

Please sign in to comment.