Skip to content

Commit afc7a2f

Browse files
authored
Update FiresiteTransform (firebase#5550)
Per [b/310955409](https://b.corp.google.com/issues/310955409), This adds a transform to our `FiresiteTransform` task to add a deprecated status to the toc sections of our `ktx` libs, as we are marking those as deprecated in the sidebar. Previously- this way being done manually during releases in the ref docs CL. Additionally, this PR fixes the following: - [b/310966215](https://b.corp.google.com/issues/310966215): Remove google group id transformations from FiresiteTransform - [b/310967446](https://b.corp.google.com/issues/310967446): Combine FiresiteTransform tasks _This PR also updates the relevant documentation to reflect the changes made_
1 parent 82af60b commit afc7a2f

File tree

3 files changed

+40
-58
lines changed

3 files changed

+40
-58
lines changed

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

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@ import org.json.JSONObject
4545
* @property sources a list of source roots
4646
* @property suppressedFiles a list of files to exclude from documentation
4747
* @property packageListFiles a list of files that define external package-lists for links
48-
* @property generateJavadocs should we generate the Javadoc variant, or just Kotlin?
4948
* @property clientName the name of the module
5049
* @property outputDirectory where to store the generated files
5150
*/
@@ -69,8 +68,6 @@ abstract class GenerateDocumentationTaskExtension : DefaultTask() {
6968
@get:PathSensitive(PathSensitivity.RELATIVE)
7069
abstract val packageListFiles: ListProperty<File>
7170

72-
@get:Input abstract val generateJavadocs: Property<Boolean>
73-
7471
@get:Input abstract val clientName: Property<String>
7572

7673
@get:OutputDirectory abstract val outputDirectory: Property<File>
@@ -152,7 +149,7 @@ constructor(private val workerExecutor: WorkerExecutor) : GenerateDocumentationT
152149
JSONObject(
153150
mapOf(
154151
"docRootPath" to "/docs/reference/",
155-
"javaDocsPath" to "android".takeIf { generateJavadocs.get() },
152+
"javaDocsPath" to "android",
156153
"kotlinDocsPath" to "kotlin",
157154
"projectPath" to "client/${clientName.get()}",
158155
"includedHeadTagsPathJava" to

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

Lines changed: 5 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ import com.android.build.gradle.LibraryExtension
1919
import java.io.File
2020
import org.gradle.api.Plugin
2121
import org.gradle.api.Project
22-
import org.gradle.api.Task
2322
import org.gradle.api.provider.Provider
2423
import org.gradle.api.tasks.Copy
2524
import org.gradle.api.tasks.Delete
@@ -233,37 +232,19 @@ abstract class DackkaPlugin : Plugin<Project> {
233232

234233
dackkaJarFile.set(dackkaFile)
235234
clientName.set(project.firebaseLibrary.artifactId)
236-
generateJavadocs.set(!project.isKTXLibary)
237235
}
238236

239-
// TODO(b/270593375): Refactor when fixed
240237
private fun registerFiresiteTransformTask(
241238
project: Project,
242239
dackkaOutputDirectory: Provider<File>,
243240
targetDirectory: Provider<File>
244-
): TaskProvider<Task> {
245-
val transformJavadoc =
246-
project.tasks.register<FiresiteTransformTask>("firesiteTransformJavadoc") {
247-
onlyIf { !project.isKTXLibary }
248-
dependsOnAndMustRunAfter("generateDackkaDocumentation")
249-
250-
removeGoogleGroupId.set(true)
251-
dackkaFiles.set(dackkaOutputDirectory.childFile("docs/reference/android"))
252-
outputDirectory.set(targetDirectory.childFile("android"))
253-
}
254-
255-
val transformKotlindoc =
256-
project.tasks.register<FiresiteTransformTask>("firesiteTransformKotlindoc") {
257-
dependsOnAndMustRunAfter("generateDackkaDocumentation")
258-
259-
dackkaFiles.set(dackkaOutputDirectory.childFile("docs/reference/kotlin"))
260-
outputDirectory.set(targetDirectory.childFile("kotlin"))
261-
}
241+
) =
242+
project.tasks.register<FiresiteTransformTask>("firesiteTransform") {
243+
dependsOnAndMustRunAfter("generateDackkaDocumentation")
262244

263-
return project.tasks.register("firesiteTransform") {
264-
dependsOn(transformJavadoc, transformKotlindoc)
245+
dackkaFiles.set(dackkaOutputDirectory.childFile("docs/reference"))
246+
outputDirectory.set(targetDirectory)
265247
}
266-
}
267248

268249
private fun registerCopyDocsToCommonDirectoryTask(
269250
project: Project,

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

Lines changed: 34 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,7 @@ import java.io.File
1818
import org.gradle.api.DefaultTask
1919
import org.gradle.api.provider.Property
2020
import org.gradle.api.tasks.CacheableTask
21-
import org.gradle.api.tasks.Input
2221
import org.gradle.api.tasks.InputDirectory
23-
import org.gradle.api.tasks.Optional
2422
import org.gradle.api.tasks.OutputDirectory
2523
import org.gradle.api.tasks.PathSensitive
2624
import org.gradle.api.tasks.PathSensitivity
@@ -35,9 +33,9 @@ import org.gradle.api.tasks.TaskAction
3533
* More specifically, it:
3634
* - Deletes unnecessary files
3735
* - Removes Class and Index headers from _toc.yaml files
36+
* - Adds the deprecated status to ktx sections in _toc.yaml files
3837
* - Fixes broken hyperlinks in `@see` blocks
3938
* - Removes the prefix path from book_path
40-
* - Removes the google groupId for Javadocs
4139
*
4240
* **Please note:** This task is idempotent- meaning it can safely be ran multiple times on the same
4341
* set of files.
@@ -48,8 +46,6 @@ abstract class FiresiteTransformTask : DefaultTask() {
4846
@get:PathSensitive(PathSensitivity.RELATIVE)
4947
abstract val dackkaFiles: Property<File>
5048

51-
@get:Input @get:Optional abstract val removeGoogleGroupId: Property<Boolean>
52-
5349
@get:OutputDirectory abstract val outputDirectory: Property<File>
5450

5551
@TaskAction
@@ -79,34 +75,10 @@ abstract class FiresiteTransformTask : DefaultTask() {
7975
}
8076

8177
private fun File.fixYamlFile() {
82-
val fixedContent =
83-
readText().removeClassHeader().removeIndexHeader().let {
84-
if (removeGoogleGroupId.getOrElse(false)) it.removeGoogleGroupId() else it
85-
}
78+
val fixedContent = readText().removeClassHeader().removeIndexHeader().addDeprecatedStatus()
8679
writeText(fixedContent)
8780
}
8881

89-
/**
90-
* Removes the leading `com.google` group id from strings in the file
91-
*
92-
* We have internal SDKs that generate their docs outside the scope of this plugin. The Javadoc
93-
* variant of those SDks is typically generated with metalava- which does *not* provide the
94-
* groupId. This makes the output look weird, as not all SDKs line up. So this method exists to
95-
* correct Javadoc nav files, so that they align with internally generated docs.
96-
*
97-
* Example input:
98-
* ```
99-
* "com.google.firebase.appcheck"
100-
* ```
101-
*
102-
* Example output:
103-
* ```
104-
* "firebase.appcheck"
105-
* ```
106-
*/
107-
// TODO(b/270593375): Remove when dackka exposes configuration for this
108-
private fun String.removeGoogleGroupId() = remove(Regex("(?<=\")com.google.(?=firebase.)"))
109-
11082
/**
11183
* Fixes broken hyperlinks in the rendered HTML
11284
*
@@ -142,11 +114,43 @@ abstract class FiresiteTransformTask : DefaultTask() {
142114
.trimIndent()
143115
}
144116

117+
/**
118+
* Adds the deprecated status to ktx libs.
119+
*
120+
* Our ktx libs are marked as deprecated in the sidebar, and as such- require that we add a
121+
* `status: deprecated` to their section in the relevant `_toc.yaml` file.
122+
*
123+
* Example input:
124+
* ```
125+
* - title: "firebase.database.ktx"
126+
* path: "/docs/reference/android/com/google/firebase/database/ktx/package-summary.html"
127+
* ```
128+
*
129+
* Example output:
130+
* ```
131+
* - title: "firebase.database.ktx"
132+
* status: deprecated
133+
* path: "/docs/reference/android/com/google/firebase/database/ktx/package-summary.html"
134+
* ```
135+
*/
136+
// TODO(b/310964911): Remove when we drop ktx modules
137+
private fun String.addDeprecatedStatus(): String =
138+
replace(Regex("- title: \"(.+ktx)\"")) {
139+
val packageName = it.firstCapturedValue
140+
141+
"""
142+
- title: "${packageName}"
143+
status: deprecated
144+
"""
145+
.trimIndent()
146+
}
147+
145148
// We don't actually upload class or index files,
146149
// so these headers will throw not found errors if not removed.
147150
// TODO(b/243674302): Remove when dackka exposes configuration for this
148151
private fun String.removeClassHeader() =
149152
remove(Regex("- title: \"Class Index\"\n {2}path: \".+\"\n\n"))
153+
150154
private fun String.removeIndexHeader() =
151155
remove(Regex("- title: \"Package Index\"\n {2}path: \".+\"\n\n"))
152156

0 commit comments

Comments
 (0)