mirror of
https://github.com/ethauvin/kobalt.git
synced 2025-04-26 00:17:11 -07:00
Implemented --log 0
This commit is contained in:
parent
a6e8dbabb1
commit
014802e272
18 changed files with 76 additions and 103 deletions
|
@ -43,7 +43,7 @@ class Args {
|
|||
var listTemplates: Boolean = false
|
||||
|
||||
@Parameter(names = arrayOf("--log"), description = "Define the log level " +
|
||||
"(${Constants.LOG_DEFAULT_LEVEL}-${Constants.LOG_MAX_LEVEL})")
|
||||
"(${Constants.LOG_QUIET_LEVEL}-${Constants.LOG_MAX_LEVEL})")
|
||||
var log: Int = Constants.LOG_DEFAULT_LEVEL
|
||||
|
||||
@Parameter(names = arrayOf("--logTags"),
|
||||
|
|
|
@ -3,6 +3,7 @@ package com.beust.kobalt
|
|||
import com.beust.kobalt.misc.KFiles
|
||||
|
||||
object Constants {
|
||||
const val LOG_QUIET_LEVEL = 0
|
||||
const val LOG_DEFAULT_LEVEL = 1
|
||||
const val LOG_MAX_LEVEL = 3
|
||||
val BUILD_FILE_NAME = "Build.kt"
|
||||
|
|
|
@ -3,13 +3,8 @@ package com.beust.kobalt
|
|||
import com.beust.kobalt.api.IClasspathDependency
|
||||
import com.beust.kobalt.maven.LocalRepo
|
||||
import com.beust.kobalt.maven.MavenId
|
||||
import com.beust.kobalt.maven.aether.AetherDependency
|
||||
import com.beust.kobalt.maven.aether.Filters
|
||||
import com.beust.kobalt.maven.aether.KobaltMavenResolver
|
||||
import com.beust.kobalt.misc.KobaltExecutors
|
||||
import com.beust.kobalt.misc.Node
|
||||
import com.beust.kobalt.misc.kobaltLog
|
||||
import com.beust.kobalt.misc.warn
|
||||
import com.beust.kobalt.maven.aether.*
|
||||
import com.beust.kobalt.misc.*
|
||||
import com.google.inject.Inject
|
||||
import org.eclipse.aether.artifact.DefaultArtifact
|
||||
import org.eclipse.aether.graph.DependencyNode
|
||||
|
@ -74,7 +69,7 @@ class ResolveDependency @Inject constructor(
|
|||
kobaltLog(1, AsciiArt.logBox(listOf(dep.id, url, dep.jarFile.get()).map { " $it" }))
|
||||
|
||||
display(root.children)
|
||||
println("")
|
||||
kobaltLog(1, "")
|
||||
}
|
||||
|
||||
private fun display(nodes: List<Node<Dep>>) {
|
||||
|
@ -86,10 +81,12 @@ class ResolveDependency @Inject constructor(
|
|||
else leftMiddle
|
||||
val indent = level * increment
|
||||
for(i in 0..indent - 2) {
|
||||
if (i == 0 || ((i + 1) % increment == 0)) print(vertical)
|
||||
else print(" ")
|
||||
if (!KobaltLogger.isQuiet) {
|
||||
if (i == 0 || ((i + 1) % increment == 0)) print(vertical)
|
||||
else print(" ")
|
||||
}
|
||||
}
|
||||
println(left + " " + dep.id + (if (dep.optional) " (optional)" else ""))
|
||||
kobaltLog(1, left + " " + dep.id + (if (dep.optional) " (optional)" else ""))
|
||||
display(node.children)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,12 +1,7 @@
|
|||
package com.beust.kobalt.internal
|
||||
|
||||
import com.beust.kobalt.AsciiTable
|
||||
import com.beust.kobalt.KobaltException
|
||||
import com.beust.kobalt.TaskResult
|
||||
import com.beust.kobalt.misc.NamedThreadFactory
|
||||
import com.beust.kobalt.misc.error
|
||||
import com.beust.kobalt.misc.kobaltLog
|
||||
import com.beust.kobalt.misc.warn
|
||||
import com.beust.kobalt.*
|
||||
import com.beust.kobalt.misc.*
|
||||
import com.google.common.collect.HashMultimap
|
||||
import java.lang.reflect.InvocationTargetException
|
||||
import java.util.*
|
||||
|
@ -303,14 +298,14 @@ class DynamicGraphExecutor<T>(val graph : DynamicGraph<T>, val factory: IThreadW
|
|||
duration = " (" + ((hl.timestamp - start) / 1000)
|
||||
.toInt().toString() + ")"
|
||||
} else {
|
||||
println("DONOTCOMMIT")
|
||||
kobaltLog(1, "DONOTCOMMIT")
|
||||
}
|
||||
}
|
||||
return hl.name + duration
|
||||
}
|
||||
|
||||
historyLog.forEach { hl ->
|
||||
println("CURRENT LOG: " + currentLog + " HISTORY LINE: " + hl)
|
||||
kobaltLog(1, "CURRENT LOG: " + currentLog + " HISTORY LINE: " + hl)
|
||||
if (hl.start) {
|
||||
projectStart[hl.name] = hl.timestamp
|
||||
}
|
||||
|
@ -318,10 +313,10 @@ class DynamicGraphExecutor<T>(val graph : DynamicGraph<T>, val factory: IThreadW
|
|||
currentLog = CompressedLog(hl.timestamp, hashMapOf(hl.threadId to hl.name))
|
||||
} else currentLog?.let { cl ->
|
||||
if (! hl.start || hl.timestamp - cl.timestamp < 1000) {
|
||||
println(" CURRENT LOG IS WITHING ONE SECOND: $hl")
|
||||
kobaltLog(1, " CURRENT LOG IS WITHING ONE SECOND: $hl")
|
||||
cl.threadMap[hl.threadId] = toName(hl)
|
||||
} else {
|
||||
println(" ADDING COMPRESSED LINE $cl")
|
||||
kobaltLog(1, " ADDING COMPRESSED LINE $cl")
|
||||
compressed.add(cl)
|
||||
currentLog = CompressedLog(hl.timestamp, hashMapOf(hl.threadId to toName(hl)))
|
||||
}
|
||||
|
@ -378,7 +373,7 @@ class DynamicGraphExecutor<T>(val graph : DynamicGraph<T>, val factory: IThreadW
|
|||
return table
|
||||
}
|
||||
|
||||
println(displayRegularLog(table).build())
|
||||
kobaltLog(1, displayRegularLog(table).build())
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -2,9 +2,7 @@ package com.beust.kobalt.internal
|
|||
|
||||
import com.beust.kobalt.Args
|
||||
import com.beust.kobalt.KobaltException
|
||||
import com.beust.kobalt.misc.kobaltError
|
||||
import com.beust.kobalt.misc.kobaltLog
|
||||
import com.beust.kobalt.misc.kobaltWarn
|
||||
import com.beust.kobalt.misc.*
|
||||
import com.google.inject.Inject
|
||||
import com.google.inject.Singleton
|
||||
import java.util.*
|
||||
|
@ -69,7 +67,7 @@ class ParallelLogger @Inject constructor(val args: Args) : ILogger {
|
|||
private fun debug(s: CharSequence) {
|
||||
if (args.log >= 3) {
|
||||
val time = System.currentTimeMillis() - startTime!!
|
||||
println(" ### [$time] $s")
|
||||
kobaltLog(1, " ### [$time] $s")
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -127,6 +125,6 @@ class ParallelLogger @Inject constructor(val args: Args) : ILogger {
|
|||
runningProjects.forEach {
|
||||
emptyProjectLog(it)
|
||||
}
|
||||
println("")
|
||||
kobaltLog(1, "")
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,19 +2,11 @@ package com.beust.kobalt.internal
|
|||
|
||||
import com.beust.kobalt.AsciiArt
|
||||
import com.beust.kobalt.TestConfig
|
||||
import com.beust.kobalt.api.IClasspathDependency
|
||||
import com.beust.kobalt.api.KobaltContext
|
||||
import com.beust.kobalt.api.Project
|
||||
import com.beust.kobalt.api.*
|
||||
import com.beust.kobalt.maven.aether.AetherDependency
|
||||
import com.beust.kobalt.misc.KFiles
|
||||
import com.beust.kobalt.misc.StringVersion
|
||||
import com.beust.kobalt.misc.runCommand
|
||||
import com.beust.kobalt.misc.warn
|
||||
import com.beust.kobalt.misc.*
|
||||
import org.testng.remote.RemoteArgs
|
||||
import org.testng.remote.strprotocol.JsonMessageSender
|
||||
import org.testng.remote.strprotocol.MessageHelper
|
||||
import org.testng.remote.strprotocol.MessageHub
|
||||
import org.testng.remote.strprotocol.TestResultMessage
|
||||
import org.testng.remote.strprotocol.*
|
||||
import java.io.File
|
||||
import java.io.IOException
|
||||
|
||||
|
@ -124,8 +116,8 @@ class TestNgRunner : GenericTestRunner() {
|
|||
|
||||
try {
|
||||
var message = mh.receiveMessage()
|
||||
println("")
|
||||
println(green("PASSED") + " | " + red("FAILED") + " | " + yellow("SKIPPED"))
|
||||
kobaltLog(1, "")
|
||||
kobaltLog(1, green("PASSED") + " | " + red("FAILED") + " | " + yellow("SKIPPED"))
|
||||
while (message != null) {
|
||||
message = mh.receiveMessage()
|
||||
if (message is TestResultMessage) {
|
||||
|
@ -136,17 +128,19 @@ class TestNgRunner : GenericTestRunner() {
|
|||
MessageHelper.SKIPPED_TEST -> skipped.add(message.name)
|
||||
}
|
||||
}
|
||||
print("\r " + d(passed.size, AsciiArt.GREEN)
|
||||
+ " | " + d(failed.size, AsciiArt.RED)
|
||||
+ " | " + d(skipped.size, AsciiArt.YELLOW))
|
||||
if (!KobaltLogger.isQuiet) {
|
||||
print("\r " + d(passed.size, AsciiArt.GREEN)
|
||||
+ " | " + d(failed.size, AsciiArt.RED)
|
||||
+ " | " + d(skipped.size, AsciiArt.YELLOW))
|
||||
}
|
||||
}
|
||||
} catch(ex: IOException) {
|
||||
println("Exception: ${ex.message}")
|
||||
kobaltLog(1, "Exception: ${ex.message}")
|
||||
}
|
||||
println("\nPassed: " + passed.size + ", Failed: " + failed.size + ", Skipped: " + skipped.size)
|
||||
kobaltLog(1, "\nPassed: " + passed.size + ", Failed: " + failed.size + ", Skipped: " + skipped.size)
|
||||
failed.forEach {
|
||||
val top = it.stackTrace.substring(0, it.stackTrace.indexOf("\n"))
|
||||
println(" " + it.cls + "." + it.method + "\n " + top)
|
||||
kobaltLog(1, " " + it.cls + "." + it.method + "\n " + top)
|
||||
}
|
||||
return failed.isEmpty() && skipped.isEmpty()
|
||||
}
|
||||
|
@ -201,10 +195,12 @@ fun main(args: Array<String>) {
|
|||
fun d(n: Int, color: String)
|
||||
= AsciiArt.wrap(String.format("%4d", n), color)
|
||||
|
||||
println("PASSED | FAILED | SKIPPED")
|
||||
repeat(20) { i ->
|
||||
print("\r " + d(i, AsciiArt.GREEN) + " | " + d(i * 2, AsciiArt.RED) + " | " + d(i, AsciiArt.YELLOW))
|
||||
Thread.sleep(500)
|
||||
if (!KobaltLogger.isQuiet) {
|
||||
println("PASSED | FAILED | SKIPPED")
|
||||
repeat(20) { i ->
|
||||
print("\r " + d(i, AsciiArt.GREEN) + " | " + d(i * 2, AsciiArt.RED) + " | " + d(i, AsciiArt.YELLOW))
|
||||
Thread.sleep(500)
|
||||
}
|
||||
println("")
|
||||
}
|
||||
println("")
|
||||
}
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package com.beust.kobalt.internal.build
|
||||
|
||||
import com.beust.kobalt.homeDir
|
||||
import com.beust.kobalt.misc.kobaltLog
|
||||
import java.io.File
|
||||
import java.nio.file.*
|
||||
import java.nio.file.attribute.BasicFileAttributes
|
||||
|
@ -37,7 +38,7 @@ class BuildSources(val file: File) : IBuildSources {
|
|||
override fun preVisitDirectory(dir: Path?, attrs: BasicFileAttributes?): FileVisitResult {
|
||||
if (dir != null) {
|
||||
val path = dir.toFile()
|
||||
println(path.name)
|
||||
kobaltLog(1, path.name)
|
||||
if (path.name == "src" && path.parentFile.name == "kobalt") {
|
||||
val sources = path.listFiles().filter { it.name.endsWith(".kt")}
|
||||
result.addAll(sources)
|
||||
|
|
|
@ -1,13 +1,12 @@
|
|||
package com.beust.kobalt.maven
|
||||
|
||||
import com.beust.kobalt.misc.kobaltLog
|
||||
import org.w3c.dom.Element
|
||||
import org.xml.sax.InputSource
|
||||
import java.io.File
|
||||
import java.io.FileReader
|
||||
import javax.xml.bind.JAXBContext
|
||||
import javax.xml.bind.annotation.XmlAnyElement
|
||||
import javax.xml.bind.annotation.XmlElement
|
||||
import javax.xml.bind.annotation.XmlRootElement
|
||||
import javax.xml.bind.annotation.*
|
||||
import javax.xml.parsers.SAXParserFactory
|
||||
import javax.xml.transform.sax.SAXSource
|
||||
|
||||
|
@ -147,7 +146,7 @@ class Dependency {
|
|||
private fun expandVariable(s: String, pom: Pom2) : String {
|
||||
val variable = extractVariable(s)
|
||||
if (variable != null) {
|
||||
println("Expanding variable $variable")
|
||||
kobaltLog(2, "Expanding variable $variable")
|
||||
val value = pom.pomProject.propertyValue(variable)
|
||||
return s
|
||||
} else {
|
||||
|
|
|
@ -1,9 +1,7 @@
|
|||
package com.beust.kobalt.misc
|
||||
|
||||
import java.io.File
|
||||
import java.nio.file.Files
|
||||
import java.nio.file.Paths
|
||||
import java.nio.file.StandardCopyOption
|
||||
import java.nio.file.*
|
||||
|
||||
class Io(val dryRun: Boolean = false) {
|
||||
fun mkdirs(dir: String) {
|
||||
|
@ -47,8 +45,8 @@ class Io(val dryRun: Boolean = false) {
|
|||
if (! dryRun) {
|
||||
KFiles.copyRecursively(from, toDir)
|
||||
require(from.exists(), { -> "$from should exist" })
|
||||
require(from.isDirectory, { -> println("$from should be a directory")})
|
||||
require(toDir.isDirectory, { -> println("$toDir should be a file")})
|
||||
require(from.isDirectory, { -> kobaltLog(1, "$from should be a directory")})
|
||||
require(toDir.isDirectory, { -> kobaltLog(1, "$toDir should be a file")})
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -58,7 +56,7 @@ class Io(val dryRun: Boolean = false) {
|
|||
private fun rmDir(dir: File, keep: (File) -> Boolean, indent : String) {
|
||||
kobaltLog("rm -rf $dir")
|
||||
|
||||
require(dir.isDirectory, { -> println("$dir should be a directory")})
|
||||
require(dir.isDirectory, { -> kobaltLog(1, "$dir should be a directory")})
|
||||
|
||||
dir.listFiles({ p0 -> ! keep(p0!!) }).forEach {
|
||||
if (it.isDirectory) {
|
||||
|
|
|
@ -1,8 +1,6 @@
|
|||
package com.beust.kobalt.misc
|
||||
|
||||
import com.beust.kobalt.Args
|
||||
import com.beust.kobalt.AsciiArt
|
||||
import com.beust.kobalt.KobaltException
|
||||
import com.beust.kobalt.*
|
||||
import com.beust.kobalt.api.Kobalt
|
||||
import com.beust.kobalt.maven.aether.Exceptions
|
||||
import java.lang.Exception
|
||||
|
@ -10,7 +8,7 @@ import java.time.LocalDateTime
|
|||
import java.time.format.DateTimeFormatter
|
||||
|
||||
fun Any.log(level: Int, text: CharSequence, newLine : Boolean = true) {
|
||||
if (level <= KobaltLogger.LOG_LEVEL) {
|
||||
if (level <= KobaltLogger.LOG_LEVEL && !KobaltLogger.isQuiet) {
|
||||
KobaltLogger.logger.log(javaClass.simpleName, text, newLine)
|
||||
}
|
||||
}
|
||||
|
@ -25,11 +23,11 @@ fun Any.kobaltLog(tag: String, text: CharSequence, newLine : Boolean = true) {
|
|||
}
|
||||
|
||||
fun Any.logWrap(level: Int, text1: CharSequence, text2: CharSequence, function: () -> Unit) {
|
||||
if (level <= KobaltLogger.LOG_LEVEL) {
|
||||
if (level <= KobaltLogger.LOG_LEVEL && !KobaltLogger.isQuiet) {
|
||||
KobaltLogger.logger.log(javaClass.simpleName, text1, newLine = false)
|
||||
}
|
||||
function()
|
||||
if (level <= KobaltLogger.LOG_LEVEL) {
|
||||
if (level <= KobaltLogger.LOG_LEVEL && !KobaltLogger.isQuiet) {
|
||||
KobaltLogger.logger.log(javaClass.simpleName, text2, newLine = true)
|
||||
}
|
||||
}
|
||||
|
@ -50,6 +48,8 @@ fun Any.error(text: CharSequence, e: Throwable? = null) {
|
|||
|
||||
object KobaltLogger {
|
||||
var LOG_LEVEL: Int = 1
|
||||
|
||||
val isQuiet: Boolean get() = (LOG_LEVEL == Constants.LOG_QUIET_LEVEL)
|
||||
|
||||
val logger: Logger get() =
|
||||
if (Kobalt.context != null) {
|
||||
|
|
|
@ -12,7 +12,7 @@ data class Node<T>(val value: T) {
|
|||
}
|
||||
|
||||
private fun p(s: String) {
|
||||
println(s)
|
||||
kobaltLog(1, s)
|
||||
}
|
||||
|
||||
fun dump(r: T, children: List<Node<T>>, indent: Int) {
|
||||
|
|
|
@ -36,6 +36,7 @@ public class Main {
|
|||
|
||||
private final Properties wrapperProperties = new Properties();
|
||||
|
||||
private static int logQuietLevel = 0;
|
||||
private static int logLevel = 1;
|
||||
private boolean noOverwrite = false;
|
||||
|
||||
|
@ -487,7 +488,7 @@ public class Main {
|
|||
}
|
||||
|
||||
private static void p(int level, String s, boolean newLine) {
|
||||
if (level <= logLevel) {
|
||||
if (level != logQuietLevel && level <= logLevel) {
|
||||
if (newLine) System.out.println(s);
|
||||
else System.out.print(s);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue