Skip to content

Commit

Permalink
add deep links test helper
Browse files Browse the repository at this point in the history
  • Loading branch information
gabrielittner committed Oct 17, 2023
1 parent 1e7f19f commit 9545218
Show file tree
Hide file tree
Showing 15 changed files with 470 additions and 199 deletions.
169 changes: 4 additions & 165 deletions deeplinks-plugin/api/deeplinks-plugin.api
Original file line number Diff line number Diff line change
@@ -1,77 +1,11 @@
public final class com/freeletics/khonshu/deeplinks/plugin/DeepLinkDefinition {
public static final field Companion Lcom/freeletics/khonshu/deeplinks/plugin/DeepLinkDefinition$Companion;
public synthetic fun <init> (ILjava/util/List;Ljava/util/List;Ljava/util/List;Ljava/util/List;Lkotlinx/serialization/internal/SerializationConstructorMarker;)V
public fun <init> (Ljava/util/List;Ljava/util/List;Ljava/util/List;Ljava/util/List;)V
public synthetic fun <init> (Ljava/util/List;Ljava/util/List;Ljava/util/List;Ljava/util/List;ILkotlin/jvm/internal/DefaultConstructorMarker;)V
public final fun component1 ()Ljava/util/List;
public final fun component2 ()Ljava/util/List;
public final fun component3 ()Ljava/util/List;
public final fun component4 ()Ljava/util/List;
public final fun copy (Ljava/util/List;Ljava/util/List;Ljava/util/List;Ljava/util/List;)Lcom/freeletics/khonshu/deeplinks/plugin/DeepLinkDefinition;
public static synthetic fun copy$default (Lcom/freeletics/khonshu/deeplinks/plugin/DeepLinkDefinition;Ljava/util/List;Ljava/util/List;Ljava/util/List;Ljava/util/List;ILjava/lang/Object;)Lcom/freeletics/khonshu/deeplinks/plugin/DeepLinkDefinition;
public fun equals (Ljava/lang/Object;)Z
public final fun getExampleQueries ()Ljava/util/List;
public final fun getPatterns ()Ljava/util/List;
public final fun getPlaceholders ()Ljava/util/List;
public final fun getPrefixes ()Ljava/util/List;
public fun hashCode ()I
public fun toString ()Ljava/lang/String;
public static final synthetic fun write$Self (Lcom/freeletics/khonshu/deeplinks/plugin/DeepLinkDefinition;Lkotlinx/serialization/encoding/CompositeEncoder;Lkotlinx/serialization/descriptors/SerialDescriptor;)V
}

public final class com/freeletics/khonshu/deeplinks/plugin/DeepLinkDefinition$$serializer : kotlinx/serialization/internal/GeneratedSerializer {
public static final field INSTANCE Lcom/freeletics/khonshu/deeplinks/plugin/DeepLinkDefinition$$serializer;
public fun childSerializers ()[Lkotlinx/serialization/KSerializer;
public fun deserialize (Lkotlinx/serialization/encoding/Decoder;)Lcom/freeletics/khonshu/deeplinks/plugin/DeepLinkDefinition;
public synthetic fun deserialize (Lkotlinx/serialization/encoding/Decoder;)Ljava/lang/Object;
public fun getDescriptor ()Lkotlinx/serialization/descriptors/SerialDescriptor;
public fun serialize (Lkotlinx/serialization/encoding/Encoder;Lcom/freeletics/khonshu/deeplinks/plugin/DeepLinkDefinition;)V
public synthetic fun serialize (Lkotlinx/serialization/encoding/Encoder;Ljava/lang/Object;)V
public fun typeParametersSerializers ()[Lkotlinx/serialization/KSerializer;
}

public final class com/freeletics/khonshu/deeplinks/plugin/DeepLinkDefinition$Companion {
public final fun serializer ()Lkotlinx/serialization/KSerializer;
}

public final class com/freeletics/khonshu/deeplinks/plugin/DeepLinkDefinitions {
public static final field Companion Lcom/freeletics/khonshu/deeplinks/plugin/DeepLinkDefinitions$Companion;
public synthetic fun <init> (ILjava/util/List;Ljava/util/List;Ljava/util/Map;Lkotlinx/serialization/internal/SerializationConstructorMarker;)V
public fun <init> (Ljava/util/List;Ljava/util/List;Ljava/util/Map;)V
public synthetic fun <init> (Ljava/util/List;Ljava/util/List;Ljava/util/Map;ILkotlin/jvm/internal/DefaultConstructorMarker;)V
public final fun component1 ()Ljava/util/List;
public final fun component2 ()Ljava/util/List;
public final fun component3 ()Ljava/util/Map;
public final fun copy (Ljava/util/List;Ljava/util/List;Ljava/util/Map;)Lcom/freeletics/khonshu/deeplinks/plugin/DeepLinkDefinitions;
public static synthetic fun copy$default (Lcom/freeletics/khonshu/deeplinks/plugin/DeepLinkDefinitions;Ljava/util/List;Ljava/util/List;Ljava/util/Map;ILjava/lang/Object;)Lcom/freeletics/khonshu/deeplinks/plugin/DeepLinkDefinitions;
public fun equals (Ljava/lang/Object;)Z
public final fun getDeepLinks ()Ljava/util/Map;
public final fun getPlaceholders ()Ljava/util/List;
public final fun getPrefixes ()Ljava/util/List;
public fun hashCode ()I
public fun toString ()Ljava/lang/String;
public static final synthetic fun write$Self (Lcom/freeletics/khonshu/deeplinks/plugin/DeepLinkDefinitions;Lkotlinx/serialization/encoding/CompositeEncoder;Lkotlinx/serialization/descriptors/SerialDescriptor;)V
}

public final class com/freeletics/khonshu/deeplinks/plugin/DeepLinkDefinitions$$serializer : kotlinx/serialization/internal/GeneratedSerializer {
public static final field INSTANCE Lcom/freeletics/khonshu/deeplinks/plugin/DeepLinkDefinitions$$serializer;
public fun childSerializers ()[Lkotlinx/serialization/KSerializer;
public fun deserialize (Lkotlinx/serialization/encoding/Decoder;)Lcom/freeletics/khonshu/deeplinks/plugin/DeepLinkDefinitions;
public synthetic fun deserialize (Lkotlinx/serialization/encoding/Decoder;)Ljava/lang/Object;
public fun getDescriptor ()Lkotlinx/serialization/descriptors/SerialDescriptor;
public fun serialize (Lkotlinx/serialization/encoding/Encoder;Lcom/freeletics/khonshu/deeplinks/plugin/DeepLinkDefinitions;)V
public synthetic fun serialize (Lkotlinx/serialization/encoding/Encoder;Ljava/lang/Object;)V
public fun typeParametersSerializers ()[Lkotlinx/serialization/KSerializer;
}

public final class com/freeletics/khonshu/deeplinks/plugin/DeepLinkDefinitions$Companion {
public final fun decodeFromString (Ljava/lang/String;)Lcom/freeletics/khonshu/deeplinks/plugin/DeepLinkDefinitions;
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 All @@ -83,98 +17,3 @@ public abstract class com/freeletics/khonshu/deeplinks/plugin/DeeplinksPlugin :
public fun apply (Lorg/gradle/api/Project;)V
}

public final class com/freeletics/khonshu/deeplinks/plugin/PatternDefinition {
public static final field Companion Lcom/freeletics/khonshu/deeplinks/plugin/PatternDefinition$Companion;
public static final synthetic fun box-impl (Ljava/lang/String;)Lcom/freeletics/khonshu/deeplinks/plugin/PatternDefinition;
public static fun constructor-impl (Ljava/lang/String;)Ljava/lang/String;
public fun equals (Ljava/lang/Object;)Z
public static fun equals-impl (Ljava/lang/String;Ljava/lang/Object;)Z
public static final fun equals-impl0 (Ljava/lang/String;Ljava/lang/String;)Z
public final fun getValue ()Ljava/lang/String;
public fun hashCode ()I
public static fun hashCode-impl (Ljava/lang/String;)I
public static final fun replacePlaceholders-impl (Ljava/lang/String;Lkotlin/jvm/functions/Function1;)Ljava/lang/String;
public fun toString ()Ljava/lang/String;
public static fun toString-impl (Ljava/lang/String;)Ljava/lang/String;
public final synthetic fun unbox-impl ()Ljava/lang/String;
}

public final class com/freeletics/khonshu/deeplinks/plugin/PatternDefinition$$serializer : kotlinx/serialization/internal/GeneratedSerializer {
public static final field INSTANCE Lcom/freeletics/khonshu/deeplinks/plugin/PatternDefinition$$serializer;
public fun childSerializers ()[Lkotlinx/serialization/KSerializer;
public synthetic fun deserialize (Lkotlinx/serialization/encoding/Decoder;)Ljava/lang/Object;
public fun deserialize-bHjcdSE (Lkotlinx/serialization/encoding/Decoder;)Ljava/lang/String;
public fun getDescriptor ()Lkotlinx/serialization/descriptors/SerialDescriptor;
public synthetic fun serialize (Lkotlinx/serialization/encoding/Encoder;Ljava/lang/Object;)V
public fun serialize-GtvXZAs (Lkotlinx/serialization/encoding/Encoder;Ljava/lang/String;)V
public fun typeParametersSerializers ()[Lkotlinx/serialization/KSerializer;
}

public final class com/freeletics/khonshu/deeplinks/plugin/PatternDefinition$Companion {
public final fun serializer ()Lkotlinx/serialization/KSerializer;
}

public final class com/freeletics/khonshu/deeplinks/plugin/PlaceholderDefinition {
public static final field Companion Lcom/freeletics/khonshu/deeplinks/plugin/PlaceholderDefinition$Companion;
public synthetic fun <init> (ILjava/lang/String;Ljava/util/List;Lkotlinx/serialization/internal/SerializationConstructorMarker;)V
public fun <init> (Ljava/lang/String;Ljava/util/List;)V
public final fun component1 ()Ljava/lang/String;
public final fun component2 ()Ljava/util/List;
public final fun copy (Ljava/lang/String;Ljava/util/List;)Lcom/freeletics/khonshu/deeplinks/plugin/PlaceholderDefinition;
public static synthetic fun copy$default (Lcom/freeletics/khonshu/deeplinks/plugin/PlaceholderDefinition;Ljava/lang/String;Ljava/util/List;ILjava/lang/Object;)Lcom/freeletics/khonshu/deeplinks/plugin/PlaceholderDefinition;
public fun equals (Ljava/lang/Object;)Z
public final fun getExampleValues ()Ljava/util/List;
public final fun getKey ()Ljava/lang/String;
public fun hashCode ()I
public fun toString ()Ljava/lang/String;
public static final synthetic fun write$Self (Lcom/freeletics/khonshu/deeplinks/plugin/PlaceholderDefinition;Lkotlinx/serialization/encoding/CompositeEncoder;Lkotlinx/serialization/descriptors/SerialDescriptor;)V
}

public final class com/freeletics/khonshu/deeplinks/plugin/PlaceholderDefinition$$serializer : kotlinx/serialization/internal/GeneratedSerializer {
public static final field INSTANCE Lcom/freeletics/khonshu/deeplinks/plugin/PlaceholderDefinition$$serializer;
public fun childSerializers ()[Lkotlinx/serialization/KSerializer;
public fun deserialize (Lkotlinx/serialization/encoding/Decoder;)Lcom/freeletics/khonshu/deeplinks/plugin/PlaceholderDefinition;
public synthetic fun deserialize (Lkotlinx/serialization/encoding/Decoder;)Ljava/lang/Object;
public fun getDescriptor ()Lkotlinx/serialization/descriptors/SerialDescriptor;
public fun serialize (Lkotlinx/serialization/encoding/Encoder;Lcom/freeletics/khonshu/deeplinks/plugin/PlaceholderDefinition;)V
public synthetic fun serialize (Lkotlinx/serialization/encoding/Encoder;Ljava/lang/Object;)V
public fun typeParametersSerializers ()[Lkotlinx/serialization/KSerializer;
}

public final class com/freeletics/khonshu/deeplinks/plugin/PlaceholderDefinition$Companion {
public final fun serializer ()Lkotlinx/serialization/KSerializer;
}

public final class com/freeletics/khonshu/deeplinks/plugin/PrefixDefinition {
public static final field Companion Lcom/freeletics/khonshu/deeplinks/plugin/PrefixDefinition$Companion;
public synthetic fun <init> (ILjava/lang/String;Ljava/lang/String;ZLkotlinx/serialization/internal/SerializationConstructorMarker;)V
public fun <init> (Ljava/lang/String;Ljava/lang/String;Z)V
public final fun component1 ()Ljava/lang/String;
public final fun component2 ()Ljava/lang/String;
public final fun component3 ()Z
public final fun copy (Ljava/lang/String;Ljava/lang/String;Z)Lcom/freeletics/khonshu/deeplinks/plugin/PrefixDefinition;
public static synthetic fun copy$default (Lcom/freeletics/khonshu/deeplinks/plugin/PrefixDefinition;Ljava/lang/String;Ljava/lang/String;ZILjava/lang/Object;)Lcom/freeletics/khonshu/deeplinks/plugin/PrefixDefinition;
public fun equals (Ljava/lang/Object;)Z
public final fun getAutoVerified ()Z
public final fun getHost ()Ljava/lang/String;
public final fun getScheme ()Ljava/lang/String;
public fun hashCode ()I
public fun toString ()Ljava/lang/String;
public static final synthetic fun write$Self (Lcom/freeletics/khonshu/deeplinks/plugin/PrefixDefinition;Lkotlinx/serialization/encoding/CompositeEncoder;Lkotlinx/serialization/descriptors/SerialDescriptor;)V
}

public final class com/freeletics/khonshu/deeplinks/plugin/PrefixDefinition$$serializer : kotlinx/serialization/internal/GeneratedSerializer {
public static final field INSTANCE Lcom/freeletics/khonshu/deeplinks/plugin/PrefixDefinition$$serializer;
public fun childSerializers ()[Lkotlinx/serialization/KSerializer;
public fun deserialize (Lkotlinx/serialization/encoding/Decoder;)Lcom/freeletics/khonshu/deeplinks/plugin/PrefixDefinition;
public synthetic fun deserialize (Lkotlinx/serialization/encoding/Decoder;)Ljava/lang/Object;
public fun getDescriptor ()Lkotlinx/serialization/descriptors/SerialDescriptor;
public fun serialize (Lkotlinx/serialization/encoding/Encoder;Lcom/freeletics/khonshu/deeplinks/plugin/PrefixDefinition;)V
public synthetic fun serialize (Lkotlinx/serialization/encoding/Encoder;Ljava/lang/Object;)V
public fun typeParametersSerializers ()[Lkotlinx/serialization/KSerializer;
}

public final class com/freeletics/khonshu/deeplinks/plugin/PrefixDefinition$Companion {
public final fun serializer ()Lkotlinx/serialization/KSerializer;
}

2 changes: 1 addition & 1 deletion deeplinks-plugin/deeplinks-plugin.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ plugins {
dependencies {
implementation(libs.toml)
implementation(libs.serialization)
implementation(projects.navigation)
implementation(projects.navigationTesting)

compileOnly(libs.android.gradle.api)

Expand Down
4 changes: 0 additions & 4 deletions deeplinks-plugin/rules.pro
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,6 @@

# Keep your public API so that it's callable from scripts
-keep class com.freeletics.khonshu.deeplinks.plugin.** { public *; }
-keepnames class kotlin.jvm.internal.DefaultConstructorMarker
-keepclassmembers @com.squareup.moshi.JsonClass @kotlin.Metadata class * {
synthetic <init>(...);
}

# No need to obfuscate class names
-dontobfuscate
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
@@ -1,6 +1,9 @@
package com.freeletics.khonshu.deeplinks.plugin

import com.freeletics.khonshu.navigation.internal.InternalNavigationApi
import com.freeletics.khonshu.navigation.deeplinks.DeepLinkDefinition
import com.freeletics.khonshu.navigation.deeplinks.DeepLinkDefinitions
import com.freeletics.khonshu.navigation.deeplinks.PatternDefinition
import com.freeletics.khonshu.navigation.deeplinks.PrefixDefinition
import java.io.File

private const val PLACEHOLDER = "<!-- DEEPLINK INTENT FILTERS -->"
Expand All @@ -16,6 +19,8 @@ internal fun configure(
"Did not find $PLACEHOLDER in given manifest ${inputManifestFile.absolutePath}"
}

check(configurationFile.exists())

val definitions = DeepLinkDefinitions.decodeFromString(configurationFile.readText())
val indentation = manifest[placeholderIndex].takeWhile { it == ' ' }
manifest[placeholderIndex] = intentFiltersFromConfig(definitions, indentation)
Expand Down Expand Up @@ -77,7 +82,6 @@ private class IntentFilterBuilder(
builder.appendLine("$indentation <category android:name=\"${category}\" />")
}

@OptIn(InternalNavigationApi::class)
fun appendData(scheme: String, host: String, pattern: PatternDefinition) {
val pathPattern = pattern.replacePlaceholders { ".*" }
builder.appendLine("$indentation <data")
Expand Down
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
Loading

0 comments on commit 9545218

Please sign in to comment.