diff --git a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/api/KobaltContext.kt b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/api/KobaltContext.kt index c927517d..f8a111c2 100644 --- a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/api/KobaltContext.kt +++ b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/api/KobaltContext.kt @@ -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 { diff --git a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/archive/Archives.kt b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/archive/Archives.kt index 8549d4ed..c36b061d 100644 --- a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/archive/Archives.kt +++ b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/archive/Archives.kt @@ -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, 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 diff --git a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/internal/ParallelLogger.kt b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/internal/ParallelLogger.kt index 24174391..05038dd1 100644 --- a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/internal/ParallelLogger.kt +++ b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/internal/ParallelLogger.kt @@ -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) } diff --git a/src/main/kotlin/com/beust/kobalt/app/BuildFileCompiler.kt b/src/main/kotlin/com/beust/kobalt/app/BuildFileCompiler.kt index 9229ea87..cda7557d 100644 --- a/src/main/kotlin/com/beust/kobalt/app/BuildFileCompiler.kt +++ b/src/main/kotlin/com/beust/kobalt/app/BuildFileCompiler.kt @@ -10,6 +10,7 @@ import com.beust.kobalt.api.PluginProperties import com.beust.kobalt.api.Project import com.beust.kobalt.internal.IncrementalManager import com.beust.kobalt.internal.KobaltSettings +import com.beust.kobalt.internal.ParallelLogger import com.beust.kobalt.internal.PluginInfo import com.beust.kobalt.internal.build.BuildFile 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 executors: KobaltExecutors, val buildScriptUtil: BuildScriptUtil, val settings: KobaltSettings, 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 { fun create(@Assisted("buildFiles") buildFiles: List, pluginInfo: PluginInfo) : BuildFileCompiler @@ -58,6 +60,7 @@ public class BuildFileCompiler @Inject constructor(@Assisted("buildFiles") val b context.incrementalManager = incrementalManagerFactory.create() context.aether = aether context.pomGeneratorFactory = pomGeneratorFactory + context.logger = parallelLogger Kobalt.context = context //