Skip to content

Commit 7c5ef93

Browse files
authored
Added stub support to dackka (#4061)
1 parent ffd44ee commit 7c5ef93

File tree

3 files changed

+53
-32
lines changed

3 files changed

+53
-32
lines changed

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

Lines changed: 32 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,7 @@ abstract class DackkaPlugin : Plugin<Project> {
3737
val outputDirectory = generateDocumentation.flatMap { it.outputDirectory }
3838
val firesiteTransform = registerFiresiteTransformTask(project, outputDirectory)
3939
val deleteJavaReferences = registerDeleteDackkaGeneratedJavaReferencesTask(project, outputDirectory)
40-
val copyOutputToCommonDirectory =
41-
registerCopyDackkaOutputToCommonDirectoryTask(project, outputDirectory)
40+
val copyOutputToCommonDirectory = registerCopyDackkaOutputToCommonDirectoryTask(project, outputDirectory)
4241

4342
project.tasks.register("kotlindoc") {
4443
group = "documentation"
@@ -68,60 +67,61 @@ abstract class DackkaPlugin : Plugin<Project> {
6867
)
6968
}
7069

71-
private fun registerGenerateDackkaDocumentationTask(project: Project) =
72-
project.tasks.register<GenerateDocumentationTask>("generateDackkaDocumentation") {
73-
with(project.extensions.getByType<LibraryExtension>()) {
74-
libraryVariants.all {
75-
if (name == "release") {
76-
mustRunAfter("createFullJarRelease")
77-
dependsOn("createFullJarRelease")
70+
// TODO(b/243534168): Refactor when fixed, so we no longer need stubs
71+
private fun registerGenerateDackkaDocumentationTask(project: Project): Provider<GenerateDocumentationTask> {
72+
val docStubs = project.tasks.register<GenerateStubsTask>("docStubsForDackkaInput")
73+
val docsTask = project.tasks.register<GenerateDocumentationTask>("generateDackkaDocumentation")
74+
with(project.extensions.getByType<LibraryExtension>()) {
75+
libraryVariants.all {
76+
if (name == "release") {
77+
val isKotlin = project.plugins.hasPlugin("kotlin-android")
7878

79-
val classpath = project.provider {
80-
runtimeConfiguration.getJars() + project.javadocConfig.getJars() + bootClasspath
81-
}
79+
val classpath = runtimeConfiguration.getJars() + project.javadocConfig.getJars() + bootClasspath
8280

83-
val sourcesForJava = sourceSets.flatMap {
84-
it.javaDirectories.map { it.absoluteFile } + projectSpecificSources(project)
85-
}
81+
val sourcesForJava = sourceSets.flatMap {
82+
it.javaDirectories.map { it.absoluteFile }
83+
}
84+
85+
docStubs.configure {
86+
classPath = project.files(classpath)
87+
sources.set(project.provider { sourcesForJava })
88+
}
8689

87-
// this will become useful with the agp upgrade, as they're separate in 7.x+
90+
docsTask.configure {
8891
val sourcesForKotlin = emptyList<File>()
89-
val excludedFiles = emptyList<File>() + projectSpecificSuppressedFiles(project)
9092

91-
dependencies.set(classpath)
92-
javaSources.set(sourcesForJava)
93-
kotlinSources.set(sourcesForKotlin)
93+
val excludedFiles = if (!isKotlin) projectSpecificSuppressedFiles(project) else emptyList()
94+
val fixedJavaSources = if (!isKotlin) listOf(project.docStubs) else sourcesForJava
95+
96+
javaSources.set(fixedJavaSources)
9497
suppressedFiles.set(excludedFiles)
9598

99+
kotlinSources.set(sourcesForKotlin)
100+
dependencies.set(classpath)
101+
96102
applyCommonConfigurations()
97103
}
98104
}
99105
}
100106
}
101-
102-
// TODO(b/243534168): Remove when fixed
103-
private fun projectSpecificSources(project: Project) =
104-
when (project.name) {
105-
"firebase-common" -> {
106-
project.project(":firebase-firestore").files("src/main/java/com/google/firebase").toList()
107-
}
108-
else -> emptyList()
109-
}
107+
return docsTask
108+
}
110109

111110
// TODO(b/243534168): Remove when fixed
112111
private fun projectSpecificSuppressedFiles(project: Project): List<File> =
113112
when (project.name) {
114113
"firebase-common" -> {
115-
val firestoreProject = project.project(":firebase-firestore")
116-
firestoreProject.files("src/main/java/com/google/firebase/firestore").toList()
114+
project.files("${project.docStubs}/com/google/firebase/firestore").toList()
117115
}
118116
"firebase-firestore" -> {
119-
project.files("src/main/java/com/google/firebase/Timestamp.java").toList()
117+
project.files("${project.docStubs}/com/google/firebase/Timestamp.java").toList()
120118
}
121119
else -> emptyList()
122120
}
123121

124122
private fun GenerateDocumentationTask.applyCommonConfigurations() {
123+
dependsOnAndMustRunAfter("createFullJarRelease")
124+
125125
val dackkaFile = project.provider { project.dackkaConfig.singleFile }
126126
val dackkaOutputDirectory = File(project.buildDir, "dackkaDocumentation")
127127

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,10 @@ val Project.metalavaConfig: Configuration
3737
this.dependencies.add(this@metalavaConfig.dependencies.create("com.android.tools.metalava:metalava:1.0.0-alpha06"))
3838
}
3939

40+
val Project.docStubs: File?
41+
get() =
42+
project.file("${buildDir.path}/doc-stubs")
43+
4044
fun Project.runMetalavaWithArgs(
4145
arguments: List<String>,
4246
ignoreFailure: Boolean = false,

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

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
package com.google.firebase.gradle.plugins
1515

1616
import org.gradle.api.Project
17+
import org.gradle.api.Task
1718
import org.gradle.api.artifacts.Configuration
1819
import org.gradle.api.attributes.Attribute
1920

@@ -53,3 +54,19 @@ fun Configuration.getJars() = incoming.artifactView {
5354
attribute(Attribute.of("artifactType", String::class.java), "jar")
5455
}
5556
}.artifacts.artifactFiles
57+
58+
/**
59+
* Utility method to call [Task.mustRunAfter] and [Task.dependsOn] on the specified task
60+
*/
61+
fun <T : Task, R : Task> T.dependsOnAndMustRunAfter(otherTask: R) {
62+
mustRunAfter(otherTask)
63+
dependsOn(otherTask)
64+
}
65+
66+
/**
67+
* Utility method to call [Task.mustRunAfter] and [Task.dependsOn] on the specified task name
68+
*/
69+
fun <T : Task> T.dependsOnAndMustRunAfter(otherTask: String) {
70+
mustRunAfter(otherTask)
71+
dependsOn(otherTask)
72+
}

0 commit comments

Comments
 (0)