Skip to content

Commit d01fa54

Browse files
committed
Merge branch 'main' into ep/vertex-serializable
2 parents 1c5d1a7 + f2d05d6 commit d01fa54

File tree

17 files changed

+1503
-13
lines changed

17 files changed

+1503
-13
lines changed

firebase-dynamic-links/CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22

33

44
# 22.1.0
5-
* [changed] Added deprecation annotations to the public API. See https://firebase.google.com/support/dynamic-links-faq for further context.
5+
* [deprecated] `firebase-dynamic-links` is deprecated. For information about timelines and alternatives,
6+
see the [irebase-dynamic-links deprecation FAQ](/support/dynamic-links-faq).
67

78

89
## Kotlin

firebase-vertexai/README.md

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,5 @@
11
# Firebase Vertex AI SDK
22

3-
**Preview**: Vertex AI for Firebase is in Public Preview, which means that the product is
4-
not subject to any SLA or deprecation policy and could change in backwards-incompatible
5-
ways.
6-
73
For developer documentation, please visit https://firebase.google.com/docs/vertex-ai.
84
This README is for contributors building and running tests for the SDK.
95

firebase-vertexai/src/test/java/com/google/firebase/vertexai/UnarySnapshotTests.kt

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ import com.google.firebase.vertexai.type.UnsupportedUserLocationException
3333
import com.google.firebase.vertexai.util.goldenUnaryFile
3434
import com.google.firebase.vertexai.util.shouldNotBeNullOrEmpty
3535
import io.kotest.assertions.throwables.shouldThrow
36+
import io.kotest.inspectors.forAtLeastOne
37+
import io.kotest.matchers.collections.shouldContain
3638
import io.kotest.matchers.collections.shouldNotBeEmpty
3739
import io.kotest.matchers.nulls.shouldNotBeNull
3840
import io.kotest.matchers.should
@@ -42,6 +44,7 @@ import io.kotest.matchers.string.shouldContain
4244
import io.kotest.matchers.string.shouldNotBeEmpty
4345
import io.kotest.matchers.types.shouldBeInstanceOf
4446
import io.ktor.http.HttpStatusCode
47+
import java.util.Calendar
4548
import kotlin.time.Duration.Companion.seconds
4649
import kotlinx.coroutines.withTimeout
4750
import kotlinx.serialization.json.JsonPrimitive
@@ -213,6 +216,11 @@ internal class UnarySnapshotTests {
213216
withTimeout(testTimeout) {
214217
val exception = shouldThrow<ResponseStoppedException> { model.generateContent("prompt") }
215218
exception.response.candidates.first().finishReason shouldBe FinishReason.SAFETY
219+
exception.response.candidates.first().safetyRatings.forAtLeastOne {
220+
it.category shouldBe HarmCategory.HARASSMENT
221+
it.probability shouldBe HarmProbability.LOW
222+
it.severity shouldBe HarmSeverity.LOW
223+
}
216224
}
217225
}
218226

@@ -233,6 +241,10 @@ internal class UnarySnapshotTests {
233241

234242
response.candidates.isEmpty() shouldBe false
235243
response.candidates.first().citationMetadata?.citations?.size shouldBe 3
244+
response.candidates.first().citationMetadata?.citations?.forAtLeastOne {
245+
it.publicationDate?.get(Calendar.YEAR) shouldBe 2019
246+
it.publicationDate?.get(Calendar.DAY_OF_MONTH) shouldBe 10
247+
}
236248
}
237249
}
238250

firebase-vertexai/update_responses.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
# This script replaces mock response files for Vertex AI unit tests with a fresh
1818
# clone of the shared repository of Vertex AI test data.
1919

20-
RESPONSES_VERSION='v3.*' # The major version of mock responses to use
20+
RESPONSES_VERSION='v5.*' # The major version of mock responses to use
2121
REPO_NAME="vertexai-sdk-test-data"
2222
REPO_LINK="https://github.com/FirebaseExtended/$REPO_NAME.git"
2323

plugins/build.gradle.kts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,11 +66,18 @@ dependencies {
6666
implementation("com.google.code.gson:gson:2.8.9")
6767
implementation(libs.android.gradlePlugin.gradle)
6868
implementation(libs.android.gradlePlugin.builder.test.api)
69+
implementation("io.github.pdvrieze.xmlutil:serialization-jvm:0.90.3") {
70+
exclude("org.jetbrains.kotlinx", "kotlinx-serialization-json")
71+
exclude("org.jetbrains.kotlinx", "kotlinx-serialization-core")
72+
}
6973

74+
testImplementation(gradleTestKit())
7075
testImplementation(libs.bundles.kotest)
76+
testImplementation(libs.mockk)
7177
testImplementation(libs.junit)
7278
testImplementation(libs.truth)
7379
testImplementation("commons-io:commons-io:2.15.1")
80+
testImplementation(kotlin("test"))
7481
}
7582

7683
gradlePlugin {

plugins/src/main/java/com/google/firebase/gradle/plugins/BaseFirebaseLibraryPlugin.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ package com.google.firebase.gradle.plugins
1818

1919
import com.android.build.gradle.LibraryExtension
2020
import com.google.firebase.gradle.plugins.ci.Coverage
21+
import com.google.firebase.gradle.plugins.services.GMavenService
2122
import java.io.File
2223
import java.nio.file.Paths
2324
import org.gradle.api.Plugin
@@ -52,6 +53,7 @@ import org.w3c.dom.Element
5253
abstract class BaseFirebaseLibraryPlugin : Plugin<Project> {
5354
protected fun setupDefaults(project: Project, library: FirebaseLibraryExtension) {
5455
with(library) {
56+
project.gradle.sharedServices.registerIfAbsent<GMavenService, _>("gmaven")
5557
previewMode.convention("")
5658
publishJavadoc.convention(true)
5759
artifactId.convention(project.name)

plugins/src/main/java/com/google/firebase/gradle/plugins/GradleExtensions.kt

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,11 @@ import org.gradle.api.attributes.Attribute
3030
import org.gradle.api.attributes.AttributeContainer
3131
import org.gradle.api.plugins.PluginManager
3232
import org.gradle.api.provider.Provider
33+
import org.gradle.api.services.BuildService
34+
import org.gradle.api.services.BuildServiceParameters
35+
import org.gradle.api.services.BuildServiceRegistry
36+
import org.gradle.api.services.BuildServiceSpec
3337
import org.gradle.kotlin.dsl.apply
34-
import org.gradle.kotlin.dsl.provideDelegate
3538
import org.gradle.workers.WorkAction
3639
import org.gradle.workers.WorkParameters
3740
import org.gradle.workers.WorkQueue
@@ -244,3 +247,19 @@ fun LibraryAndroidComponentsExtension.onReleaseVariants(
244247
) {
245248
onVariants(selector().withBuildType("release"), callback)
246249
}
250+
251+
/**
252+
* Register a build service under the specified [name], if it hasn't been registered already.
253+
*
254+
* ```
255+
* project.gradle.sharedServices.registerIfAbsent<GMavenService, _>("gmaven")
256+
* ```
257+
*
258+
* @param T The build service class to register
259+
* @param P The parameters class for the build service to register
260+
* @param name The name to register the build service under
261+
* @param config An optional configuration block to setup the build service with
262+
*/
263+
inline fun <reified T : BuildService<P>, reified P : BuildServiceParameters> BuildServiceRegistry
264+
.registerIfAbsent(name: String, noinline config: BuildServiceSpec<P>.() -> Unit = {}) =
265+
registerIfAbsent(name, T::class.java, config)

plugins/src/main/java/com/google/firebase/gradle/plugins/KotlinExtensions.kt

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,9 @@
1717
package com.google.firebase.gradle.plugins
1818

1919
import java.io.File
20+
import java.io.InputStream
2021
import org.w3c.dom.Element
22+
import org.w3c.dom.Node
2123
import org.w3c.dom.NodeList
2224

2325
/** Replaces all matching substrings with an empty string (nothing) */
@@ -124,6 +126,13 @@ fun Element.findOrCreate(tag: String): Element =
124126
fun Element.findElementsByTag(tag: String) =
125127
getElementsByTagName(tag).children().mapNotNull { it as? Element }
126128

129+
/**
130+
* Returns the text of an attribute, if it exists.
131+
*
132+
* @param name The name of the attribute to get the text for
133+
*/
134+
fun Node.textByAttributeOrNull(name: String) = attributes?.getNamedItem(name)?.textContent
135+
127136
/**
128137
* Yields the items of this [NodeList] as a [Sequence].
129138
*
@@ -267,6 +276,19 @@ infix fun <T> List<T>.diff(other: List<T>): List<Pair<T?, T?>> {
267276
*/
268277
fun <T> List<T>.coerceToSize(targetSize: Int) = List(targetSize) { getOrNull(it) }
269278

279+
/**
280+
* Writes the [InputStream] to this file.
281+
*
282+
* While this method _does_ close the generated output stream, it's the callers responsibility to
283+
* close the passed [stream].
284+
*
285+
* @return This [File] instance for chaining.
286+
*/
287+
fun File.writeStream(stream: InputStream): File {
288+
outputStream().use { stream.copyTo(it) }
289+
return this
290+
}
291+
270292
/**
271293
* The [path][File.path] represented as a qualified unix path.
272294
*

plugins/src/main/java/com/google/firebase/gradle/plugins/ModuleVersion.kt

Lines changed: 29 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ enum class PreReleaseVersionType {
5757
* Where `Type` is a case insensitive string of any [PreReleaseVersionType], and `Build` is a two
5858
* digit number (single digits should have a leading zero).
5959
*
60-
* Note that `build` will always be present as starting at one by defalt. That is, the following
60+
* Note that `build` will always be present as starting at one by default. That is, the following
6161
* transform occurs:
6262
* ```
6363
* "12.13.1-beta" // 12.13.1-beta01
@@ -92,7 +92,7 @@ data class PreReleaseVersion(val type: PreReleaseVersionType, val build: Int = 1
9292
*/
9393
fun fromStringsOrNull(type: String, build: String): PreReleaseVersion? =
9494
runCatching {
95-
val preType = PreReleaseVersionType.valueOf(type.toUpperCase())
95+
val preType = PreReleaseVersionType.valueOf(type.uppercase())
9696
val buildNumber = build.takeUnless { it.isBlank() }?.toInt() ?: 1
9797

9898
PreReleaseVersion(preType, buildNumber)
@@ -115,7 +115,7 @@ data class PreReleaseVersion(val type: PreReleaseVersionType, val build: Int = 1
115115
* PreReleaseVersion(RC, 12).toString() // "rc12"
116116
* ```
117117
*/
118-
override fun toString() = "${type.name.toLowerCase()}${build.toString().padStart(2, '0')}"
118+
override fun toString() = "${type.name.lowercase()}${build.toString().padStart(2, '0')}"
119119
}
120120

121121
/**
@@ -140,7 +140,7 @@ data class ModuleVersion(
140140
) : Comparable<ModuleVersion> {
141141

142142
/** Formatted as `MAJOR.MINOR.PATCH-PRE` */
143-
override fun toString() = "$major.$minor.$patch${pre?.let { "-${it.toString()}" } ?: ""}"
143+
override fun toString() = "$major.$minor.$patch${pre?.let { "-$it" } ?: ""}"
144144

145145
override fun compareTo(other: ModuleVersion) =
146146
compareValuesBy(
@@ -149,7 +149,7 @@ data class ModuleVersion(
149149
{ it.major },
150150
{ it.minor },
151151
{ it.patch },
152-
{ it.pre == null }, // a version with no prerelease version takes precedence
152+
{ it.pre == null }, // a version with no pre-release version takes precedence
153153
{ it.pre },
154154
)
155155

@@ -176,7 +176,7 @@ data class ModuleVersion(
176176
* ```
177177
*/
178178
val VERSION_REGEX =
179-
"(?<major>\\d+)\\.(?<minor>\\d+)\\.(?<patch>\\d+)(?:\\-\\b)?(?<pre>\\w\\D+)?(?<build>\\B\\d+)?"
179+
"(?<major>\\d+)\\.(?<minor>\\d+)\\.(?<patch>\\d+)(?:-\\b)?(?<pre>\\w\\D+)?(?<build>\\B\\d+)?"
180180
.toRegex()
181181

182182
/**
@@ -209,6 +209,29 @@ data class ModuleVersion(
209209
}
210210
}
211211
.getOrNull()
212+
213+
/**
214+
* Parse a [ModuleVersion] from a string.
215+
*
216+
* You should use [fromStringOrNull] when you don't know the `artifactId` of the corresponding
217+
* artifact, if you don't need to throw on failure, or if you need to throw a more specific
218+
* message.
219+
*
220+
* This method exists to cover the common ground of getting [ModuleVersion] representations of
221+
* artifacts.
222+
*
223+
* @param artifactId The artifact that this version belongs to. Will be used in the error
224+
* message on failure.
225+
* @param version The version to parse into a [ModuleVersion].
226+
* @return A [ModuleVersion] created from the string.
227+
* @throws IllegalArgumentException If the string doesn't represent a valid semver version.
228+
* @see fromStringOrNull
229+
*/
230+
fun fromString(artifactId: String, version: String): ModuleVersion =
231+
fromStringOrNull(version)
232+
?: throw IllegalArgumentException(
233+
"Invalid module version found for '${artifactId}': $version"
234+
)
212235
}
213236

214237
/**

0 commit comments

Comments
 (0)