com.qxml.transform.generate.tools.GenReportTool.kt Maven / Gradle / Ivy
package com.qxml.transform.generate.tools
import com.qxml.tools.LayoutTypeNameCorrect
import com.qxml.transform.generate.GenResult
import com.qxml.transform.generate.ViewGenResultInfo
import java.io.File
import java.lang.StringBuilder
object GenReportTool {
private const val TABLE_HEAD = "\n" +
"\n" +
"\n" +
" LayoutName LayoutType Info \n" +
" "
@JvmStatic
fun genReport(reportFile: File, genResultMap: Map>) {
if (!reportFile.parentFile.exists()) {
reportFile.parentFile.mkdirs()
}
if (!reportFile.exists()) {
reportFile.createNewFile()
}
val stringBuilder = StringBuilder()
stringBuilder.append(TABLE_HEAD).append("\n")
genResultMap.forEach { (layoutName, hashMap) ->
var firstLine = true
hashMap.forEach { (layoutType, viewGenResultInfo) ->
val firstClo = if (firstLine) {
firstLine = false
"${layoutName} "
} else ""
val bgColor = if (viewGenResultInfo.result == GenResult.SUCCESS) "#ffffff" else "#fe2047"
stringBuilder.append("\n" +
" ${firstClo}${LayoutTypeNameCorrect.toDisplayText(layoutType)} ${viewGenResultInfo.info} \n" +
" \n")
}
}
stringBuilder.append("
")
reportFile.writeText(stringBuilder.toString())
}
}