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,19 +36,13 @@ class AsciiArt {
val horizontalSingleLine = "\u2500\u2500\u2500\u2500\u2500"
val horizontalDoubleLine = "\u2550\u2550\u2550\u2550\u2550"
val verticalBar = "\u2551"
// fun horizontalLine(n: Int) = StringBuffer().apply {
// repeat(n, { append("\u2500") })
// }.toString()
fun box(strings: List<String>) : List<String> {
val ul = "\u2554"
val ur = "\u2557"
val h = "\u2550"
val v = "\u2551"
val bl = "\u255a"
val br = "\u255d"
// Repeat
fun r(n: Int, w: String) : String {
with(StringBuffer()) {
repeat(n, { append(w) })
@ -56,11 +50,28 @@ class AsciiArt {
}
}
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 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.add(bl + r(max + 2, h) + br)
result.add(lowerBox(max, bl, br))
return result
}
@ -68,14 +79,15 @@ class AsciiArt {
val defaultLog : (s: String) -> Unit = { log(1, " $it") }
fun logBox(strings: List<String>, print: (String) -> Unit = defaultLog) {
box(strings).forEach {
fun logBox(strings: List<String>, bl: String = bottomLeft, br: String = bottomRight,
print: (String) -> Unit = defaultLog) {
box(strings, bl, br).forEach {
print(it)
}
}
fun logBox(s: String, print: (String) -> Unit = defaultLog) {
logBox(listOf(s), print)
fun logBox(s: String, bl: String = bottomLeft, br: String = bottomRight, print: (String) -> Unit = defaultLog) {
logBox(listOf(s), bl, br, print)
}
fun center(s: String, width: Int) : String {

View file

@ -42,7 +42,7 @@ class ResolveDependency @Inject constructor(
val seen = hashSetOf(dep.id)
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)
println("")

View file

@ -35,11 +35,18 @@ class BuildListeners : IBuildListener, IBuildReportContributor {
}
log(1, "\n")
log(1, "\n" + AsciiArt.horizontalSingleLine + " Build status")
}
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 ->
log(1, " " + pair.first.name + " " + pair.second)
}
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))
}