Skip to content

Add Dackka transform to remove leading groupId in Javadocs #4278

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

Merged
merged 2 commits into from
Nov 4, 2022
Merged
Show file tree
Hide file tree
Changes from all 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
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,7 @@ abstract class DackkaPlugin : Plugin<Project> {
val transformJavadoc = project.tasks.register<FiresiteTransformTask>("firesiteTransformJavadoc") {
dependsOnAndMustRunAfter("separateJavadoc")

removeGoogleGroupId.set(true)
referencePath.set("/docs/reference/android")
referenceHeadTagsPath.set("docs/reference/android")
dackkaFiles.set(project.childFile(separatedFilesDirectory, "android"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import org.gradle.api.provider.Property
import org.gradle.api.tasks.CacheableTask
import org.gradle.api.tasks.Input
import org.gradle.api.tasks.InputDirectory
import org.gradle.api.tasks.Optional
import org.gradle.api.tasks.OutputDirectory
import org.gradle.api.tasks.PathSensitive
import org.gradle.api.tasks.PathSensitivity
Expand All @@ -21,7 +22,7 @@ import org.gradle.api.tasks.TaskAction
* - Removes Class and Index headers from _toc.yaml files
* - Changes links to be appropriate for Firesite versus normal Devsite behavior
* - Removes the prefix path from book_path
* - Removes the firebase prefix from all links
* - Removes the google groupId for Javadocs
* - Changes the path for _reference-head-tags at the top of html files
*
* **Please note:**
Expand All @@ -39,6 +40,10 @@ abstract class FiresiteTransformTask : DefaultTask() {
@get:Input
abstract val referencePath: Property<String>

@get:Input
@get:Optional
abstract val removeGoogleGroupId: Property<Boolean>

@get:OutputDirectory
abstract val outputDirectory: Property<File>

Expand Down Expand Up @@ -73,10 +78,30 @@ abstract class FiresiteTransformTask : DefaultTask() {
}

private fun File.fixYamlFile() {
val fixedContent = readText().removeClassHeader().removeIndexHeader().fixLinks()
val fixedContent = readText().removeClassHeader().removeIndexHeader().fixLinks().let {
if (removeGoogleGroupId.getOrElse(false)) it.removeGoogleGroupId() else it
}
writeText(fixedContent)
}

/**
* Removes the leading `com.google` group id from strings in the file
*
* We have internal SDKs that generate their docs outside the scope of this plugin. The Javadoc
* variant of those SDks is typically generated with metalava- which does *not* provide the
* groupId. This makes the output look weird, as not all SDKs line up. So this method exists
* to correct Javadoc nav files, so that they align with internally generated docs.
*
* Example output:
* ```
* removeGoogleGroupId("com.google.firebase.appcheck")
* --> "firebase.appcheck"
* ```
*/
// TODO(b/257293594): Remove when dackka exposes configuration for this
private fun String.removeGoogleGroupId() =
remove(Regex("(?<=\")com.google.(?=firebase.)"))

// Our documentation does not live under the standard path expected by Dackka, especially
// between Kotlin + Javadocs
// TODO(b/243674305): Remove when dackka exposes configuration for this
Expand All @@ -100,11 +125,4 @@ abstract class FiresiteTransformTask : DefaultTask() {
// TODO(b/243674303): Remove when dackka exposes configuration for this
private fun String.fixBookPath() =
remove(Regex("(?<=setvar book_path ?%})(.+)(?=/_book.yaml\\{% ?endsetvar)"))

// The documentation will work fine without this. This is primarily to make sure that links
// resolve to their local counter part. Meaning when the docs are staged, they will resolve to
// staged docs instead of prod docs- and vise versa.
// TODO(b/243673063): Remove when dackka exposes configuration for this
private fun String.removeLeadingFirebaseDomainInLinks() =
remove(Regex("(?<=\")(https://firebase\\.google\\.com)(?=/docs/reference)"))
}