[Test] Don't generate new files in GeneratorsFileUtil in teamcity mode

This commit is contained in:
Dmitriy Novozhilov
2021-01-29 16:29:26 +03:00
parent 772ca2715c
commit 297288e984
+9 -1
View File
@@ -11,6 +11,8 @@ import java.io.IOException
import kotlin.io.path.* import kotlin.io.path.*
object GeneratorsFileUtil { object GeneratorsFileUtil {
private val isTeamCityBuild: Boolean = System.getProperty("TEAMCITY_VERSION") != null
@OptIn(ExperimentalPathApi::class) @OptIn(ExperimentalPathApi::class)
@JvmStatic @JvmStatic
@JvmOverloads @JvmOverloads
@@ -18,6 +20,7 @@ object GeneratorsFileUtil {
fun writeFileIfContentChanged(file: File, newText: String, logNotChanged: Boolean = true) { fun writeFileIfContentChanged(file: File, newText: String, logNotChanged: Boolean = true) {
val parentFile = file.parentFile val parentFile = file.parentFile
if (!parentFile.exists()) { if (!parentFile.exists()) {
if (isTeamCityBuild) assertTeamCityMode()
if (parentFile.mkdirs()) { if (parentFile.mkdirs()) {
println("Directory created: " + parentFile.absolutePath) println("Directory created: " + parentFile.absolutePath)
} else { } else {
@@ -30,6 +33,7 @@ object GeneratorsFileUtil {
} }
return return
} }
if (isTeamCityBuild) assertTeamCityMode()
val useTempFile = !SystemInfo.isWindows val useTempFile = !SystemInfo.isWindows
val targetFile = file.toPath() val targetFile = file.toPath()
val tempFile = val tempFile =
@@ -43,6 +47,10 @@ object GeneratorsFileUtil {
println() println()
} }
private fun assertTeamCityMode(): Nothing {
throw IllegalStateException("You should commit all newly generated files before pushing them to TeamCity")
}
fun isFileContentChangedIgnoringLineSeparators(file: File, content: String): Boolean { fun isFileContentChangedIgnoringLineSeparators(file: File, content: String): Boolean {
val currentContent: String = try { val currentContent: String = try {
StringUtil.convertLineSeparators(file.readText(Charsets.UTF_8)) StringUtil.convertLineSeparators(file.readText(Charsets.UTF_8))
@@ -51,4 +59,4 @@ object GeneratorsFileUtil {
} }
return StringUtil.convertLineSeparators(content) != currentContent return StringUtil.convertLineSeparators(content) != currentContent
} }
} }