Skip to content
Merged
Show file tree
Hide file tree
Changes from 10 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
96 changes: 0 additions & 96 deletions firebase-dataconnect/connectors/connectors.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
* limitations under the License.
*/

import com.google.firebase.dataconnect.gradle.plugin.UpdateDataConnectExecutableVersionsTask
import org.gradle.kotlin.dsl.withType
import org.jetbrains.kotlin.gradle.dsl.JvmTarget
import org.jetbrains.kotlin.gradle.tasks.KotlinJvmCompile
Expand Down Expand Up @@ -113,98 +112,3 @@ tasks.withType<KotlinJvmCompile>().configureEach {
compilerOptions.freeCompilerArgs.add("-Xexplicit-api=strict")
}
}

// 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 propertyNames =
object {
val version = "version"
val versions = "versions"
val updateMode = "updateMode"
val defaultVersion = "defaultVersion"
}

val singleVersion: String? = project.providers.gradleProperty(propertyNames.version).orNull
val multipleVersions: List<String>? =
project.providers.gradleProperty(propertyNames.versions).orNull?.split(',')
versions.set(
buildList {
singleVersion?.let { add(it) }
multipleVersions?.let { addAll(it) }
}
)

doFirst {
if (versions.get().isEmpty()) {
logger.warn(
"WARNING: no '${propertyNames.version}' or '${propertyNames.versions}' specified " +
"for task '$name'; no versions will be added to ${jsonFile.get()}. " +
"Try specifying something like '-P${propertyNames.version}=1.2.3' or " +
"'-P${propertyNames.versions}=1.2.3,4.5.6' on the gradle command line " +
"if you want to add versions (warning code bm6d5ezxzd)"
)
}
}

updateMode.set(
project.providers.gradleProperty(propertyNames.updateMode).map {
when (it) {
"overwrite" -> UpdateDataConnectExecutableVersionsTask.UpdateMode.Overwrite
"update" -> UpdateDataConnectExecutableVersionsTask.UpdateMode.Update
else ->
throw Exception(
"Invalid '${propertyNames.updateMode}' specified for task '$name': $it. " +
"Valid values are 'update' and 'overwrite'. " +
"Try specifying '-P${propertyNames.updateMode}=update' or " +
"'-P${propertyNames.updateMode}=overwrite' on the gradle command line. " +
"(error code v2e3cfqbnf)"
)
}
}
)

doFirst {
if (!updateMode.isPresent) {
logger.warn(
"WARNING: no '${propertyNames.updateMode}' specified for task '$name'; " +
"the default update mode of 'update' will be used when updating ${jsonFile.get()}. " +
"Try specifying '-P${propertyNames.updateMode}=update' or " +
"'-P${propertyNames.updateMode}=overwrite' on the gradle command line " +
"if you want a different update mode, or just want to be explicit about " +
"which update mode is in effect (warning code tjyscqmdne)"
)
}
}

defaultVersion.set(project.providers.gradleProperty(propertyNames.defaultVersion))

doFirst {
if (!defaultVersion.isPresent) {
logger.warn(
"WARNING: no '${propertyNames.defaultVersion}' specified for task '$name'; " +
"the default version will not be updated in ${jsonFile.get()}. " +
"Try specifying something like '-P${propertyNames.defaultVersion}=1.2.3' " +
"on the gradle command line if you want to update the default version " +
"(warning code vqrbrktx9f)"
)
}
}
}
13 changes: 13 additions & 0 deletions firebase-dataconnect/firebase-dataconnect.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
* limitations under the License.
*/

import com.google.firebase.dataconnect.gradle.plugin.DataConnectExecutableVersionsRegistry
import com.google.firebase.dataconnect.gradle.plugin.UpdateDataConnectExecutableVersionsTask
import org.gradle.kotlin.dsl.withType
import org.jetbrains.kotlin.gradle.dsl.JvmTarget
import org.jetbrains.kotlin.gradle.tasks.KotlinJvmCompile
Expand All @@ -24,6 +26,7 @@ plugins {
id("com.google.protobuf")
id("copy-google-services")
alias(libs.plugins.kotlinx.serialization)
id("com.google.firebase.dataconnect.gradle.plugin") apply false
}

firebaseLibrary {
Expand Down Expand Up @@ -163,3 +166,13 @@ tasks.withType<KotlinJvmCompile>().configureEach {
compilerOptions.freeCompilerArgs.add("-Xexplicit-api=strict")
}
}

// Registers a Gradle task that updates the JSON file that stores the list of Data Connect
// executable versions. The task gets the list of all versions from the Internet and then
// updates the JSON file with their sizes and hashes.
tasks.register<UpdateDataConnectExecutableVersionsTask>("updateJson") {
jsonFile.set(
file("gradleplugin/plugin/src/main/resources/${DataConnectExecutableVersionsRegistry.PATH}")
)
workDirectory.set(project.layout.buildDirectory.dir("updateJson"))
}
2 changes: 2 additions & 0 deletions firebase-dataconnect/gradleplugin/plugin/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ dependencies {
implementation(gradleKotlinDsl())
implementation(firebaseLibs.kotlinx.serialization.core)
implementation(firebaseLibs.kotlinx.serialization.json)
implementation("com.google.cloud:google-cloud-storage:2.56.0")
implementation("io.github.z4kn4fein:semver:3.0.0")
}

gradlePlugin {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ abstract class DataConnectExecutableDownloadTask : DefaultTask() {
.sorted()
.joinToString(", ")
val applicableVersions =
allVersions.filter { it.version == version && it.os == operatingSystem }
allVersions.filter { it.version.toString() == version && it.os == operatingSystem }

if (applicableVersions.isEmpty()) {
val message =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
*/
package com.google.firebase.dataconnect.gradle.plugin

import io.github.z4kn4fein.semver.LooseVersionSerializer
import io.github.z4kn4fein.semver.Version
import java.io.InputStream
import java.io.OutputStream
import kotlinx.serialization.ExperimentalSerializationApi
Expand All @@ -38,6 +40,7 @@ object DataConnectExecutableVersionsRegistry {
Json {
prettyPrint = true
prettyPrintIndent = " "
allowTrailingComma = true
}
}

Expand All @@ -59,13 +62,13 @@ object DataConnectExecutableVersionsRegistry {

@Serializable
data class Root(
val defaultVersion: String,
@Serializable(with = LooseVersionSerializer::class) val defaultVersion: Version,
val versions: List<VersionInfo>,
)

@Serializable
data class VersionInfo(
val version: String,
@Serializable(with = LooseVersionSerializer::class) val version: Version,
@Serializable(with = OperatingSystemSerializer::class) val os: OperatingSystem,
val size: Long,
val sha512DigestHex: String,
Expand All @@ -79,24 +82,24 @@ object DataConnectExecutableVersionsRegistry {
)

override fun deserialize(decoder: Decoder): OperatingSystem =
when (val name = decoder.decodeString()) {
"windows" -> OperatingSystem.Windows
"macos" -> OperatingSystem.MacOS
"linux" -> OperatingSystem.Linux
else ->
throw DataConnectGradleException(
decoder.decodeString().let { serializedValue ->
OperatingSystem.entries.singleOrNull { it.serializedValue == serializedValue }
?: throw DataConnectGradleException(
"nd5z2jk4hr",
"Unknown operating system: $name (must be windows, macos, or linux)"
"Unknown operating system: $serializedValue " +
"(must be one of ${OperatingSystem.entries.joinToString { it.serializedValue }})"
)
}

override fun serialize(encoder: Encoder, value: OperatingSystem) =
encoder.encodeString(
when (value) {
OperatingSystem.Windows -> "windows"
OperatingSystem.MacOS -> "macos"
OperatingSystem.Linux -> "linux"
}
)
encoder.encodeString(value.serializedValue)
}

val OperatingSystem.serializedValue: String
get() =
when (this) {
OperatingSystem.Windows -> "windows"
OperatingSystem.MacOS -> "macos"
OperatingSystem.Linux -> "linux"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ class DataConnectProviders(
val defaultVersion: Provider<DataConnectExecutable> =
project.provider {
val root = DataConnectExecutableVersionsRegistry.load()
DataConnectExecutable.Version(root.defaultVersion)
DataConnectExecutable.Version(root.defaultVersion.toString())
}

valueFromLocalSettings
Expand Down
Loading
Loading