Add teamcity problems when generating files instead of exception
This commit is contained in:
committed by
TeamCityServer
parent
3757bd0c1f
commit
14ead33db6
+1
-3
@@ -20,9 +20,7 @@ fun removeExtraFilesFromPreviousGeneration(previouslyGeneratedFiles: List<File>,
|
||||
|
||||
for (file in previouslyGeneratedFiles) {
|
||||
if (file.absolutePath !in generatedFilesPath) {
|
||||
if (GeneratorsFileUtil.isTeamCityBuild) {
|
||||
GeneratorsFileUtil.assertTeamCityMode()
|
||||
}
|
||||
if (GeneratorsFileUtil.failOnTeamCity("File delete `${file.absolutePath}`")) continue
|
||||
println("Deleted: ${file.absolutePath}")
|
||||
file.delete()
|
||||
}
|
||||
|
||||
@@ -20,7 +20,7 @@ object GeneratorsFileUtil {
|
||||
fun writeFileIfContentChanged(file: File, newText: String, logNotChanged: Boolean = true) {
|
||||
val parentFile = file.parentFile
|
||||
if (!parentFile.exists()) {
|
||||
if (isTeamCityBuild) assertTeamCityMode()
|
||||
if (failOnTeamCity("Create dir `${parentFile.path}`")) return
|
||||
if (parentFile.mkdirs()) {
|
||||
println("Directory created: " + parentFile.absolutePath)
|
||||
} else {
|
||||
@@ -33,7 +33,7 @@ object GeneratorsFileUtil {
|
||||
}
|
||||
return
|
||||
}
|
||||
if (isTeamCityBuild) assertTeamCityMode()
|
||||
if (failOnTeamCity("Write file `${file.toPath()}`")) return
|
||||
val useTempFile = !SystemInfo.isWindows
|
||||
val targetFile = file.toPath()
|
||||
val tempFile =
|
||||
@@ -47,8 +47,30 @@ object GeneratorsFileUtil {
|
||||
println()
|
||||
}
|
||||
|
||||
fun assertTeamCityMode(): Nothing {
|
||||
throw IllegalStateException("You should commit all newly generated files before pushing them to TeamCity")
|
||||
fun failOnTeamCity(message: String): Boolean {
|
||||
if (!isTeamCityBuild) return false
|
||||
|
||||
fun String.escapeForTC(): String = StringBuilder(length).apply {
|
||||
for (char in this@escapeForTC) {
|
||||
append(
|
||||
when (char) {
|
||||
'|' -> "||"
|
||||
'\'' -> "|'"
|
||||
'\n' -> "|n"
|
||||
'\r' -> "|r"
|
||||
'[' -> "|["
|
||||
']' -> "|]"
|
||||
else -> char
|
||||
}
|
||||
)
|
||||
}
|
||||
}.toString()
|
||||
|
||||
val fullMessage = "[Re-generation needed!] $message\n" +
|
||||
"Run correspondent (check the log above) Gradle task locally and commit changes."
|
||||
|
||||
println("##teamcity[buildProblem description='${fullMessage.escapeForTC()}']")
|
||||
return true
|
||||
}
|
||||
|
||||
fun isFileContentChangedIgnoringLineSeparators(file: File, content: String): Boolean {
|
||||
|
||||
Reference in New Issue
Block a user