Skip to content

Make FiresiteTransform a Cacheable task #4124

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 1 commit into from
Sep 21, 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 @@ -120,10 +120,11 @@ abstract class DackkaPlugin : Plugin<Project> {
project.afterEvaluate {
if (shouldWePublish(project)) {
val generateDocumentation = registerGenerateDackkaDocumentationTask(project)
val outputDirectory = generateDocumentation.flatMap { it.outputDirectory }
val firesiteTransform = registerFiresiteTransformTask(project, outputDirectory)
val copyJavaDocToCommonDirectory = registerCopyJavaDocToCommonDirectoryTask(project, outputDirectory)
val copyKotlinDocToCommonDirectory = registerCopyKotlinDocToCommonDirectoryTask(project, outputDirectory)
val dackkaFilesDirectory = generateDocumentation.flatMap { it.outputDirectory }
val firesiteTransform = registerFiresiteTransformTask(project, dackkaFilesDirectory)
val transformedFilesDirectory = firesiteTransform.flatMap { it.outputDirectory }
val copyJavaDocToCommonDirectory = registerCopyJavaDocToCommonDirectoryTask(project, transformedFilesDirectory)
val copyKotlinDocToCommonDirectory = registerCopyKotlinDocToCommonDirectoryTask(project, transformedFilesDirectory)

project.tasks.register("kotlindoc") {
group = "documentation"
Expand Down Expand Up @@ -238,12 +239,12 @@ abstract class DackkaPlugin : Plugin<Project> {
clientName.set(project.firebaseConfigValue { artifactId })
}

// TODO(b/243833009): Make task cacheable
private fun registerFiresiteTransformTask(project: Project, outputDirectory: Provider<File>) =
private fun registerFiresiteTransformTask(project: Project, dackkaFilesDirectory: Provider<File>) =
project.tasks.register<FiresiteTransformTask>("firesiteTransform") {
mustRunAfter("generateDackkaDocumentation")

dackkaFiles.set(outputDirectory)
dackkaFiles.set(dackkaFilesDirectory)
outputDirectory.set(project.file("${project.buildDir}/dackkaTransformedFiles"))
}

// TODO(b/246593212): Migrate doc files to single directory
Expand Down Expand Up @@ -287,5 +288,7 @@ abstract class DackkaPlugin : Plugin<Project> {
group = "cleanup"

delete("${project.buildDir}/dackkaDocumentation")
delete("${project.buildDir}/dackkaTransformedFiles")
delete("${project.rootProject.buildDir}/firebase-kotlindoc")
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,11 @@ package com.google.firebase.gradle.plugins
import java.io.File
import org.gradle.api.DefaultTask
import org.gradle.api.provider.Property
import org.gradle.api.tasks.CacheableTask
import org.gradle.api.tasks.InputDirectory
import org.gradle.api.tasks.OutputDirectory
import org.gradle.api.tasks.PathSensitive
import org.gradle.api.tasks.PathSensitivity
import org.gradle.api.tasks.TaskAction

/**
Expand All @@ -21,10 +25,15 @@ import org.gradle.api.tasks.TaskAction
* **Please note:**
* This task is idempotent- meaning it can safely be ran multiple times on the same set of files.
*/
@CacheableTask
abstract class FiresiteTransformTask : DefaultTask() {
@get:InputDirectory
@get:PathSensitive(PathSensitivity.RELATIVE)
abstract val dackkaFiles: Property<File>

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

@TaskAction
fun build() {
val namesOfFilesWeDoNotNeed = listOf(
Expand All @@ -33,14 +42,18 @@ abstract class FiresiteTransformTask : DefaultTask() {
"packages.html",
"package-list"
)
val rootDirectory = dackkaFiles.get()
val targetDirectory = outputDirectory.get()
targetDirectory.deleteRecursively()

rootDirectory.walkTopDown().forEach {
if (it.name !in namesOfFilesWeDoNotNeed) {
val relativePath = it.toRelativeString(rootDirectory)
val newFile = it.copyTo(File("${targetDirectory.path}/$relativePath"), true)

dackkaFiles.get().walkTopDown().forEach {
if (it.name in namesOfFilesWeDoNotNeed) {
it.delete()
} else {
when (it.extension) {
"html" -> it.fixHTMLFile()
"yaml" -> it.fixYamlFile()
"html" -> newFile.fixHTMLFile()
"yaml" -> newFile.fixYamlFile()
}
}
}
Expand Down