Skip to content

Make dackka task depend on docStubs task. #4072

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 3 commits into from
Sep 9, 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 @@ -8,6 +8,7 @@ import org.gradle.api.provider.Property
import org.gradle.api.provider.SetProperty
import org.gradle.api.tasks.CacheableTask
import org.gradle.api.tasks.Classpath
import org.gradle.api.tasks.Input
import org.gradle.api.tasks.InputFile
import org.gradle.api.tasks.InputFiles
import org.gradle.api.tasks.OutputDirectory
Expand All @@ -19,7 +20,6 @@ import org.gradle.workers.WorkAction
import org.gradle.workers.WorkParameters
import org.gradle.workers.WorkerExecutor
import org.json.JSONObject

/**
* Extension class for [GenerateDocumentationTask].
*
Expand Down Expand Up @@ -56,6 +56,9 @@ abstract class GenerateDocumentationTaskExtension : DefaultTask() {
@get:PathSensitive(PathSensitivity.RELATIVE)
abstract val packageListFiles: ListProperty<File>

@get:Input
abstract val clientName: Property<String>

@get:OutputDirectory
abstract val outputDirectory: Property<File>
}
Expand Down Expand Up @@ -89,7 +92,7 @@ abstract class GenerateDocumentationTask @Inject constructor(
@TaskAction
fun build() {
val configFile = saveToJsonFile(constructArguments())
launchDackka(configFile, workerExecutor)
launchDackka(clientName, configFile, workerExecutor)
}

private fun constructArguments(): JSONObject {
Expand Down Expand Up @@ -122,7 +125,7 @@ abstract class GenerateDocumentationTask @Inject constructor(
private fun createExternalLinks(packageLists: ListProperty<File>): List<ExternalDocumentationLink> {
val linksMap = mapOf(
"android" to "https://developer.android.com/reference/kotlin/",
"google" to "https://developer.android.com/reference/",
"google" to "https://developers.google.com/android/reference/",
"firebase" to "https://firebase.google.com/docs/reference/kotlin/",
"coroutines" to "https://kotlinlang.org/api/kotlinx.coroutines/kotlinx-coroutines-core/"
)
Expand All @@ -142,13 +145,13 @@ abstract class GenerateDocumentationTask @Inject constructor(
return outputFile
}

private fun launchDackka(argsFile: File, workerExecutor: WorkerExecutor) {
private fun launchDackka(clientName: Property<String>, argsFile: File, workerExecutor: WorkerExecutor) {
val workQueue = workerExecutor.noIsolation()

workQueue.submit(DackkaWorkAction::class.java) {
args.set(listOf(argsFile.path, "-loggingLevel", "WARN"))
classpath.set(setOf(dackkaJarFile.get()))
projectName.set(project.name)
projectName.set(clientName)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,11 @@ abstract class DackkaPlugin : Plugin<Project> {
}
}

fun <T> Project.firebaseConfigValue(getter: FirebaseLibraryExtension.() -> T): T =
project.extensions.getByType<FirebaseLibraryExtension>().getter()

private fun shouldWePublish(project: Project) =
project.extensions.getByType<FirebaseLibraryExtension>().publishJavadoc
project.firebaseConfigValue { publishJavadoc }

private fun prepareJavadocConfiguration(project: Project) {
val javadocConfig = project.javadocConfig
Expand All @@ -76,22 +79,24 @@ abstract class DackkaPlugin : Plugin<Project> {
if (name == "release") {
val isKotlin = project.plugins.hasPlugin("kotlin-android")

val classpath = runtimeConfiguration.getJars() + project.javadocConfig.getJars() + bootClasspath
val classpath = compileConfiguration.getJars() + project.javadocConfig.getJars() + project.files(bootClasspath)

val sourcesForJava = sourceSets.flatMap {
it.javaDirectories.map { it.absoluteFile }
}

docStubs.configure {
classPath = project.files(classpath)
classPath = classpath
sources.set(project.provider { sourcesForJava })
}

docsTask.configure {
clientName.set(project.firebaseConfigValue { artifactId })
// this will become useful with the agp upgrade, as they're separate in 7.x+
val sourcesForKotlin = emptyList<File>()
val packageLists = fetchPackageLists(project)

if (!isKotlin) dependsOn(docStubs)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice catch! Ideally we should switch this to dependsOnAndMustRunAfter in the future, but it's not breaking for now.

val excludedFiles = if (!isKotlin) projectSpecificSuppressedFiles(project) else emptyList()
val fixedJavaSources = if (!isKotlin) listOf(project.docStubs) else sourcesForJava

Expand Down