Skip to content

Commit 095f048

Browse files
committed
Merge branch 'master' of https://github.com/firebase/firebase-android-sdk into rpf-add-coroutines-common-ktx
2 parents 5131b74 + ed10eb5 commit 095f048

File tree

71 files changed

+1360
-1020
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

71 files changed

+1360
-1020
lines changed

buildSrc/src/main/java/com/google/firebase/gradle/bomgenerator/BomGeneratorTask.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ public class BomGeneratorTask extends DefaultTask {
5454
"com.google.firebase:firebase-analytics-ktx",
5555
"com.google.firebase:firebase-appcheck-debug",
5656
"com.google.firebase:firebase-appcheck-debug-testing",
57+
"com.google.firebase:firebase-appcheck-ktx",
5758
"com.google.firebase:firebase-appcheck-playintegrity",
5859
"com.google.firebase:firebase-appcheck-safetynet",
5960
"com.google.firebase:firebase-appcheck",

buildSrc/src/main/java/com/google/firebase/gradle/plugins/DackkaGenerationTask.kt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package com.google.firebase.gradle.plugins
33
import java.io.File
44
import javax.inject.Inject
55
import org.gradle.api.DefaultTask
6+
import org.gradle.api.file.FileCollection
67
import org.gradle.api.provider.ListProperty
78
import org.gradle.api.provider.Property
89
import org.gradle.api.provider.SetProperty
@@ -38,7 +39,7 @@ abstract class GenerateDocumentationTaskExtension : DefaultTask() {
3839
abstract val dackkaJarFile: Property<File>
3940

4041
@get:[InputFiles Classpath]
41-
abstract val dependencies: ListProperty<File>
42+
abstract val dependencies: Property<FileCollection>
4243

4344
@get:InputFiles
4445
@get:PathSensitive(PathSensitivity.RELATIVE)
@@ -127,7 +128,8 @@ abstract class GenerateDocumentationTask @Inject constructor(
127128
"android" to "https://developer.android.com/reference/kotlin/",
128129
"google" to "https://developers.google.com/android/reference/",
129130
"firebase" to "https://firebase.google.com/docs/reference/kotlin/",
130-
"coroutines" to "https://kotlinlang.org/api/kotlinx.coroutines/kotlinx-coroutines-core/"
131+
"coroutines" to "https://kotlinlang.org/api/kotlinx.coroutines/kotlinx-coroutines-core/",
132+
"kotlin" to "https://kotlinlang.org/api/latest/jvm/stdlib/"
131133
)
132134

133135
return packageLists.get().map {

buildSrc/src/main/java/com/google/firebase/gradle/plugins/DackkaPlugin.kt

Lines changed: 67 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -90,26 +90,23 @@ tasks above). While we do not currently offer any configuration for the Dackka
9090
plugin, this could change in the future as needed. Currently, the DackkaPlugin
9191
provides sensible defaults to output directories, package lists, and so forth.
9292
93-
The DackkaPlugin also provides two extra tasks:
94-
[cleanDackkaDocumentation][registerCleanDackkaDocumentation] and
95-
[deleteDackkaGeneratedJavaReferences][registerDeleteDackkaGeneratedJavaReferencesTask].
93+
The DackkaPlugin also provides three extra tasks:
94+
[cleanDackkaDocumentation][registerCleanDackkaDocumentation],
95+
[copyJavaDocToCommonDirectory][registerCopyJavaDocToCommonDirectoryTask] and
96+
[copyKotlinDocToCommonDirectory][registerCopyKotlinDocToCommonDirectoryTask].
9697
9798
_cleanDackkaDocumentation_ is exactly what it sounds like, a task to clean up (delete)
9899
the output of Dackka. This is useful when testing Dackka outputs itself- and
99100
shouldn't be apart of the normal flow. The reasoning is that it would otherwise
100101
invalidate the gradle cache.
101102
102-
_deleteDackkaGeneratedJavaReferences_ is a temporary addition. Dackka generates
103-
two separate styles of docs for every source set: Java & Kotlin. Regardless of
104-
whether the source is in Java or Kotlin. The Java output is how the source looks
105-
from Java, and the Kotlin output is how the source looks from Kotlin. We publish
106-
these under two separate categories, which you can see here:
107-
[Java](https://firebase.google.com/docs/reference/android/packages)
108-
or
109-
[Kotlin](https://firebase.google.com/docs/reference/kotlin/packages).
110-
Although, we do not currently publish Java packages with Dackka- and will wait
111-
until we are more comfortable with the output of Dackka to do so. So until then,
112-
this task will remove all generate Java references from the Dackka output.
103+
_copyJavaDocToCommonDirectory_ copies the JavaDoc variant of the Dackka output for each sdk,
104+
and pastes it in a common directory under the root project's build directory. This makes it easier
105+
to zip the doc files for staging.
106+
107+
_copyKotlinDocToCommonDirectory_ copies the KotlinDoc variant of the Dackka output for each sdk,
108+
and pastes it in a common directory under the root project's build directory. This makes it easier
109+
to zip the doc files for staging.
113110
114111
Currently, the DackkaPlugin builds Java sources separate from Kotlin Sources. There is an open bug
115112
for Dackka in which hidden parent classes and annotations do not hide themselves from children classes.
@@ -123,18 +120,19 @@ abstract class DackkaPlugin : Plugin<Project> {
123120
project.afterEvaluate {
124121
if (shouldWePublish(project)) {
125122
val generateDocumentation = registerGenerateDackkaDocumentationTask(project)
126-
val outputDirectory = generateDocumentation.flatMap { it.outputDirectory }
127-
val firesiteTransform = registerFiresiteTransformTask(project, outputDirectory)
128-
val deleteJavaReferences = registerDeleteDackkaGeneratedJavaReferencesTask(project, outputDirectory)
129-
val copyOutputToCommonDirectory = registerCopyDackkaOutputToCommonDirectoryTask(project, outputDirectory)
123+
val dackkaFilesDirectory = generateDocumentation.flatMap { it.outputDirectory }
124+
val firesiteTransform = registerFiresiteTransformTask(project, dackkaFilesDirectory)
125+
val transformedFilesDirectory = firesiteTransform.flatMap { it.outputDirectory }
126+
val copyJavaDocToCommonDirectory = registerCopyJavaDocToCommonDirectoryTask(project, transformedFilesDirectory)
127+
val copyKotlinDocToCommonDirectory = registerCopyKotlinDocToCommonDirectoryTask(project, transformedFilesDirectory)
130128

131129
project.tasks.register("kotlindoc") {
132130
group = "documentation"
133131
dependsOn(
134132
generateDocumentation,
135133
firesiteTransform,
136-
deleteJavaReferences,
137-
copyOutputToCommonDirectory
134+
copyJavaDocToCommonDirectory,
135+
copyKotlinDocToCommonDirectory
138136
)
139137
}
140138
} else {
@@ -171,6 +169,7 @@ abstract class DackkaPlugin : Plugin<Project> {
171169
val classpath = compileConfiguration.getJars() + project.javadocConfig.getJars() + project.files(bootClasspath)
172170

173171
val sourcesForJava = sourceSets.flatMap {
172+
// TODO(b/246984444): Investigate why kotlinDirectories includes javaDirectories
174173
it.javaDirectories.map { it.absoluteFile }
175174
}
176175

@@ -180,13 +179,12 @@ abstract class DackkaPlugin : Plugin<Project> {
180179
}
181180

182181
docsTask.configure {
183-
clientName.set(project.firebaseConfigValue { artifactId })
184-
// this will become useful with the agp upgrade, as they're separate in 7.x+
185-
val sourcesForKotlin = emptyList<File>()
182+
if (!isKotlin) dependsOn(docStubs)
183+
184+
val sourcesForKotlin = emptyList<File>() + projectSpecificSources(project)
186185
val packageLists = fetchPackageLists(project)
187186

188-
if (!isKotlin) dependsOn(docStubs)
189-
val excludedFiles = if (!isKotlin) projectSpecificSuppressedFiles(project) else emptyList()
187+
val excludedFiles = projectSpecificSuppressedFiles(project)
190188
val fixedJavaSources = if (!isKotlin) listOf(project.docStubs) else sourcesForJava
191189

192190
javaSources.set(fixedJavaSources)
@@ -209,11 +207,20 @@ abstract class DackkaPlugin : Plugin<Project> {
209207
include("**/package-list")
210208
}.toList()
211209

210+
// TODO(b/243534168): Remove when fixed
211+
private fun projectSpecificSources(project: Project) =
212+
when (project.name) {
213+
"firebase-common" -> {
214+
project.project(":firebase-firestore").files("src/main/java/com/google/firebase").toList()
215+
}
216+
else -> emptyList()
217+
}
218+
212219
// TODO(b/243534168): Remove when fixed
213220
private fun projectSpecificSuppressedFiles(project: Project): List<File> =
214221
when (project.name) {
215222
"firebase-common" -> {
216-
project.files("${project.docStubs}/com/google/firebase/firestore").toList()
223+
project.project(":firebase-firestore").files("src/main/java/com/google/firebase/firestore").toList()
217224
}
218225
"firebase-firestore" -> {
219226
project.files("${project.docStubs}/com/google/firebase/Timestamp.java").toList()
@@ -229,43 +236,50 @@ abstract class DackkaPlugin : Plugin<Project> {
229236

230237
dackkaJarFile.set(dackkaFile)
231238
outputDirectory.set(dackkaOutputDirectory)
239+
clientName.set(project.firebaseConfigValue { artifactId })
232240
}
233241

234-
// TODO(b/243833009): Make task cacheable
235-
private fun registerFiresiteTransformTask(project: Project, outputDirectory: Provider<File>) =
242+
private fun registerFiresiteTransformTask(project: Project, dackkaFilesDirectory: Provider<File>) =
236243
project.tasks.register<FiresiteTransformTask>("firesiteTransform") {
237-
dackkaFiles.set(outputDirectory)
238-
}
239-
240-
// If we decide to publish java variants, we'll need to address the generated format as well
241-
// TODO(b/243833009): Make task cacheable
242-
private fun registerDeleteDackkaGeneratedJavaReferencesTask(project: Project, outputDirectory: Provider<File>) =
243-
project.tasks.register<Delete>("deleteDackkaGeneratedJavaReferences") {
244244
mustRunAfter("generateDackkaDocumentation")
245245

246-
val filesWeDoNotNeed = listOf(
247-
"reference/client",
248-
"reference/com"
249-
)
250-
val filesToDelete = outputDirectory.map { dir ->
251-
filesWeDoNotNeed.map {
252-
project.files("${dir.path}/$it")
253-
}
254-
}
246+
dackkaFiles.set(dackkaFilesDirectory)
247+
outputDirectory.set(project.file("${project.buildDir}/dackkaTransformedFiles"))
248+
}
255249

256-
delete(filesToDelete)
250+
// TODO(b/246593212): Migrate doc files to single directory
251+
private fun registerCopyJavaDocToCommonDirectoryTask(project: Project, outputDirectory: Provider<File>) =
252+
project.tasks.register<Copy>("copyJavaDocToCommonDirectory") {
253+
/**
254+
* This is not currently cache compliant. The need for this property is
255+
* temporary while we test it alongside the current javaDoc task. Since it's such a
256+
* temporary behavior, losing cache compliance is fine for now.
257+
*/
258+
if (project.rootProject.findProperty("dackkaJavadoc") == "true") {
259+
mustRunAfter("firesiteTransform")
260+
261+
val outputFolder = project.file("${project.rootProject.buildDir}/firebase-kotlindoc/android")
262+
val clientFolder = outputDirectory.map { project.file("${it.path}/reference/client") }
263+
val comFolder = outputDirectory.map { project.file("${it.path}/reference/com") }
264+
265+
fromDirectory(clientFolder)
266+
fromDirectory(comFolder)
267+
268+
into(outputFolder)
269+
}
257270
}
258271

259-
private fun registerCopyDackkaOutputToCommonDirectoryTask(project: Project, outputDirectory: Provider<File>) =
260-
project.tasks.register<Copy>("copyDackkaOutputToCommonDirectory") {
261-
mustRunAfter("deleteDackkaGeneratedJavaReferences")
272+
// TODO(b/246593212): Migrate doc files to single directory
273+
private fun registerCopyKotlinDocToCommonDirectoryTask(project: Project, outputDirectory: Provider<File>) =
274+
project.tasks.register<Copy>("copyKotlinDocToCommonDirectory") {
262275
mustRunAfter("firesiteTransform")
263276

264-
val referenceFolder = outputDirectory.map { project.file("${it.path}/reference") }
265277
val outputFolder = project.file("${project.rootProject.buildDir}/firebase-kotlindoc")
278+
val kotlinFolder = outputDirectory.map { project.file("${it.path}/reference/kotlin") }
279+
280+
fromDirectory(kotlinFolder)
266281

267-
from(referenceFolder)
268-
destinationDir = outputFolder
282+
into(outputFolder)
269283
}
270284

271285
// Useful for local testing, but may not be desired for standard use (that's why it's not depended on)
@@ -274,5 +288,7 @@ abstract class DackkaPlugin : Plugin<Project> {
274288
group = "cleanup"
275289

276290
delete("${project.buildDir}/dackkaDocumentation")
291+
delete("${project.buildDir}/dackkaTransformedFiles")
292+
delete("${project.rootProject.buildDir}/firebase-kotlindoc")
277293
}
278294
}

buildSrc/src/main/java/com/google/firebase/gradle/plugins/FiresiteTransformTask.kt

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,11 @@ package com.google.firebase.gradle.plugins
33
import java.io.File
44
import org.gradle.api.DefaultTask
55
import org.gradle.api.provider.Property
6+
import org.gradle.api.tasks.CacheableTask
67
import org.gradle.api.tasks.InputDirectory
8+
import org.gradle.api.tasks.OutputDirectory
9+
import org.gradle.api.tasks.PathSensitive
10+
import org.gradle.api.tasks.PathSensitivity
711
import org.gradle.api.tasks.TaskAction
812

913
/**
@@ -21,10 +25,15 @@ import org.gradle.api.tasks.TaskAction
2125
* **Please note:**
2226
* This task is idempotent- meaning it can safely be ran multiple times on the same set of files.
2327
*/
28+
@CacheableTask
2429
abstract class FiresiteTransformTask : DefaultTask() {
2530
@get:InputDirectory
31+
@get:PathSensitive(PathSensitivity.RELATIVE)
2632
abstract val dackkaFiles: Property<File>
2733

34+
@get:OutputDirectory
35+
abstract val outputDirectory: Property<File>
36+
2837
@TaskAction
2938
fun build() {
3039
val namesOfFilesWeDoNotNeed = listOf(
@@ -33,14 +42,18 @@ abstract class FiresiteTransformTask : DefaultTask() {
3342
"packages.html",
3443
"package-list"
3544
)
45+
val rootDirectory = dackkaFiles.get()
46+
val targetDirectory = outputDirectory.get()
47+
targetDirectory.deleteRecursively()
48+
49+
rootDirectory.walkTopDown().forEach {
50+
if (it.name !in namesOfFilesWeDoNotNeed) {
51+
val relativePath = it.toRelativeString(rootDirectory)
52+
val newFile = it.copyTo(File("${targetDirectory.path}/$relativePath"), true)
3653

37-
dackkaFiles.get().walkTopDown().forEach {
38-
if (it.name in namesOfFilesWeDoNotNeed) {
39-
it.delete()
40-
} else {
4154
when (it.extension) {
42-
"html" -> it.fixHTMLFile()
43-
"yaml" -> it.fixYamlFile()
55+
"html" -> newFile.fixHTMLFile()
56+
"yaml" -> newFile.fixYamlFile()
4457
}
4558
}
4659
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package com.google.firebase.gradle.plugins
2+
3+
import java.io.File
4+
import org.gradle.api.provider.Provider
5+
import org.gradle.api.tasks.Copy
6+
7+
fun Copy.fromDirectory(directory: Provider<File>) =
8+
from(directory) {
9+
into(directory.map { it.name })
10+
}

buildSrc/src/main/java/com/google/firebase/gradle/plugins/Metalava.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import org.gradle.api.artifacts.Configuration
2323
import org.gradle.api.file.FileCollection
2424
import org.gradle.api.provider.Property
2525
import org.gradle.api.provider.SetProperty
26+
import org.gradle.api.tasks.Classpath
2627
import org.gradle.api.tasks.Input
2728
import org.gradle.api.tasks.InputFile
2829
import org.gradle.api.tasks.InputFiles
@@ -68,7 +69,7 @@ abstract class GenerateStubsTask : DefaultTask() {
6869
@get:InputFiles
6970
abstract val sources: SetProperty<File>
7071

71-
@get:InputFiles
72+
@get:[InputFiles Classpath]
7273
lateinit var classPath: FileCollection
7374

7475
@get:OutputDirectory

buildSrc/src/main/java/com/google/firebase/gradle/plugins/ProjectUtils.kt

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import org.gradle.api.Project
1717
import org.gradle.api.Task
1818
import org.gradle.api.artifacts.Configuration
1919
import org.gradle.api.attributes.Attribute
20+
import org.gradle.api.provider.Provider
2021

2122
fun Project.isAndroid(): Boolean =
2223
listOf("com.android.application", "com.android.library", "com.android.test")
@@ -50,8 +51,7 @@ val Project.dackkaConfig: Configuration
5051
*/
5152
fun Configuration.getJars() = incoming.artifactView {
5253
attributes {
53-
// TODO(b/241795594): replace value with android-class instead of jar after agp upgrade
54-
attribute(Attribute.of("artifactType", String::class.java), "jar")
54+
attribute(Attribute.of("artifactType", String::class.java), "android-classes")
5555
}
5656
}.artifacts.artifactFiles
5757

@@ -63,6 +63,14 @@ fun <T : Task, R : Task> T.dependsOnAndMustRunAfter(otherTask: R) {
6363
dependsOn(otherTask)
6464
}
6565

66+
/**
67+
* Utility method to call [Task.mustRunAfter] and [Task.dependsOn] on the specified task
68+
*/
69+
fun <T : Task, R : Task> T.dependsOnAndMustRunAfter(otherTask: Provider<R>) {
70+
mustRunAfter(otherTask)
71+
dependsOn(otherTask)
72+
}
73+
6674
/**
6775
* Utility method to call [Task.mustRunAfter] and [Task.dependsOn] on the specified task name
6876
*/

0 commit comments

Comments
 (0)