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

Introducing ILogger.

This commit is contained in:
Cedric Beust 2016-08-08 17:44:19 -07:00
parent fa6820e440
commit 54b68b0105
4 changed files with 16 additions and 9 deletions

View file

@ -4,6 +4,7 @@ import com.beust.kobalt.Args
import com.beust.kobalt.KobaltException
import com.beust.kobalt.Plugins
import com.beust.kobalt.Variant
import com.beust.kobalt.internal.ILogger
import com.beust.kobalt.internal.IncrementalManager
import com.beust.kobalt.internal.KobaltSettings
import com.beust.kobalt.internal.PluginInfo
@ -82,6 +83,7 @@ class KobaltContext(val args: Args) {
lateinit var incrementalManager: IncrementalManager
lateinit var aether: KobaltAether
lateinit var pomGeneratorFactory: PomGenerator.IFactory
lateinit var logger: ILogger
}
class InternalContext {

View file

@ -5,7 +5,6 @@ import com.beust.kobalt.IFileSpec
import com.beust.kobalt.api.KobaltContext
import com.beust.kobalt.api.Project
import com.beust.kobalt.api.annotation.ExportedProjectProperty
import com.beust.kobalt.internal.ParallelLogger
import com.beust.kobalt.misc.*
import java.io.File
import java.io.FileOutputStream
@ -28,8 +27,7 @@ class Archives {
suffix: String,
includedFiles: List<IncludedFile>,
expandJarFiles : Boolean = false,
outputStreamFactory: (OutputStream) -> ZipOutputStream = DEFAULT_STREAM_FACTORY,
kobaltLog: ParallelLogger) : File {
outputStreamFactory: (OutputStream) -> ZipOutputStream = DEFAULT_STREAM_FACTORY) : File {
val fullArchiveName = context.variant.archiveName(project, archiveName, suffix)
val archiveDir = File(KFiles.libsDir(project))
val result = File(archiveDir.path, fullArchiveName)
@ -39,7 +37,7 @@ class Archives {
outputStreamFactory(FileOutputStream(result)).use {
JarUtils.addFiles(project.directory, includedFiles, it, expandJarFiles)
log(2, text = "Added ${includedFiles.size} files to $result")
kobaltLog.log(project.name, 1, " Created $result")
context.logger.log(project.name, 1, " Created $result")
}
} catch (e: Throwable) {
// make sure that incomplete archive is deleted

View file

@ -11,6 +11,10 @@ import java.util.*
import java.util.concurrent.ConcurrentHashMap
import java.util.concurrent.ConcurrentLinkedQueue
interface ILogger {
fun log(tag: String, level: Int, message: String)
}
/**
* This class manages logs for parallel builds. These logs come from multiple projects interwoven as
* they are being scheduled on different threads. This class maintains a "current" project which has
@ -18,10 +22,10 @@ import java.util.concurrent.ConcurrentLinkedQueue
* Once the current project is done, this class will catch up all the finished project logs and then
* pick the next current project to be displayed live.
*
* Yes, this code was pretty painful to write and I'm pretty sure it still have a few bugs left.
* Yes, this code was pretty painful to write and I'm pretty sure it can be made less ugly.
*/
@Singleton
class ParallelLogger @Inject constructor(val args: Args) {
class ParallelLogger @Inject constructor(val args: Args) : ILogger {
enum class Type { LOG, WARN, ERROR }
class LogLine(val name: String? = null, val level: Int, val message: String, val type: Type)
@ -108,9 +112,9 @@ class ParallelLogger @Inject constructor(val args: Args) {
}
}
fun log(name: String, level: Int, message: String) {
override fun log(tag: String, level: Int, message: String) {
if (args.parallel) {
addLogLine(name, LogLine(name, level, message, Type.LOG))
addLogLine(tag, LogLine(tag, level, message, Type.LOG))
} else {
kobaltLog(level, message)
}