Skip to content

Commit

Permalink
Better logging for multiline replacements
Browse files Browse the repository at this point in the history
  • Loading branch information
Krystian Panek committed Dec 20, 2019
1 parent 0b40f81 commit 8c31137
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion src/main/kotlin/com/neva/gradle/fork/config/FileHandler.kt
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,19 @@ class FileHandler(val config: Config, val file: File) {
fun replace(search: String, replace: String): FileHandler {
val content = read()
if (content.contains(search)) {
logger.info("Replacing '$search' with '$replace' in file $file")
if (search.contains("\n") || replace.contains("\n")) {
if (replace.isEmpty()) {
logger.info("Removing from file $file content:\n$search")
} else {
logger.info("Replacing content of file $file\nSearch:\n$search\nReplace:\n$replace")
}
} else {
if (replace.isEmpty()) {
logger.info("Removing from file $file content '$search'")
} else {
logger.info("Replacing '$search' with '${replace.ifBlank { "<empty>" }}' in file $file")
}
}

val updatedContent = content.replace(search, replace)
write(updatedContent)
Expand Down

0 comments on commit 8c31137

Please sign in to comment.