Skip to content

Commit

Permalink
Only update versions in specific files, to avoid reading and writing …
Browse files Browse the repository at this point in the history
…to lots of files
  • Loading branch information
adam-enko committed Nov 13, 2024
1 parent 2b37748 commit ddcd84c
Showing 1 changed file with 21 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -71,27 +71,27 @@ fun interface GradleTestProjectInitializer {
projectDir: Path,
testedVersions: TestedVersions,
) {
projectDir.walk().filter { it.isRegularFile() }.forEach { file ->
file.writeText(
file.readText()
.replace("/* %{KGP_VERSION} */", testedVersions.kgp.version)
.replace("/* %{DGP_VERSION} */", testedVersions.dgp.version)
.run {
if (testedVersions.agp != null) {
replace("/* %{AGP_VERSION} */", testedVersions.agp.version)
} else {
this
}
}
.run {
if (testedVersions.composeGradlePlugin != null) {
replace("/* %{COMPOSE_VERSION} */", testedVersions.composeGradlePlugin.version)
} else {
this
}
}
)
}
// Only update versions in specific files, to avoid reading and writing to lots of files.
val namesOfFilesWithVersions = setOf(
"build.gradle.kts",
"settings.gradle.kts",
"libs.versions.toml",
)

projectDir.walk()
.filter { it.isRegularFile() && it.name in namesOfFilesWithVersions }
.forEach { file ->
file.writeText(
file.readText()
.replace("/* %{KGP_VERSION} */", testedVersions.kgp.version)
.replace("/* %{DGP_VERSION} */", testedVersions.dgp.version)
.replace("/* %{AGP_VERSION} */", testedVersions.agp?.version ?: "Missing AGP version")
.replace(
"/* %{COMPOSE_VERSION} */",
testedVersions.composeGradlePlugin?.version ?: "Missing Compose version"
)
)
}
}

private fun initialiseAndroid(
Expand Down

0 comments on commit ddcd84c

Please sign in to comment.