Skip to content

Commit 80ae555

Browse files
authored
Fix StoneTask cache misses (#530)
* fix StoneTask cacheability
1 parent ef82f15 commit 80ae555

File tree

2 files changed

+27
-15
lines changed

2 files changed

+27
-15
lines changed

stone-java-gradle-plugin/src/main/kotlin/com/dropbox/stone/java/StonePlugin.kt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ package com.dropbox.stone.java
33
import org.gradle.api.Plugin
44
import org.gradle.api.Project
55
import org.gradle.api.plugins.JavaPluginExtension
6-
import org.gradle.api.tasks.PathSensitivity
76
import org.gradle.api.tasks.SourceSet
87
import org.gradle.api.tasks.compile.JavaCompile
98
import org.gradle.kotlin.dsl.withType
@@ -58,7 +57,7 @@ class StonePlugin : Plugin<Project> {
5857
val mySpecDir: String = specDirPropNameValue ?: "src/${sourceSet.name}/stone"
5958
specDir.set(File(mySpecDir))
6059

61-
generatorDir.set(File("${project.projectDir.absoluteFile}/generator/java"))
60+
generatorFile.set(File("${project.projectDir}/generator/java/java.stoneg.py"))
6261
stoneDir.set(File("stone"))
6362
pythonCommand.set("python")
6463
outputDir.set(File("${project.buildDir}/generated/source/stone/${sourceSet.name}"))

stone-java-gradle-plugin/src/main/kotlin/com/dropbox/stone/java/StoneTask.kt

Lines changed: 26 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import org.gradle.process.ExecOperations
1111
import java.io.File
1212
import java.io.FileOutputStream
1313
import javax.inject.Inject
14+
import org.gradle.api.file.ConfigurableFileCollection
1415

1516
@CacheableTask
1617
abstract class StoneTask : DefaultTask() {
@@ -21,44 +22,56 @@ abstract class StoneTask : DefaultTask() {
2122
@get:Input
2223
abstract val stoneConfigs: ListProperty<StoneConfig>
2324

24-
@get:InputDirectory
25+
@get:InputFile
2526
@get:PathSensitive(PathSensitivity.RELATIVE)
26-
abstract val generatorDir: DirectoryProperty
27+
abstract val generatorFile: RegularFileProperty
2728

28-
@get:InputDirectory
29-
@get:PathSensitive(PathSensitivity.RELATIVE)
29+
@get:Internal
3030
abstract val specDir: DirectoryProperty
3131

32+
@get:InputFiles
33+
@get:PathSensitive(PathSensitivity.RELATIVE)
34+
abstract val specFiles: ConfigurableFileCollection
35+
3236
@get:Optional
3337
@get:InputFile
3438
@get:PathSensitive(PathSensitivity.RELATIVE)
3539
abstract val routeWhitelistFilter: RegularFileProperty
3640

37-
@get:InputDirectory
38-
@get:PathSensitive(PathSensitivity.RELATIVE)
41+
@get:Internal
3942
abstract val stoneDir: DirectoryProperty
4043

44+
@get:InputFiles
45+
@get:PathSensitive(PathSensitivity.RELATIVE)
46+
abstract val stoneFiles: ConfigurableFileCollection
47+
4148
@get:Input
4249
abstract val pythonCommand: Property<String>
4350

4451
@get:OutputDirectory
4552
abstract val outputDir: DirectoryProperty
4653

54+
init {
55+
stoneFiles.setFrom(stoneDir.asFileTree.matching {
56+
include("**/*.py")
57+
})
58+
59+
specFiles.setFrom(specDir.asFileTree.matching {
60+
include("**/*.stone")
61+
})
62+
}
63+
4764
@TaskAction
4865
fun processStone() {
4966
check(stoneDir.get().asFile.exists()) {
50-
"Stone directory ${stoneDir} does not exist. " +
67+
"Stone directory $stoneDir does not exist. " +
5168
"Please run `./update-submodules` to download the stone submodule."
5269
}
5370

5471
val outputDirectory = outputDir.asFile.get()
5572
outputDirectory.deleteRecursively()
5673
outputDirectory.mkdirs()
5774

58-
val generatorFile = generatorDir.asFileTree.matching {
59-
exclude("**/*.pyc")
60-
}.singleFile
61-
6275
val specFiles = specDir.asFileTree.matching {
6376
include("**/*.stone")
6477
}.files
@@ -83,7 +96,7 @@ abstract class StoneTask : DefaultTask() {
8396
pythonCommand.get(), "-m", "stone.cli",
8497
"--attribute", ":all",
8598

86-
generatorFile.absolutePath,
99+
generatorFile.get().asFile,
87100
outputDirectory.resolve("src").absolutePath,
88101
*specFiles.map { it.absolutePath }.toTypedArray(),
89102
"--", "--package", stoneConfig.packageName,
@@ -124,7 +137,7 @@ abstract class StoneTask : DefaultTask() {
124137

125138
private fun buildRouteFilter(stoneConfig: StoneConfig): String {
126139
val client = stoneConfig.client
127-
val routeFilters = listOf(stoneConfig.globalRouteFilter, client?.routeFilter).filterNotNull()
140+
val routeFilters = listOfNotNull(stoneConfig.globalRouteFilter, client?.routeFilter)
128141
return routeFilters.joinToString(" and ") { "(${it})" }
129142
}
130143
}

0 commit comments

Comments
 (0)