Files
detekt/build-logic/src/main/kotlin/UpdateVersionInFileTask.kt
Matthew Haughton fd0cb9096e Migrate buildSrc to composite build (#4090)
This will help reduce build times when changes are made to the precompiled
script plugins used in the build. This is because a change in buildSrc
causes the whole project to become out-of-date [0]. Using an included build
instead works around this problem.

[0] https://docs.gradle.org/7.2/userguide/organizing_gradle_projects.html#sec:build_sources
2021-09-04 23:09:59 +10:00

30 lines
847 B
Kotlin

import org.gradle.api.DefaultTask
import org.gradle.api.file.RegularFileProperty
import org.gradle.api.provider.Property
import org.gradle.api.tasks.Input
import org.gradle.api.tasks.InputFile
import org.gradle.api.tasks.TaskAction
abstract class UpdateVersionInFileTask : DefaultTask() {
@get:InputFile
abstract val fileToUpdate: RegularFileProperty
@get:Input
abstract val linePartToFind: Property<String>
@get:Input
abstract val lineTransformation: Property<String>
@TaskAction
fun run() {
val newContent = fileToUpdate.asFile.get().readLines()
.joinToString(LN) { if (it.contains(linePartToFind.get())) lineTransformation.get() else it }
fileToUpdate.asFile.get().writeText("$newContent$LN")
}
companion object {
val LN: String = System.lineSeparator()
}
}