Skip to content

Commit 19b7315

Browse files
danysantiagoDagger Team
authored and
Dagger Team
committed
Add cache relocation test for when 'enableAggregatingTask = true'
Fixes: google#2794 RELNOTES=n/a PiperOrigin-RevId: 390118580
1 parent 509669d commit 19b7315

File tree

1 file changed

+44
-33
lines changed

1 file changed

+44
-33
lines changed

java/dagger/hilt/android/plugin/src/test/kotlin/BuildCacheTest.kt

+44-33
Original file line numberDiff line numberDiff line change
@@ -22,20 +22,18 @@ import org.junit.Before
2222
import org.junit.Rule
2323
import org.junit.Test
2424
import org.junit.rules.TemporaryFolder
25+
import org.junit.runner.RunWith
26+
import org.junit.runners.Parameterized
2527

2628
// Test that verifies the hilt class transform does not break the Gradle's remote build cache.
27-
class BuildCacheTest {
28-
@get:Rule
29-
val gradleHomeFolder = TemporaryFolder()
30-
31-
@get:Rule
32-
val firstProjectDir = TemporaryFolder()
29+
@RunWith(Parameterized::class)
30+
class BuildCacheTest(private val enableAggregatingTask: Boolean) {
31+
@get:Rule val gradleHomeFolder = TemporaryFolder()
3332

33+
@get:Rule val firstProjectDir = TemporaryFolder()
3434
lateinit var firstGradleRunner: GradleTestRunner
3535

36-
@get:Rule
37-
val secondProjectDir = TemporaryFolder()
38-
36+
@get:Rule val secondProjectDir = TemporaryFolder()
3937
lateinit var secondGradleRunner: GradleTestRunner
4038

4139
private val testId = UUID.randomUUID().toString()
@@ -57,7 +55,7 @@ class BuildCacheTest {
5755
gradleRunner.addSrc(
5856
srcPath = "minimal/MyApp.java",
5957
srcContent =
60-
"""
58+
"""
6159
package minimal;
6260
6361
import android.app.Application;
@@ -71,6 +69,7 @@ class BuildCacheTest {
7169
""".trimIndent()
7270
)
7371
gradleRunner.setAppClassName(".MyApp")
72+
gradleRunner.addHiltOption("enableAggregatingTask = $enableAggregatingTask")
7473
return gradleRunner
7574
}
7675

@@ -81,32 +80,44 @@ class BuildCacheTest {
8180
assertEquals(firstResult.getTask(":transformDebugClassesWithAsm").outcome, SUCCESS)
8281

8382
val secondResult = secondGradleRunner.build()
84-
val cacheableTasks = listOf(
85-
":checkDebugAarMetadata",
86-
":checkDebugDuplicateClasses",
87-
":compileDebugJavaWithJavac",
88-
":compressDebugAssets",
89-
":extractDeepLinksDebug",
90-
":generateDebugBuildConfig",
91-
":generateDebugResValues",
92-
":javaPreCompileDebug",
93-
":mergeDebugAssets",
94-
":mergeDebugJavaResource",
95-
":mergeDebugJniLibFolders",
96-
":mergeDebugNativeLibs",
97-
":mergeDebugShaders",
98-
":mergeExtDexDebug",
99-
":mergeLibDexDebug",
100-
":mergeProjectDexDebug",
101-
":processDebugManifestForPackage",
102-
":transformDebugClassesWithAsm",
103-
":validateSigningDebug",
104-
":writeDebugAppMetadata",
105-
":writeDebugSigningConfigVersions",
106-
)
83+
val cacheableTasks: List<String> = mutableListOf<String>().apply {
84+
add(":checkDebugAarMetadata")
85+
add(":checkDebugDuplicateClasses")
86+
add(":compileDebugJavaWithJavac")
87+
add(":compressDebugAssets")
88+
add(":extractDeepLinksDebug")
89+
add(":generateDebugBuildConfig")
90+
add(":generateDebugResValues")
91+
// When aggregating task is enabled, the plugin adds two more tasks that should be
92+
// cacheable.
93+
if (enableAggregatingTask) {
94+
add(":hiltAggregateDepsDebug")
95+
add(":hiltJavaCompileDebug")
96+
}
97+
add(":javaPreCompileDebug")
98+
add(":mergeDebugAssets")
99+
add(":mergeDebugJavaResource")
100+
add(":mergeDebugJniLibFolders")
101+
add(":mergeDebugNativeLibs")
102+
add(":mergeDebugShaders")
103+
add(":mergeExtDexDebug")
104+
add(":mergeLibDexDebug")
105+
add(":mergeProjectDexDebug")
106+
add(":processDebugManifestForPackage")
107+
add(":transformDebugClassesWithAsm")
108+
add(":validateSigningDebug")
109+
add(":writeDebugAppMetadata")
110+
add(":writeDebugSigningConfigVersions")
111+
}
107112

108113
val tasksFromCache =
109114
secondResult.tasks.filter { it.outcome == FROM_CACHE }.map { it.path }.sorted()
110115
assertEquals(cacheableTasks, tasksFromCache)
111116
}
117+
118+
companion object {
119+
@JvmStatic
120+
@Parameterized.Parameters(name = "enableAggregatingTask = {0}")
121+
fun parameters() = listOf(false, true)
122+
}
112123
}

0 commit comments

Comments
 (0)