Skip to content

Commit

Permalink
Merge branch 'main' into tomandersen/cleanupProtos
Browse files Browse the repository at this point in the history
  • Loading branch information
tom-andersen authored Oct 9, 2024
2 parents a56581f + b49d448 commit 8c9a3a4
Show file tree
Hide file tree
Showing 11 changed files with 532 additions and 242 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,12 @@ package com.google.firebase.dataconnect.testutil
import androidx.test.ext.junit.runners.AndroidJUnit4
import com.google.firebase.dataconnect.ConnectorConfig
import com.google.firebase.util.nextAlphanumericString
import io.kotest.property.Arb
import io.kotest.property.RandomSource
import io.kotest.property.arbitrary.Codepoint
import io.kotest.property.arbitrary.alphanumeric
import io.kotest.property.arbitrary.arbitrary
import io.kotest.property.arbitrary.string
import kotlin.random.Random
import org.junit.Rule
import org.junit.rules.TestName
Expand All @@ -40,6 +45,31 @@ abstract class DataConnectIntegrationTestBase {

val rs: RandomSource by randomSeedTestRule.rs

/**
* Generates and returns a string containing random alphanumeric characters, including the name of
* the currently-running test as returned from [testName].
*
* @param string The [Arb] to use to generate the random string; if not specified, then an [Arb]
* that generates strings of 20 alphanumeric characters is used.
* @param prefix A prefix to include in the returned string; if null (the default) then no prefix
* will be included.
* @return a string containing random characters and incorporating the other information
* identified above.
*/
fun Arb.Companion.alphanumericString(
string: Arb<String> = Arb.string(20, Codepoint.alphanumeric()),
prefix: String? = null,
): Arb<String> = arbitrary {
buildString {
if (prefix != null) {
append(prefix)
}
append(testName)
append("_")
append(string.bind())
}
}

companion object {
val testConnectorConfig: ConnectorConfig
get() =
Expand Down
39 changes: 39 additions & 0 deletions firebase-dataconnect/connectors/connectors.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
*/

import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
import com.google.firebase.dataconnect.gradle.plugin.UpdateDataConnectExecutableVersionsTask

plugins {
id("com.android.library")
Expand Down Expand Up @@ -109,3 +110,41 @@ tasks.withType<KotlinCompile>().all {
}
}
}

// Adds a Gradle task that updates the JSON file that stores the list of Data Connect
// executable versions.
//
// Example 1: Add versions 1.4.3 and 1.4.4 to the JSON file, and set 1.4.4 as the default:
// ../../gradlew -Pversions=1.4.3,1.4.4 -PdefaultVersion=1.4.4 updateJson --info
//
// Example 2: Add version 1.2.3 to the JSON file, but do not change the default version:
// ../../gradlew -Pversion=1.2.3 updateJson --info
//
// The `--info` argument can be omitted; it merely controls the level of log output.
tasks.register<UpdateDataConnectExecutableVersionsTask>("updateJson") {
outputs.upToDateWhen { false }
jsonFile.set(project.layout.projectDirectory.file(
"../gradleplugin/plugin/src/main/resources/com/google/firebase/dataconnect/gradle/" +
"plugin/DataConnectExecutableVersions.json"))
workDirectory.set(project.layout.buildDirectory.dir("updateJson"))

val singleVersion: String? = project.providers.gradleProperty("version").orNull
val multipleVersions: List<String>? = project.providers.gradleProperty("versions").orNull?.split(',')
versions.set(buildList {
singleVersion?.let{add(it)}
multipleVersions?.let{addAll(it)}
if (isEmpty()) {
throw Exception("bm6d5ezxzd 'version' or 'versions' property must be specified")
}
})

updateMode.set(project.providers.gradleProperty("updateMode").map {
when (it) {
"overwrite" -> UpdateDataConnectExecutableVersionsTask.UpdateMode.Overwrite
"update" -> UpdateDataConnectExecutableVersionsTask.UpdateMode.Update
else -> throw Exception("ahe4zadcjs 'updateMode' must be 'overwrite' or 'update', but got: $it")
}
})

defaultVersion.set(project.providers.gradleProperty("defaultVersion"))
}
Loading

0 comments on commit 8c9a3a4

Please sign in to comment.