-
Notifications
You must be signed in to change notification settings - Fork 7.4k
dataconnect: integrate codegen into the gradle build #2569
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
dconeybe
wants to merge
82
commits into
master
Choose a base branch
from
dconeybe/dataconnect/GradleCodegen
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 2 commits
Commits
Show all changes
82 commits
Select commit
Hold shift + click to select a range
87c4832
dataconnect: integrate codegen into the gradle build
dconeybe bcbc8df
minor doc cleanups
dconeybe e451068
Merge remote-tracking branch 'origin/master' into GradleCodegen
dconeybe 985d3f2
workflows/android.yml: change node-version to 20 (was 22) based on re…
dconeybe 5ab7abe
README.md: mark gradle codegen tasks as "optional"
dconeybe 9005866
movie-connector/connector.yaml: update comment to give a concrete exa…
dconeybe 1fce124
get rid of ktfmt and spotless, since ktlint is what is used in this repo
dconeybe 510f258
ktlint format the code in dataconnect/buildSrc by running ./gradlew k…
dconeybe a66e0ae
add the ability to explictly specify the path to the npm executable
dconeybe b598af6
First start at supporting a nodeExecutable setting in dataconnect.loc…
dconeybe ee27641
enable specifying nodeExecutable in dataconnect.local.toml as well as…
dconeybe fda7364
rename dataconnect.local.toml -> dataconnect.local.toml.example
dconeybe f188cf1
fix calling npm when node is not in the path
dconeybe 1e9d05b
minor plugin refactor
dconeybe c71a458
move tasks into their own package
dconeybe 957dfed
more file reorganization
dconeybe 6284011
format code with ktlint
dconeybe b65499c
REVERT ME: detect system info
dconeybe 427e5d7
OperatingSystemProvider.kt added
dconeybe d35b123
download nodejs binary distro via ktor
dconeybe 16214d1
actually download and save to a file
dconeybe 3704326
download shasums as well
dconeybe db94e28
add node.js release signing keys
dconeybe 3ee1118
verify downloaded nodejs signatures
dconeybe 608dd81
minor refactor
dconeybe 54b6d8b
verify the sha256 hash of the nodejs binary distribution
dconeybe d01b098
NodeJS -> NodeJs
dconeybe 67319da
refactor
dconeybe 4600046
unzip too
dconeybe 0c41373
ktlint format the code in dataconnect/buildSrc by running ./gradlew k…
dconeybe 8ef8480
wire up node executable between tasks
dconeybe 9fa40e4
improvements
dconeybe 668a7de
fix untarring symlinks
dconeybe dc010b1
DownloadNodeJsTask.kt fixed
dconeybe f09fc20
it finally works in android studio
dconeybe 585c9b2
fixed it all
dconeybe a4e16ea
ktlint
dconeybe ee81688
Merge remote-tracking branch 'origin/master' into GradleCodegen
dconeybe 6b771be
OperatingSystem.kt: unhardcode linux-x64 (oops!)
dconeybe 343f660
.github/workflows/android.yml: remove installation of node.js since t…
dconeybe e47c9ec
specify --stacktrace to gradle when run from github actions, to assis…
dconeybe fd6d44a
specify --info to gradle when run from github actions, to assist with…
dconeybe c021ea8
OperatingSystem.kt: fix os detection: got x86 and x86_64 backwards
dconeybe 01cce18
DownloadNodeJsTask.kt: make it compatible with both org.apache.common…
dconeybe 6fd0016
DownloadNodeJsTask.kt: more fixes for NoSuchMethodError
dconeybe 2899860
Allow nodeVersion to be specified in build.gradle.kts
dconeybe 882f073
suppoer caching
dconeybe ca5a06b
code cleanup
dconeybe e2f50e9
skip building if dataConnectConfigDir is not set
dconeybe 250d11d
ktlint format the code in dataconnect/buildSrc by running ./gradlew k…
dconeybe d803c27
revert changes to dataconnect.local.toml
dconeybe 38b4a40
Use ExecOperations since project.exec is deprecated
dconeybe e5d6589
dataconnect.local.toml.example deleted, as it is obsolete
dconeybe bd49216
remove --info --stacktrace from CI gradle invocation; it was only the…
dconeybe 096bd45
fix ExecOperations usage
dconeybe acc8359
rename the gradle property DataConnectGradleCacheDir to dataconnect.g…
dconeybe 553e816
fix gradle configuration cache issues
dconeybe 1e5d5c4
on the way to a cacheable task
dconeybe 69c1961
DownloadNodeJsBinaryDistributionArchiveTask.kt started
dconeybe e379f48
DownloadNodeJsBinaryDistributionArchiveTask.kt more work
dconeybe 22c3ed7
.gitignore: add .kotlin
dconeybe 60765f4
DownloadNodeJsBinaryDistributionArchiveTask.kt implements downloading…
dconeybe 8174272
download SHASUMS256.txt.asc
dconeybe 024039d
Sha256SignatureVerifier.kt added
dconeybe 2fa6f94
code cleanup
dconeybe 032f17c
DownloadNodeJsBinaryDistributionArchiveTask.kt: done
dconeybe 8947f13
tweaks
dconeybe 14aae3f
remove manual caching
dconeybe 2f7ff97
enable kotlin explicit api mode
dconeybe ecf3fc1
ExtractArchiveTask.kt skeleton added
dconeybe 7747535
work
dconeybe fd72edd
fix build
dconeybe 8159400
implement xz
dconeybe 1ef9852
refactor DataConnectTaskBase
dconeybe d843aeb
pathPrefixComponentStripCount impl started
dconeybe fdb816c
strip prefix
dconeybe e830d63
more work
dconeybe a9f9ceb
show elapsed time
dconeybe 1e1af6c
tweak elapsed time message
dconeybe 68bffd3
big refactor
dconeybe ba411ed
ktlint
dconeybe b88e2e8
Merge remote-tracking branch 'origin/master' into GradleCodegen
dconeybe File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
/* | ||
* Copyright 2024 Google LLC | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
plugins { | ||
// See https://docs.gradle.org/current/userguide/kotlin_dsl.html#sec:kotlin-dsl_plugin | ||
`kotlin-dsl` | ||
alias(libs.plugins.spotless) | ||
} | ||
|
||
java { toolchain { languageVersion.set(JavaLanguageVersion.of(17)) } } | ||
|
||
dependencies { | ||
implementation(libs.android.gradlePlugin.api) | ||
implementation(libs.snakeyaml) | ||
} | ||
|
||
gradlePlugin { | ||
plugins { | ||
create("dataconnect") { | ||
id = "com.google.firebase.example.dataconnect.gradle" | ||
implementationClass = "com.google.firebase.example.dataconnect.gradle.DataConnectGradlePlugin" | ||
} | ||
} | ||
} | ||
|
||
spotless { | ||
kotlin { ktfmt(libs.versions.ktfmt.get()).googleStyle() } | ||
kotlinGradle { | ||
target("*.gradle.kts") | ||
ktfmt(libs.versions.ktfmt.get()).googleStyle() | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
pluginManagement { | ||
repositories { | ||
gradlePluginPortal() | ||
google() | ||
mavenCentral() | ||
} | ||
} | ||
|
||
dependencyResolutionManagement { | ||
repositories { | ||
google() | ||
mavenCentral() | ||
} | ||
versionCatalogs { create("libs") { from(files("../../gradle/libs.versions.toml")) } } | ||
} |
75 changes: 75 additions & 0 deletions
75
...ct/buildSrc/src/main/kotlin/com/google/firebase/example/dataconnect/gradle/CodegenTask.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
/* | ||
* Copyright 2024 Google LLC | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.google.firebase.example.dataconnect.gradle | ||
|
||
import java.io.File | ||
import org.gradle.api.DefaultTask | ||
import org.gradle.api.file.DirectoryProperty | ||
import org.gradle.api.file.RegularFileProperty | ||
import org.gradle.api.tasks.InputDirectory | ||
import org.gradle.api.tasks.InputFile | ||
import org.gradle.api.tasks.Internal | ||
import org.gradle.api.tasks.OutputDirectory | ||
import org.gradle.api.tasks.TaskAction | ||
|
||
abstract class CodegenTask : DefaultTask() { | ||
|
||
@get:InputDirectory abstract val dataConnectConfigDir: DirectoryProperty | ||
|
||
@get:InputFile abstract val firebaseExecutable: RegularFileProperty | ||
|
||
@get:OutputDirectory abstract val outputDirectory: DirectoryProperty | ||
|
||
@get:Internal abstract val tweakedDataConnectConfigDir: DirectoryProperty | ||
|
||
@TaskAction | ||
fun run() { | ||
val dataConnectConfigDir = dataConnectConfigDir.get().asFile | ||
val firebaseExecutable = firebaseExecutable.get().asFile | ||
val outputDirectory = outputDirectory.get().asFile | ||
val tweakedDataConnectConfigDir = tweakedDataConnectConfigDir.get().asFile | ||
|
||
logger.info("dataConnectConfigDir: {}", dataConnectConfigDir) | ||
logger.info("firebaseExecutable: {}", firebaseExecutable) | ||
logger.info("outputDirectory: {}", outputDirectory) | ||
logger.info("tweakedDataConnectConfigDir: {}", tweakedDataConnectConfigDir) | ||
|
||
project.delete(outputDirectory) | ||
project.delete(tweakedDataConnectConfigDir) | ||
project.mkdir(tweakedDataConnectConfigDir) | ||
|
||
project.copy { | ||
from(dataConnectConfigDir) | ||
into(tweakedDataConnectConfigDir) | ||
} | ||
tweakConnectorYamlFiles(tweakedDataConnectConfigDir, outputDirectory.absolutePath) | ||
|
||
runCommand(File(tweakedDataConnectConfigDir, "generate.log.txt")) { | ||
commandLine(firebaseExecutable.absolutePath, "--debug", "dataconnect:sdk:generate") | ||
// Specify a fake project because dataconnect:sdk:generate unnecessarily | ||
// requires one. The actual value does not matter. | ||
args("--project", "zzyzx") | ||
workingDir(tweakedDataConnectConfigDir) | ||
} | ||
} | ||
|
||
internal fun configureFrom(providers: MyVariantProviders) { | ||
dataConnectConfigDir.set(providers.dataConnectConfigDir) | ||
firebaseExecutable.set(providers.firebaseExecutable) | ||
tweakedDataConnectConfigDir.set(providers.buildDirectory.map { it.dir("config") }) | ||
} | ||
} |
42 changes: 42 additions & 0 deletions
42
...nnect/buildSrc/src/main/kotlin/com/google/firebase/example/dataconnect/gradle/Commands.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
/* | ||
* Copyright 2024 Google LLC | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.google.firebase.example.dataconnect.gradle | ||
|
||
import java.io.File | ||
import org.gradle.api.Task | ||
import org.gradle.process.ExecSpec | ||
|
||
internal fun Task.runCommand(logFile: File, configure: ExecSpec.() -> Unit) { | ||
val effectiveLogFile = if (logger.isInfoEnabled) null else logFile | ||
val result = | ||
effectiveLogFile?.outputStream().use { logStream -> | ||
project.runCatching { | ||
exec { | ||
isIgnoreExitValue = false | ||
if (logStream !== null) { | ||
standardOutput = logStream | ||
errorOutput = logStream | ||
} | ||
configure(this) | ||
} | ||
} | ||
} | ||
result.onFailure { exception -> | ||
effectiveLogFile?.let { logger.warn("{}", it.readText()) } | ||
throw exception | ||
} | ||
} |
89 changes: 89 additions & 0 deletions
89
...c/src/main/kotlin/com/google/firebase/example/dataconnect/gradle/ConnectorYamlTweaking.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
/* | ||
* Copyright 2024 Google LLC | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.google.firebase.example.dataconnect.gradle | ||
|
||
import java.io.File | ||
import org.gradle.api.GradleException | ||
import org.gradle.api.Task | ||
import org.yaml.snakeyaml.Yaml | ||
|
||
internal fun Task.tweakConnectorYamlFiles(dir: File, newOutputDir: String) { | ||
logger.info("Tweaking connector.yaml files in {}", dir.absolutePath) | ||
dir.walk().forEach { file -> | ||
if (file.isFile && file.name == "connector.yaml") { | ||
tweakConnectorYamlFile(file, newOutputDir) | ||
} else { | ||
logger.debug("skipping file: {}", file.absolutePath) | ||
} | ||
} | ||
} | ||
|
||
internal fun Task.tweakConnectorYamlFile(file: File, newOutputDir: String) { | ||
logger.info("Tweaking connector.yaml file: {}", file.absolutePath) | ||
|
||
fun Map<*, *>.withTweakedKotlinSdk() = | ||
filterKeys { it == "kotlinSdk" } | ||
.mapValues { (_, value) -> | ||
val kotlinSdkMap = | ||
value as? Map<*, *> | ||
?: throw GradleException( | ||
"Parsing ${file.absolutePath} failed: \"kotlinSdk\" is " + | ||
(if (value === null) "null" else value::class.qualifiedName) + | ||
", but expected ${Map::class.qualifiedName} " + | ||
"(error code m697s27yxn)" | ||
) | ||
kotlinSdkMap.mapValues { (key, value) -> | ||
if (key == "outputDir") { | ||
newOutputDir | ||
} else { | ||
value | ||
} | ||
} | ||
} | ||
|
||
fun Map<*, *>.withTweakedGenerateNode() = mapValues { (key, value) -> | ||
if (key != "generate") { | ||
value | ||
} else { | ||
val generateMap = | ||
value as? Map<*, *> | ||
?: throw GradleException( | ||
"Parsing ${file.absolutePath} failed: \"generate\" is " + | ||
(if (value === null) "null" else value::class.qualifiedName) + | ||
", but expected ${Map::class.qualifiedName} " + | ||
"(error code 9c2p857gq6)" | ||
) | ||
generateMap.withTweakedKotlinSdk() | ||
} | ||
} | ||
|
||
val yaml = Yaml() | ||
val rootObject = file.reader(Charsets.UTF_8).use { reader -> yaml.load<Any?>(reader) } | ||
|
||
val rootMap = | ||
rootObject as? Map<*, *> | ||
?: throw GradleException( | ||
"Parsing ${file.absolutePath} failed: root is " + | ||
(if (rootObject === null) "null" else rootObject::class.qualifiedName) + | ||
", but expected ${Map::class.qualifiedName} " + | ||
"(error code 45dw8jx8jd)" | ||
) | ||
|
||
val newRootMap = rootMap.withTweakedGenerateNode() | ||
|
||
file.writer(Charsets.UTF_8).use { writer -> yaml.dump(newRootMap, writer) } | ||
} |
24 changes: 24 additions & 0 deletions
24
...rc/src/main/kotlin/com/google/firebase/example/dataconnect/gradle/DataConnectExtension.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
/* | ||
* Copyright 2024 Google LLC | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.google.firebase.example.dataconnect.gradle | ||
|
||
import java.io.File | ||
|
||
interface DataConnectExtension { | ||
var firebaseToolsVersion: String? | ||
var dataConnectConfigDir: File? | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.