Skip to content

Commit 85522b4

Browse files
daymxnqdpham13
authored andcommitted
Add Javadoc support to the DackkaPlugin (#4082)
* Add util method for copying directories * Add javadoc support to our dackka plugin * Remove the extension check on fromDirectory * Add a note about cache compliance and the javadoc task
1 parent a1fbf51 commit 85522b4

File tree

2 files changed

+53
-40
lines changed

2 files changed

+53
-40
lines changed

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

Lines changed: 43 additions & 40 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.
@@ -125,16 +122,16 @@ abstract class DackkaPlugin : Plugin<Project> {
125122
val generateDocumentation = registerGenerateDackkaDocumentationTask(project)
126123
val outputDirectory = generateDocumentation.flatMap { it.outputDirectory }
127124
val firesiteTransform = registerFiresiteTransformTask(project, outputDirectory)
128-
val deleteJavaReferences = registerDeleteDackkaGeneratedJavaReferencesTask(project, outputDirectory)
129-
val copyOutputToCommonDirectory = registerCopyDackkaOutputToCommonDirectoryTask(project, outputDirectory)
125+
val copyJavaDocToCommonDirectory = registerCopyJavaDocToCommonDirectoryTask(project, outputDirectory)
126+
val copyKotlinDocToCommonDirectory = registerCopyKotlinDocToCommonDirectoryTask(project, outputDirectory)
130127

131128
project.tasks.register("kotlindoc") {
132129
group = "documentation"
133130
dependsOn(
134131
generateDocumentation,
135132
firesiteTransform,
136-
deleteJavaReferences,
137-
copyOutputToCommonDirectory
133+
copyJavaDocToCommonDirectory,
134+
copyKotlinDocToCommonDirectory
138135
)
139136
}
140137
} else {
@@ -234,38 +231,44 @@ abstract class DackkaPlugin : Plugin<Project> {
234231
// TODO(b/243833009): Make task cacheable
235232
private fun registerFiresiteTransformTask(project: Project, outputDirectory: Provider<File>) =
236233
project.tasks.register<FiresiteTransformTask>("firesiteTransform") {
234+
mustRunAfter("generateDackkaDocumentation")
235+
237236
dackkaFiles.set(outputDirectory)
238237
}
239238

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") {
244-
mustRunAfter("generateDackkaDocumentation")
245-
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-
}
239+
// TODO(b/246593212): Migrate doc files to single directory
240+
private fun registerCopyJavaDocToCommonDirectoryTask(project: Project, outputDirectory: Provider<File>) =
241+
project.tasks.register<Copy>("copyJavaDocToCommonDirectory") {
242+
/**
243+
* This is not currently cache compliant. The need for this property is
244+
* temporary while we test it alongside the current javaDoc task. Since it's such a
245+
* temporary behavior, losing cache compliance is fine for now.
246+
*/
247+
if (project.rootProject.findProperty("dackkaJavadoc") == "true") {
248+
mustRunAfter("firesiteTransform")
249+
250+
val outputFolder = project.file("${project.rootProject.buildDir}/firebase-kotlindoc/android")
251+
val clientFolder = outputDirectory.map { project.file("${it.path}/reference/client") }
252+
val comFolder = outputDirectory.map { project.file("${it.path}/reference/com") }
253+
254+
fromDirectory(clientFolder)
255+
fromDirectory(comFolder)
256+
257+
into(outputFolder)
254258
}
255-
256-
delete(filesToDelete)
257259
}
258260

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

264-
val referenceFolder = outputDirectory.map { project.file("${it.path}/reference") }
265266
val outputFolder = project.file("${project.rootProject.buildDir}/firebase-kotlindoc")
267+
val kotlinFolder = outputDirectory.map { project.file("${it.path}/reference/kotlin") }
268+
269+
fromDirectory(kotlinFolder)
266270

267-
from(referenceFolder)
268-
destinationDir = outputFolder
271+
into(outputFolder)
269272
}
270273

271274
// Useful for local testing, but may not be desired for standard use (that's why it's not depended on)
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+
}

0 commit comments

Comments
 (0)