1
0
Fork 0
mirror of https://github.com/ethauvin/kobalt.git synced 2025-04-26 08:27:12 -07:00

Better build reports.

This commit is contained in:
Cedric Beust 2016-07-30 10:35:21 -07:00
parent 8168d263e0
commit c23007f82b
3 changed files with 43 additions and 24 deletions

View file

@ -36,31 +36,42 @@ class AsciiArt {
val horizontalSingleLine = "\u2500\u2500\u2500\u2500\u2500" val horizontalSingleLine = "\u2500\u2500\u2500\u2500\u2500"
val horizontalDoubleLine = "\u2550\u2550\u2550\u2550\u2550" val horizontalDoubleLine = "\u2550\u2550\u2550\u2550\u2550"
val verticalBar = "\u2551"
// fun horizontalLine(n: Int) = StringBuffer().apply { // fun horizontalLine(n: Int) = StringBuffer().apply {
// repeat(n, { append("\u2500") }) // repeat(n, { append("\u2500") })
// }.toString() // }.toString()
fun box(strings: List<String>) : List<String> { // Repeat
val ul = "\u2554" fun r(n: Int, w: String) : String {
val ur = "\u2557" with(StringBuffer()) {
val h = "\u2550" repeat(n, { append(w) })
val v = "\u2551" return toString()
val bl = "\u255a"
val br = "\u255d"
fun r(n: Int, w: String) : String {
with(StringBuffer()) {
repeat(n, { append(w) })
return toString()
}
} }
}
val h = "\u2550"
val ul = "\u2554"
val ur = "\u2557"
val bottomLeft = "\u255a"
val bottomRight = "\u255d"
// Bottom left with continuation
val bottomLeft2 = "\u2560"
// Bottom right with continuation
val bottomRight2 = "\u2563"
fun upperBox(max: Int) = ul + r(max + 2, h) + ur
fun lowerBox(max: Int, bl: String = bottomLeft, br : String = bottomRight) = bl + r(max + 2, h) + br
private fun box(strings: List<String>, bl: String = bottomLeft, br: String = bottomRight) : List<String> {
val v = verticalBar
val maxString: String = strings.maxBy { it.length } ?: "" val maxString: String = strings.maxBy { it.length } ?: ""
val max = maxString.length val max = maxString.length
val result = arrayListOf(ul + r(max + 2, h) + ur) val result = arrayListOf(upperBox(max))
result.addAll(strings.map { "$v ${center(it, max - 2)} $v" }) result.addAll(strings.map { "$v ${center(it, max - 2)} $v" })
result.add(bl + r(max + 2, h) + br) result.add(lowerBox(max, bl, br))
return result return result
} }
@ -68,14 +79,15 @@ class AsciiArt {
val defaultLog : (s: String) -> Unit = { log(1, " $it") } val defaultLog : (s: String) -> Unit = { log(1, " $it") }
fun logBox(strings: List<String>, print: (String) -> Unit = defaultLog) { fun logBox(strings: List<String>, bl: String = bottomLeft, br: String = bottomRight,
box(strings).forEach { print: (String) -> Unit = defaultLog) {
box(strings, bl, br).forEach {
print(it) print(it)
} }
} }
fun logBox(s: String, print: (String) -> Unit = defaultLog) { fun logBox(s: String, bl: String = bottomLeft, br: String = bottomRight, print: (String) -> Unit = defaultLog) {
logBox(listOf(s), print) logBox(listOf(s), bl, br, print)
} }
fun center(s: String, width: Int) : String { fun center(s: String, width: Int) : String {

View file

@ -42,7 +42,7 @@ class ResolveDependency @Inject constructor(
val seen = hashSetOf(dep.id) val seen = hashSetOf(dep.id)
root.addChildren(findChildren(root, seen)) root.addChildren(findChildren(root, seen))
AsciiArt.logBox(listOf(dep.id, url, dep.jarFile.get()).map { " $it" }, {s -> println(s) }) AsciiArt.logBox(listOf(dep.id, url, dep.jarFile.get()).map { " $it" }, print = {s -> println(s) })
display(root.children) display(root.children)
println("") println("")

View file

@ -35,12 +35,19 @@ class BuildListeners : IBuildListener, IBuildReportContributor {
} }
log(1, "\n") log(1, "\n")
log(1, "\n" + AsciiArt.horizontalSingleLine + " Build status")
projectStatuses.forEach { pair ->
log(1, " " + pair.first.name + " " + pair.second)
}
} }
fun col1(s: String) = String.format(" %1\$-30s", s)
fun col2(s: String) = String.format(" %1\$-10s", s)
val line = listOf(col1("Project"), col2("Build status")).joinToString(AsciiArt.verticalBar)
AsciiArt.logBox(listOf(line), AsciiArt.bottomLeft2, AsciiArt.bottomRight2)
projectStatuses.forEach { pair ->
val cl = listOf(col1(pair.first.name), col2(pair.second.toString())).joinToString(AsciiArt.verticalBar)
log(1, " " + AsciiArt.verticalBar + " " + cl + " " + AsciiArt.verticalBar)
}
log(1, " " + AsciiArt.lowerBox(line.length))
} }