Skip to content

Add projectSpecificSources back to the DackkaPlugin #4110

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 19, 2022
Merged
Show file tree
Hide file tree
Changes from 2 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 @@ -168,6 +168,7 @@ abstract class DackkaPlugin : Plugin<Project> {
val classpath = compileConfiguration.getJars() + project.javadocConfig.getJars() + project.files(bootClasspath)

val sourcesForJava = sourceSets.flatMap {
// TODO(b/246984444): Investigate why kotlinDirectories includes javaDirectories
it.javaDirectories.map { it.absoluteFile }
}

Expand All @@ -177,13 +178,12 @@ abstract class DackkaPlugin : Plugin<Project> {
}

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>()
if (!isKotlin) dependsOnAndMustRunAfter(docStubs)
Copy link
Member

Choose a reason for hiding this comment

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

isn't it cleaner to wire this dependency up via javaSources.set(docStubs.flatMap { it.output })?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah, but you'd be invoking docStubs for kotlin modules as well.

Copy link
Member

Choose a reason for hiding this comment

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

sure, but it can be conditional right?

javaSources.set(if(isKotlin) sourcesForJava  else docStubs.flatMap { it.output })

Copy link
Member Author

Choose a reason for hiding this comment

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

Sure, but I would argue that's less readable. Especially when all the other inputs are being defined in their own variables for readability. Because under that practice, we could restructure this section to this:

docsTask.configure {
    if (!isKotlin) dependsOnAndMustRunAfter(docStubs)

    javaSources.set(if (!isKotlin) listOf(project.docStubs) else sourcesForJava)
    suppressedFiles.set(projectSpecificSuppressedFiles(project))
    packageListFiles.set(fetchPackageLists(project))

    kotlinSources.set(projectSpecificSources(project))
    dependencies.set(classpath)

    applyCommonConfigurations()
}

which I would argue is less readable than this:

docsTask.configure {
    if (!isKotlin) dependsOnAndMustRunAfter(docStubs)

    val sourcesForKotlin = emptyList<File>() + projectSpecificSources(project)
    val packageLists = fetchPackageLists(project)

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

    javaSources.set(fixedJavaSources)
    suppressedFiles.set(excludedFiles)
    packageListFiles.set(packageLists)

    kotlinSources.set(sourcesForKotlin)
    dependencies.set(classpath)

    applyCommonConfigurations()
}

But if you feel strongly about inlining it, I'm comfortable with it.


val sourcesForKotlin = emptyList<File>() + projectSpecificSources(project)
val packageLists = fetchPackageLists(project)

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

javaSources.set(fixedJavaSources)
Expand All @@ -206,11 +206,20 @@ abstract class DackkaPlugin : Plugin<Project> {
include("**/package-list")
}.toList()

// TODO(b/243534168): Remove when fixed
private fun projectSpecificSources(project: Project) =
when (project.name) {
"firebase-common" -> {
project.project(":firebase-firestore").files("src/main/java/com/google/firebase").toList()
}
else -> emptyList()
}

// TODO(b/243534168): Remove when fixed
private fun projectSpecificSuppressedFiles(project: Project): List<File> =
when (project.name) {
"firebase-common" -> {
project.files("${project.docStubs}/com/google/firebase/firestore").toList()
project.project(":firebase-firestore").files("src/main/java/com/google/firebase/firestore").toList()
}
"firebase-firestore" -> {
project.files("${project.docStubs}/com/google/firebase/Timestamp.java").toList()
Expand All @@ -226,6 +235,7 @@ abstract class DackkaPlugin : Plugin<Project> {

dackkaJarFile.set(dackkaFile)
outputDirectory.set(dackkaOutputDirectory)
clientName.set(project.firebaseConfigValue { artifactId })
}

// TODO(b/243833009): Make task cacheable
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import org.gradle.api.Project
import org.gradle.api.Task
import org.gradle.api.artifacts.Configuration
import org.gradle.api.attributes.Attribute
import org.gradle.api.provider.Provider

fun Project.isAndroid(): Boolean =
listOf("com.android.application", "com.android.library", "com.android.test")
Expand Down Expand Up @@ -63,6 +64,14 @@ fun <T : Task, R : Task> T.dependsOnAndMustRunAfter(otherTask: R) {
dependsOn(otherTask)
}

/**
* Utility method to call [Task.mustRunAfter] and [Task.dependsOn] on the specified task
*/
fun <T : Task, R : Task> T.dependsOnAndMustRunAfter(otherTask: Provider<R>) {
mustRunAfter(otherTask)
dependsOn(otherTask)
}

/**
* Utility method to call [Task.mustRunAfter] and [Task.dependsOn] on the specified task name
*/
Expand Down