mirror of
https://github.com/ethauvin/kobalt.git
synced 2025-04-26 08:27:12 -07:00
Introducing ILogger.
This commit is contained in:
parent
fa6820e440
commit
54b68b0105
4 changed files with 16 additions and 9 deletions
|
@ -4,6 +4,7 @@ import com.beust.kobalt.Args
|
||||||
import com.beust.kobalt.KobaltException
|
import com.beust.kobalt.KobaltException
|
||||||
import com.beust.kobalt.Plugins
|
import com.beust.kobalt.Plugins
|
||||||
import com.beust.kobalt.Variant
|
import com.beust.kobalt.Variant
|
||||||
|
import com.beust.kobalt.internal.ILogger
|
||||||
import com.beust.kobalt.internal.IncrementalManager
|
import com.beust.kobalt.internal.IncrementalManager
|
||||||
import com.beust.kobalt.internal.KobaltSettings
|
import com.beust.kobalt.internal.KobaltSettings
|
||||||
import com.beust.kobalt.internal.PluginInfo
|
import com.beust.kobalt.internal.PluginInfo
|
||||||
|
@ -82,6 +83,7 @@ class KobaltContext(val args: Args) {
|
||||||
lateinit var incrementalManager: IncrementalManager
|
lateinit var incrementalManager: IncrementalManager
|
||||||
lateinit var aether: KobaltAether
|
lateinit var aether: KobaltAether
|
||||||
lateinit var pomGeneratorFactory: PomGenerator.IFactory
|
lateinit var pomGeneratorFactory: PomGenerator.IFactory
|
||||||
|
lateinit var logger: ILogger
|
||||||
}
|
}
|
||||||
|
|
||||||
class InternalContext {
|
class InternalContext {
|
||||||
|
|
|
@ -5,7 +5,6 @@ import com.beust.kobalt.IFileSpec
|
||||||
import com.beust.kobalt.api.KobaltContext
|
import com.beust.kobalt.api.KobaltContext
|
||||||
import com.beust.kobalt.api.Project
|
import com.beust.kobalt.api.Project
|
||||||
import com.beust.kobalt.api.annotation.ExportedProjectProperty
|
import com.beust.kobalt.api.annotation.ExportedProjectProperty
|
||||||
import com.beust.kobalt.internal.ParallelLogger
|
|
||||||
import com.beust.kobalt.misc.*
|
import com.beust.kobalt.misc.*
|
||||||
import java.io.File
|
import java.io.File
|
||||||
import java.io.FileOutputStream
|
import java.io.FileOutputStream
|
||||||
|
@ -28,8 +27,7 @@ class Archives {
|
||||||
suffix: String,
|
suffix: String,
|
||||||
includedFiles: List<IncludedFile>,
|
includedFiles: List<IncludedFile>,
|
||||||
expandJarFiles : Boolean = false,
|
expandJarFiles : Boolean = false,
|
||||||
outputStreamFactory: (OutputStream) -> ZipOutputStream = DEFAULT_STREAM_FACTORY,
|
outputStreamFactory: (OutputStream) -> ZipOutputStream = DEFAULT_STREAM_FACTORY) : File {
|
||||||
kobaltLog: ParallelLogger) : File {
|
|
||||||
val fullArchiveName = context.variant.archiveName(project, archiveName, suffix)
|
val fullArchiveName = context.variant.archiveName(project, archiveName, suffix)
|
||||||
val archiveDir = File(KFiles.libsDir(project))
|
val archiveDir = File(KFiles.libsDir(project))
|
||||||
val result = File(archiveDir.path, fullArchiveName)
|
val result = File(archiveDir.path, fullArchiveName)
|
||||||
|
@ -39,7 +37,7 @@ class Archives {
|
||||||
outputStreamFactory(FileOutputStream(result)).use {
|
outputStreamFactory(FileOutputStream(result)).use {
|
||||||
JarUtils.addFiles(project.directory, includedFiles, it, expandJarFiles)
|
JarUtils.addFiles(project.directory, includedFiles, it, expandJarFiles)
|
||||||
log(2, text = "Added ${includedFiles.size} files to $result")
|
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) {
|
} catch (e: Throwable) {
|
||||||
// make sure that incomplete archive is deleted
|
// make sure that incomplete archive is deleted
|
||||||
|
|
|
@ -11,6 +11,10 @@ import java.util.*
|
||||||
import java.util.concurrent.ConcurrentHashMap
|
import java.util.concurrent.ConcurrentHashMap
|
||||||
import java.util.concurrent.ConcurrentLinkedQueue
|
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
|
* 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
|
* 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
|
* 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.
|
* 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
|
@Singleton
|
||||||
class ParallelLogger @Inject constructor(val args: Args) {
|
class ParallelLogger @Inject constructor(val args: Args) : ILogger {
|
||||||
enum class Type { LOG, WARN, ERROR }
|
enum class Type { LOG, WARN, ERROR }
|
||||||
|
|
||||||
class LogLine(val name: String? = null, val level: Int, val message: String, val type: Type)
|
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) {
|
if (args.parallel) {
|
||||||
addLogLine(name, LogLine(name, level, message, Type.LOG))
|
addLogLine(tag, LogLine(tag, level, message, Type.LOG))
|
||||||
} else {
|
} else {
|
||||||
kobaltLog(level, message)
|
kobaltLog(level, message)
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,6 +10,7 @@ import com.beust.kobalt.api.PluginProperties
|
||||||
import com.beust.kobalt.api.Project
|
import com.beust.kobalt.api.Project
|
||||||
import com.beust.kobalt.internal.IncrementalManager
|
import com.beust.kobalt.internal.IncrementalManager
|
||||||
import com.beust.kobalt.internal.KobaltSettings
|
import com.beust.kobalt.internal.KobaltSettings
|
||||||
|
import com.beust.kobalt.internal.ParallelLogger
|
||||||
import com.beust.kobalt.internal.PluginInfo
|
import com.beust.kobalt.internal.PluginInfo
|
||||||
import com.beust.kobalt.internal.build.BuildFile
|
import com.beust.kobalt.internal.build.BuildFile
|
||||||
import com.beust.kobalt.internal.build.VersionFile
|
import com.beust.kobalt.internal.build.VersionFile
|
||||||
|
@ -36,7 +37,8 @@ public class BuildFileCompiler @Inject constructor(@Assisted("buildFiles") val b
|
||||||
val dependencyManager: DependencyManager, val pluginProperties: PluginProperties,
|
val dependencyManager: DependencyManager, val pluginProperties: PluginProperties,
|
||||||
val executors: KobaltExecutors, val buildScriptUtil: BuildScriptUtil, val settings: KobaltSettings,
|
val executors: KobaltExecutors, val buildScriptUtil: BuildScriptUtil, val settings: KobaltSettings,
|
||||||
val incrementalManagerFactory: IncrementalManager.IFactory, val args: Args,
|
val incrementalManagerFactory: IncrementalManager.IFactory, val args: Args,
|
||||||
val aether: KobaltAether, val pomGeneratorFactory: PomGenerator.IFactory) {
|
val aether: KobaltAether, val pomGeneratorFactory: PomGenerator.IFactory,
|
||||||
|
val parallelLogger: ParallelLogger) {
|
||||||
|
|
||||||
interface IFactory {
|
interface IFactory {
|
||||||
fun create(@Assisted("buildFiles") buildFiles: List<BuildFile>, pluginInfo: PluginInfo) : BuildFileCompiler
|
fun create(@Assisted("buildFiles") buildFiles: List<BuildFile>, pluginInfo: PluginInfo) : BuildFileCompiler
|
||||||
|
@ -58,6 +60,7 @@ public class BuildFileCompiler @Inject constructor(@Assisted("buildFiles") val b
|
||||||
context.incrementalManager = incrementalManagerFactory.create()
|
context.incrementalManager = incrementalManagerFactory.create()
|
||||||
context.aether = aether
|
context.aether = aether
|
||||||
context.pomGeneratorFactory = pomGeneratorFactory
|
context.pomGeneratorFactory = pomGeneratorFactory
|
||||||
|
context.logger = parallelLogger
|
||||||
Kobalt.context = context
|
Kobalt.context = context
|
||||||
|
|
||||||
//
|
//
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue