Skip to content

Commit

Permalink
fix stone cacheability
Browse files Browse the repository at this point in the history
  • Loading branch information
devPalacio committed Mar 19, 2024
1 parent de23905 commit 0a8f510
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package com.dropbox.stone.java
import org.gradle.api.Plugin
import org.gradle.api.Project
import org.gradle.api.plugins.JavaPluginExtension
import org.gradle.api.tasks.PathSensitivity
import org.gradle.api.tasks.SourceSet
import org.gradle.api.tasks.compile.JavaCompile
import org.gradle.kotlin.dsl.withType
Expand Down Expand Up @@ -58,7 +57,7 @@ class StonePlugin : Plugin<Project> {
val mySpecDir: String = specDirPropNameValue ?: "src/${sourceSet.name}/stone"
specDir.set(File(mySpecDir))

generatorDir.set(File("${project.projectDir.absoluteFile}/generator/java"))
generatorFile.set(File("${project.projectDir}/generator/java/java.stoneg.py"))
stoneDir.set(File("stone"))
pythonCommand.set("python")
outputDir.set(File("${project.buildDir}/generated/source/stone/${sourceSet.name}"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import org.gradle.process.ExecOperations
import java.io.File
import java.io.FileOutputStream
import javax.inject.Inject
import org.gradle.api.file.ConfigurableFileCollection

@CacheableTask
abstract class StoneTask : DefaultTask() {
Expand All @@ -21,44 +22,55 @@ abstract class StoneTask : DefaultTask() {
@get:Input
abstract val stoneConfigs: ListProperty<StoneConfig>

@get:InputDirectory
@get:PathSensitive(PathSensitivity.RELATIVE)
abstract val generatorDir: DirectoryProperty
@get:Internal
abstract val generatorFile: RegularFileProperty

@get:InputDirectory
@get:PathSensitive(PathSensitivity.RELATIVE)
@get:Internal
abstract val specDir: DirectoryProperty

@get:InputFiles
@get:PathSensitive(PathSensitivity.RELATIVE)
abstract val specFiles: ConfigurableFileCollection

@get:Optional
@get:InputFile
@get:PathSensitive(PathSensitivity.RELATIVE)
abstract val routeWhitelistFilter: RegularFileProperty

@get:InputDirectory
@get:PathSensitive(PathSensitivity.RELATIVE)
@get:Internal
abstract val stoneDir: DirectoryProperty

@get:InputFiles
@get:PathSensitive(PathSensitivity.RELATIVE)
abstract val stoneFiles: ConfigurableFileCollection

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

@get:OutputDirectory
abstract val outputDir: DirectoryProperty

init {
stoneFiles.setFrom(stoneDir.asFileTree.matching {
include("**/*.py")
})

specFiles.setFrom(specDir.asFileTree.matching {
include("**/*.stone")
})
}

@TaskAction
fun processStone() {
check(stoneDir.get().asFile.exists()) {
"Stone directory ${stoneDir} does not exist. " +
"Stone directory $stoneDir does not exist. " +
"Please run `./update-submodules` to download the stone submodule."
}

val outputDirectory = outputDir.asFile.get()
outputDirectory.deleteRecursively()
outputDirectory.mkdirs()

val generatorFile = generatorDir.asFileTree.matching {
exclude("**/*.pyc")
}.singleFile

val specFiles = specDir.asFileTree.matching {
include("**/*.stone")
}.files
Expand All @@ -83,7 +95,7 @@ abstract class StoneTask : DefaultTask() {
pythonCommand.get(), "-m", "stone.cli",
"--attribute", ":all",

generatorFile.absolutePath,
generatorFile.get().asFile,
outputDirectory.resolve("src").absolutePath,
*specFiles.map { it.absolutePath }.toTypedArray(),
"--", "--package", stoneConfig.packageName,
Expand Down Expand Up @@ -124,7 +136,7 @@ abstract class StoneTask : DefaultTask() {

private fun buildRouteFilter(stoneConfig: StoneConfig): String {
val client = stoneConfig.client
val routeFilters = listOf(stoneConfig.globalRouteFilter, client?.routeFilter).filterNotNull()
val routeFilters = listOfNotNull(stoneConfig.globalRouteFilter, client?.routeFilter)
return routeFilters.joinToString(" and ") { "(${it})" }
}
}

0 comments on commit 0a8f510

Please sign in to comment.