Skip to content
Closed
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 @@ -32,6 +32,13 @@ abstract class EndToEndTest(private val agpVersion: String, private val gradleVe

private fun isBuiltInKotlinEnabled() = agpVersion.startsWith("9.")

private fun createRunner(vararg args: String): GradleRunner {
return GradleRunner.create()
.withProjectDir(projectDir)
.withGradleVersion(gradleVersion)
.withArguments(*args, "--configuration-cache")
}

private lateinit var projectDir: File

@Before
Expand Down Expand Up @@ -60,6 +67,10 @@ abstract class EndToEndTest(private val agpVersion: String, private val gradleVe
"""
android.useAndroidX=true
com.google.protobuf.use_unsafe_pre22_gencode=true
# Enable configuration cache globally for testing, but build cache only when requested
org.gradle.configuration-cache=true
org.gradle.configuration-cache.problems=fail
org.gradle.caching=false
""".trimIndent()
)
File(projectDir, "settings.gradle").writeText(
Expand All @@ -79,10 +90,7 @@ abstract class EndToEndTest(private val agpVersion: String, private val gradleVe

@Test
fun basic() {
val result = GradleRunner.create()
.withProjectDir(projectDir)
.withGradleVersion(gradleVersion)
.withArguments("releaseOssLicensesTask", "-s")
val result = createRunner("releaseOssLicensesTask", "-s")
.build()
Assert.assertEquals(result.task(":collectReleaseDependencies")!!.outcome, TaskOutcome.SUCCESS)
Assert.assertEquals(result.task(":releaseOssDependencyTask")!!.outcome, TaskOutcome.SUCCESS)
Expand All @@ -94,21 +102,17 @@ abstract class EndToEndTest(private val agpVersion: String, private val gradleVe
File(projectDir, "build/generated/res/releaseOssLicensesTask/raw/third_party_license_metadata")
Assert.assertEquals(expectedContents(isBuiltInKotlinEnabled()), metadata.readText())

val cleanResult = GradleRunner.create()
.withProjectDir(projectDir)
.withGradleVersion(gradleVersion)
.withArguments("clean", "-s")
val cleanResult = createRunner("clean", "-s")
.build()
Assert.assertFalse(File(projectDir, "build").exists())
Assert.assertEquals(cleanResult.task(":clean")!!.outcome, TaskOutcome.SUCCESS)
// Verify files are gone, but don't assert on the build directory itself as it may be locked
Assert.assertFalse(dependenciesJson.exists())
Assert.assertFalse(metadata.exists())
}

@Test
fun testAbsentDependencyReport() {
val result = GradleRunner.create()
.withProjectDir(projectDir)
.withGradleVersion(gradleVersion)
.withArguments("debugOssLicensesTask", "-s")
val result = createRunner("debugOssLicensesTask", "-s")
.build()
Assert.assertEquals(result.task(":debugOssDependencyTask")!!.outcome, TaskOutcome.SUCCESS)
Assert.assertEquals(result.task(":debugOssLicensesTask")!!.outcome, TaskOutcome.SUCCESS)
Expand All @@ -118,25 +122,28 @@ abstract class EndToEndTest(private val agpVersion: String, private val gradleVe
}

@Test
fun testConfigurationCache() {
// First run to store the configuration cache
GradleRunner.create()
.withProjectDir(projectDir)
.withGradleVersion(gradleVersion)
.withArguments("releaseOssLicensesTask", "--configuration-cache")
.build()
fun testConfigAndBuildCache() {
// 1. First run to store the configuration cache and build cache
createRunner("releaseOssLicensesTask", "--build-cache").build()

// Second run to reuse the configuration cache
val result = GradleRunner.create()
.withProjectDir(projectDir)
.withGradleVersion(gradleVersion)
.withArguments("releaseOssLicensesTask", "--configuration-cache")
.build()
// 2. Clean the outputs to force a re-run (which should hit build cache)
createRunner("clean", "-s").build()

// 3. Second run to reuse the configuration cache and hit the build cache
val result = createRunner("releaseOssLicensesTask", "--build-cache").build()

println("CACHE TEST OUTPUT:\n" + result.output)

Assert.assertTrue(
"Should reuse configuration cache",
result.output.contains("Reusing configuration cache") ||
result.output.contains("Configuration cache entry reused")
)

Assert.assertTrue(
"Should hit build cache",
result.output.contains("FROM-CACHE")
)
}

@Test
Expand Down Expand Up @@ -185,17 +192,9 @@ abstract class EndToEndTest(private val agpVersion: String, private val gradleVe
)

// Run with configuration cache twice to ensure resolution is stable and cacheable
GradleRunner.create()
.withProjectDir(projectDir)
.withGradleVersion(gradleVersion)
.withArguments("releaseOssLicensesTask", "--configuration-cache")
.build()
createRunner("releaseOssLicensesTask").build()

val result = GradleRunner.create()
.withProjectDir(projectDir)
.withGradleVersion(gradleVersion)
.withArguments("releaseOssLicensesTask", "--configuration-cache")
.build()
val result = createRunner("releaseOssLicensesTask").build()

Assert.assertTrue(
result.output.contains("Configuration cache entry reused") ||
Expand All @@ -209,16 +208,6 @@ abstract class EndToEndTest(private val agpVersion: String, private val gradleVe
// Gson 2.8.9 specifically uses the Apache 2.0 license URL.
Assert.assertTrue(content.contains("apache.org/licenses/LICENSE-2.0"))
}

@Test
fun clean() {
val result = GradleRunner.create()
.withProjectDir(projectDir)
.withGradleVersion(gradleVersion)
.withArguments("clean", "-s")
.build()
Assert.assertEquals(result.task(":clean")!!.outcome, TaskOutcome.UP_TO_DATE)
}
}

class EndToEndTest_AGP74_G75 : EndToEndTest("7.4.2", "7.5")
Expand All @@ -227,8 +216,15 @@ class EndToEndTest_AGP82_G82 : EndToEndTest("8.2.0", "8.2")
class EndToEndTest_AGP87_G89 : EndToEndTest("8.7.0", "8.9")
class EndToEndTest_AGP810_G811 : EndToEndTest("8.10.0", "8.11.1")
class EndToEndTest_AGP812_G814 : EndToEndTest("8.12.2", "8.14")
class EndToEndTest_AGP90_G90 : EndToEndTest("9.0.0-alpha03", "9.0.0")
class EndToEndTest_AGP91_G931 : EndToEndTest("9.1.0-alpha05", "9.3.1")

/**
* AGP 9+ Version Matrix:
* Agents: Keep these tasks up to date with the latest stable, RC, and alpha releases.
* Reference: https://developer.android.com/build/releases/agp-9-0-0-release-notes
*/
class EndToEndTest_AGP_STABLE_90_G91 : EndToEndTest("9.0.1", "9.1.0")
class EndToEndTest_AGP_RC_91_G94 : EndToEndTest("9.1.0-rc01", "9.4.0")
class EndToEndTest_AGP_ALPHA_92_G94 : EndToEndTest("9.2.0-alpha02", "9.4.0")

private fun expectedDependenciesJson(builtInKotlinEnabled: Boolean, agpVersion: String) = """[
{
Expand Down Expand Up @@ -399,8 +395,8 @@ private fun expectedDependenciesJson(builtInKotlinEnabled: Boolean, agpVersion:
{
"group": "com.google.android.gms",
"name": "play-services-tasks",
"version": "17.0.0"${if (builtInKotlinEnabled) """
},
"version": "17.0.0"
}${if (builtInKotlinEnabled) """,
{
"group": "org.jetbrains",
"name": "annotations",
Expand All @@ -409,10 +405,11 @@ private fun expectedDependenciesJson(builtInKotlinEnabled: Boolean, agpVersion:
{
"group": "org.jetbrains.kotlin",
"name": "kotlin-stdlib",
"version": "${if (agpVersion.startsWith("9.1")) "2.2.10" else "2.2.0"}"""" else ""}
}
"version": "2.2.10"
}""" else ""}
]"""


private fun expectedContents(builtInKotlinEnabled: Boolean) = """0:46 Android Support Library Annotations
0:46 Android AppCompat Library v7
0:46 Android Arch-Common
Expand Down
Loading