mirror of
https://github.com/ethauvin/kobalt.git
synced 2025-04-26 08:27:12 -07:00
Logging clean up.
This commit is contained in:
parent
8a672ad764
commit
8805e1c130
62 changed files with 336 additions and 320 deletions
|
@ -19,7 +19,7 @@ import com.beust.kobalt.maven.PomGenerator
|
|||
import com.beust.kobalt.maven.aether.KobaltAether
|
||||
import com.beust.kobalt.misc.KFiles
|
||||
import com.beust.kobalt.misc.KobaltExecutors
|
||||
import com.beust.kobalt.misc.log
|
||||
import com.beust.kobalt.misc.kobaltLog
|
||||
import com.beust.kobalt.plugin.kotlin.kotlinCompilePrivate
|
||||
import com.google.inject.assistedinject.Assisted
|
||||
import java.io.File
|
||||
|
@ -94,7 +94,7 @@ public class BuildFileCompiler @Inject constructor(@Assisted("buildFiles") val b
|
|||
// changed in-between
|
||||
buildScriptJarFile.parentFile.let { dir ->
|
||||
if (! VersionFile.isSameVersionFile(dir)) {
|
||||
log(1, "Detected new installation, wiping $dir")
|
||||
kobaltLog(1, "Detected new installation, wiping $dir")
|
||||
dir.listFiles().map { it.delete() }
|
||||
}
|
||||
}
|
||||
|
@ -125,7 +125,7 @@ public class BuildFileCompiler @Inject constructor(@Assisted("buildFiles") val b
|
|||
|
||||
private fun maybeCompileBuildFile(context: KobaltContext, buildFile: BuildFile, buildScriptJarFile: File,
|
||||
pluginUrls: List<URL>) : TaskResult {
|
||||
log(2, "Running build file ${buildFile.name} jar: $buildScriptJarFile")
|
||||
kobaltLog(2, "Running build file ${buildFile.name} jar: $buildScriptJarFile")
|
||||
|
||||
// If the user specifed --profiles, always recompile the build file since we don't know if
|
||||
// the current buildScript.jar we have contains the correct value for these profiles
|
||||
|
@ -136,10 +136,10 @@ public class BuildFileCompiler @Inject constructor(@Assisted("buildFiles") val b
|
|||
val bs = BuildScriptJarFile(buildScriptJarFile)
|
||||
val same = bs.sameProfiles(args.profiles)
|
||||
if (same && buildScriptUtil.isUpToDate(buildFile, buildScriptJarFile)) {
|
||||
log(2, " Build file is up to date")
|
||||
kobaltLog(2, " Build file is up to date")
|
||||
return TaskResult()
|
||||
} else {
|
||||
log(2, " Need to recompile ${buildFile.name}")
|
||||
kobaltLog(2, " Need to recompile ${buildFile.name}")
|
||||
|
||||
buildScriptJarFile.delete()
|
||||
val buildFileClasspath = Kobalt.buildFileClasspath.map { it.jarFile.get() }.map { it.absolutePath }
|
||||
|
|
|
@ -12,7 +12,7 @@ import com.beust.kobalt.internal.TaskManager
|
|||
import com.beust.kobalt.internal.build.BuildFile
|
||||
import com.beust.kobalt.misc.KFiles
|
||||
import com.beust.kobalt.misc.Topological
|
||||
import com.beust.kobalt.misc.log
|
||||
import com.beust.kobalt.misc.kobaltLog
|
||||
import com.beust.kobalt.plugin.KobaltPlugin
|
||||
import com.google.inject.Inject
|
||||
import java.io.File
|
||||
|
@ -83,7 +83,7 @@ class BuildScriptUtil @Inject constructor(val plugins: Plugins, val files: KFile
|
|||
try {
|
||||
val r = method.invoke(null)
|
||||
if (r is Project) {
|
||||
log(2, "Found project ${r.name} in class $cls")
|
||||
kobaltLog(2, "Found project ${r.name} in class $cls")
|
||||
projects.add(r)
|
||||
}
|
||||
} catch(ex: Throwable) {
|
||||
|
|
|
@ -5,6 +5,7 @@ import com.beust.kobalt.api.ITemplate
|
|||
import com.beust.kobalt.api.ITemplateContributor
|
||||
import com.beust.kobalt.maven.Pom
|
||||
import com.beust.kobalt.misc.KFiles
|
||||
import com.beust.kobalt.misc.kobaltLog
|
||||
import com.beust.kobalt.misc.log
|
||||
import com.beust.kobalt.plugin.KobaltPlugin
|
||||
import com.github.mustachejava.DefaultMustacheFactory
|
||||
|
@ -35,7 +36,7 @@ abstract class LanguageTemplateGenerator : ITemplate {
|
|||
.getResource(ITemplateContributor.DIRECTORY_NAME + "/$templateName/$mustache").openStream()
|
||||
val createdFile = File(KFiles.joinDir(it.dir, it.fileName))
|
||||
Mustache.generateFile(fileInputStream, File(KFiles.joinDir(it.dir, it.fileName)), map)
|
||||
log(2, "Created $createdFile")
|
||||
kobaltLog(2, "Created $createdFile")
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -78,7 +79,7 @@ abstract class LanguageTemplateGenerator : ITemplate {
|
|||
it.print(buildFileContent)
|
||||
}
|
||||
} else {
|
||||
log(1, "Build file already exists, not overwriting it")
|
||||
kobaltLog(1, "Build file already exists, not overwriting it")
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -10,7 +10,7 @@ import com.beust.kobalt.internal.build.VersionFile
|
|||
import com.beust.kobalt.maven.DependencyManager
|
||||
import com.beust.kobalt.misc.KFiles
|
||||
import com.beust.kobalt.misc.countChar
|
||||
import com.beust.kobalt.misc.log
|
||||
import com.beust.kobalt.misc.kobaltLog
|
||||
import com.beust.kobalt.plugin.kotlin.kotlinCompilePrivate
|
||||
import java.io.File
|
||||
import java.net.URL
|
||||
|
@ -85,7 +85,7 @@ class ParsedBuildFile(val buildFile: BuildFile, val context: KobaltContext, val
|
|||
(context.profiles as List<String>).forEach {
|
||||
if (line.matches(Regex("[ \\t]*val[ \\t]+$it[ \\t]*=.*"))) {
|
||||
with("val $it = true") {
|
||||
log(2, "Activating profile $it in build file")
|
||||
kobaltLog(2, "Activating profile $it in build file")
|
||||
activeProfiles.add(it)
|
||||
profileLines.add(this)
|
||||
return this
|
||||
|
@ -110,7 +110,7 @@ class ParsedBuildFile(val buildFile: BuildFile, val context: KobaltContext, val
|
|||
//
|
||||
val pluginSourceFile = KFiles.createTempFile(".kt", deleteOnExit = true)
|
||||
pluginSourceFile.writeText(preBuildScriptCode, Charset.defaultCharset())
|
||||
log(2, "Saved ${pluginSourceFile.absolutePath}")
|
||||
kobaltLog(2, "Saved ${pluginSourceFile.absolutePath}")
|
||||
|
||||
//
|
||||
// Compile to preBuildScript.jar
|
||||
|
|
|
@ -8,7 +8,7 @@ import com.beust.kobalt.api.Kobalt
|
|||
import com.beust.kobalt.api.Project
|
||||
import com.beust.kobalt.internal.PluginInfo
|
||||
import com.beust.kobalt.internal.build.BuildFile
|
||||
import com.beust.kobalt.misc.log
|
||||
import com.beust.kobalt.misc.kobaltLog
|
||||
import com.google.inject.Inject
|
||||
import java.util.*
|
||||
|
||||
|
@ -41,7 +41,7 @@ class ProjectFinder @Inject constructor(val buildFileCompilerFactory: BuildFileC
|
|||
//
|
||||
runClasspathInterceptors(allProjects)
|
||||
|
||||
log(2, "Final list of repos:\n " + Kobalt.repos.joinToString("\n "))
|
||||
kobaltLog(2, "Final list of repos:\n " + Kobalt.repos.joinToString("\n "))
|
||||
|
||||
//
|
||||
// Call apply() on all plug-ins now that the repos are set up
|
||||
|
|
|
@ -3,7 +3,7 @@ package com.beust.kobalt.app
|
|||
import com.beust.kobalt.Args
|
||||
import com.beust.kobalt.api.ITemplate
|
||||
import com.beust.kobalt.internal.PluginInfo
|
||||
import com.beust.kobalt.misc.log
|
||||
import com.beust.kobalt.misc.kobaltLog
|
||||
import com.beust.kobalt.misc.warn
|
||||
import com.google.inject.Inject
|
||||
import java.io.File
|
||||
|
@ -24,10 +24,10 @@ class ProjectGenerator @Inject constructor(val pluginInfo: PluginInfo){
|
|||
args.templates?.split(',')?.forEach { templateName ->
|
||||
val template = map[templateName]
|
||||
if (template != null) {
|
||||
log(2, "Running template $templateName")
|
||||
kobaltLog(2, "Running template $templateName")
|
||||
template.generateTemplate(args, classLoader)
|
||||
log(1, "\n\nTemplate \"$templateName\" installed")
|
||||
log(1, template.instructions)
|
||||
kobaltLog(1, "\n\nTemplate \"$templateName\" installed")
|
||||
kobaltLog(1, template.instructions)
|
||||
} else {
|
||||
warn("Couldn't find any template named $templateName")
|
||||
}
|
||||
|
|
|
@ -5,7 +5,7 @@ import com.beust.kobalt.api.ITemplateContributor
|
|||
import com.beust.kobalt.app.java.JavaTemplateGenerator
|
||||
import com.beust.kobalt.app.kotlin.KotlinTemplateGenerator
|
||||
import com.beust.kobalt.internal.PluginInfo
|
||||
import com.beust.kobalt.misc.log
|
||||
import com.beust.kobalt.misc.kobaltLog
|
||||
import com.google.common.collect.ArrayListMultimap
|
||||
import com.google.common.collect.ListMultimap
|
||||
|
||||
|
@ -25,9 +25,9 @@ class Templates : ITemplateContributor {
|
|||
fun displayTemplates(pluginInfo : PluginInfo) {
|
||||
val templates = getTemplates(pluginInfo)
|
||||
templates.keySet().forEach {
|
||||
log(1, " Plug-in: $it")
|
||||
kobaltLog(1, " Plug-in: $it")
|
||||
templates[it].forEach {
|
||||
log(1, " \"" + it.templateName + "\"\t\t" + it.templateDescription)
|
||||
kobaltLog(1, " \"" + it.templateName + "\"\t\t" + it.templateDescription)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -44,18 +44,18 @@ class UpdateKobalt @Inject constructor(val github: GithubApi2, val wrapperProper
|
|||
val distFile = File(KFiles.distributionsDir)
|
||||
if (latestVersion > current) {
|
||||
if (distFile.exists()) {
|
||||
log(1, "**** Version $latestVersionString is installed, you can switch to it with " +
|
||||
kobaltLog(1, "**** Version $latestVersionString is installed, you can switch to it with " +
|
||||
"./kobaltw --update")
|
||||
} else {
|
||||
listOf("", "New Kobalt version available: $latestVersionString",
|
||||
"To update, run ./kobaltw --update", "").forEach {
|
||||
log(1, "**** $it")
|
||||
kobaltLog(1, "**** $it")
|
||||
}
|
||||
}
|
||||
}
|
||||
VersionCheckTimestampFile.updateTimestamp(Instant.now())
|
||||
} catch(ex: TimeoutException) {
|
||||
log(2, "Didn't get the new version in time, skipping it")
|
||||
kobaltLog(2, "Didn't get the new version in time, skipping it")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -8,7 +8,7 @@ import com.beust.kobalt.app.MainModule
|
|||
import com.beust.kobalt.homeDir
|
||||
import com.beust.kobalt.internal.KobaltSettings
|
||||
import com.beust.kobalt.misc.KFiles
|
||||
import com.beust.kobalt.misc.log
|
||||
import com.beust.kobalt.misc.kobaltLog
|
||||
import com.beust.kobalt.misc.warn
|
||||
import com.google.gson.Gson
|
||||
import com.google.gson.JsonObject
|
||||
|
@ -168,7 +168,7 @@ class ServerProcess @Inject constructor(val serverFactory: KobaltServer.IFactory
|
|||
}
|
||||
}
|
||||
} catch(ex: IOException) {
|
||||
log(1, "Couldn't connect to current server, launching a new one")
|
||||
kobaltLog(1, "Couldn't connect to current server, launching a new one")
|
||||
Thread.sleep(1000)
|
||||
}
|
||||
}
|
||||
|
@ -179,7 +179,7 @@ class ServerProcess @Inject constructor(val serverFactory: KobaltServer.IFactory
|
|||
|
||||
private fun launchServer(port: Int) {
|
||||
val kobaltJar = File(KFiles().kobaltJar[0])
|
||||
log(1, "Kobalt jar: $kobaltJar")
|
||||
kobaltLog(1, "Kobalt jar: $kobaltJar")
|
||||
if (! kobaltJar.exists()) {
|
||||
warn("Can't find the jar file " + kobaltJar.absolutePath + " can't be found")
|
||||
} else {
|
||||
|
@ -198,28 +198,28 @@ class ServerProcess @Inject constructor(val serverFactory: KobaltServer.IFactory
|
|||
val process = pb.start()
|
||||
val errorCode = process.waitFor()
|
||||
if (errorCode == 0) {
|
||||
log(1, "Server exiting")
|
||||
kobaltLog(1, "Server exiting")
|
||||
} else {
|
||||
log(1, "Server exiting with error")
|
||||
kobaltLog(1, "Server exiting with error")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun createServerFile(port: Int, force: Boolean) : Boolean {
|
||||
if (File(SERVER_FILE).exists() && ! force) {
|
||||
log(1, "Server file $SERVER_FILE already exists, is another server running?")
|
||||
kobaltLog(1, "Server file $SERVER_FILE already exists, is another server running?")
|
||||
return false
|
||||
} else {
|
||||
Properties().apply {
|
||||
put(KEY_PORT, port.toString())
|
||||
}.store(FileWriter(SERVER_FILE), "")
|
||||
log(2, "KobaltServer created $SERVER_FILE")
|
||||
kobaltLog(2, "KobaltServer created $SERVER_FILE")
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
private fun deleteServerFile() {
|
||||
log(1, "KobaltServer deleting $SERVER_FILE")
|
||||
kobaltLog(1, "KobaltServer deleting $SERVER_FILE")
|
||||
File(SERVER_FILE).delete()
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,7 +4,7 @@ import com.beust.kobalt.api.Project
|
|||
import com.beust.kobalt.homeDir
|
||||
import com.beust.kobalt.internal.PluginInfo
|
||||
import com.beust.kobalt.misc.KFiles
|
||||
import com.beust.kobalt.misc.log
|
||||
import com.beust.kobalt.misc.kobaltLog
|
||||
import com.google.inject.Inject
|
||||
import com.google.inject.assistedinject.Assisted
|
||||
import java.io.File
|
||||
|
@ -49,7 +49,7 @@ class KobaltServer @Inject constructor(@Assisted val force: Boolean, @Assisted @
|
|||
val port = givenPort ?: ProcessUtil.findAvailablePort(1234)
|
||||
try {
|
||||
if (createServerFile(port, force)) {
|
||||
log(1, "KobaltServer listening on port $port")
|
||||
kobaltLog(1, "KobaltServer listening on port $port")
|
||||
// OldServer(initCallback, cleanUpCallback).run(port)
|
||||
// JerseyServer(initCallback, cleanUpCallback).run(port)
|
||||
SparkServer(initCallback, cleanUpCallback, pluginInfo).run(port)
|
||||
|
@ -69,7 +69,7 @@ class KobaltServer @Inject constructor(@Assisted val force: Boolean, @Assisted @
|
|||
|
||||
private fun createServerFile(port: Int, force: Boolean) : Boolean {
|
||||
if (File(SERVER_FILE).exists() && ! force) {
|
||||
log(1, "Server file $SERVER_FILE already exists, is another server running?")
|
||||
kobaltLog(1, "Server file $SERVER_FILE already exists, is another server running?")
|
||||
return false
|
||||
} else {
|
||||
val processName = ManagementFactory.getRuntimeMXBean().name
|
||||
|
@ -78,13 +78,13 @@ class KobaltServer @Inject constructor(@Assisted val force: Boolean, @Assisted @
|
|||
put(KEY_PORT, port.toString())
|
||||
put(KEY_PID, pid)
|
||||
}.store(FileWriter(SERVER_FILE), "")
|
||||
log(2, "KobaltServer created $SERVER_FILE")
|
||||
kobaltLog(2, "KobaltServer created $SERVER_FILE")
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
private fun deleteServerFile() {
|
||||
log(1, "KobaltServer deleting $SERVER_FILE")
|
||||
kobaltLog(1, "KobaltServer deleting $SERVER_FILE")
|
||||
File(SERVER_FILE).delete()
|
||||
}
|
||||
}
|
||||
|
|
|
@ -5,7 +5,7 @@ import com.beust.kobalt.api.Project
|
|||
import com.beust.kobalt.internal.remote.CommandData
|
||||
import com.beust.kobalt.internal.remote.ICommandSender
|
||||
import com.beust.kobalt.internal.remote.PingCommand
|
||||
import com.beust.kobalt.misc.log
|
||||
import com.beust.kobalt.misc.kobaltLog
|
||||
import com.google.gson.Gson
|
||||
import com.google.gson.JsonObject
|
||||
import com.google.gson.JsonParser
|
||||
|
@ -21,12 +21,12 @@ class OldServer(val initCallback: (String) -> List<Project>, val cleanUpCallback
|
|||
val pending = arrayListOf<CommandData>()
|
||||
|
||||
override fun run(port: Int) {
|
||||
log(1, "Listening to port $port")
|
||||
kobaltLog(1, "Listening to port $port")
|
||||
var quit = false
|
||||
serverInfo = ServerInfo(port)
|
||||
while (!quit) {
|
||||
if (pending.size > 0) {
|
||||
log(1, "Emptying the queue, size $pending.size()")
|
||||
kobaltLog(1, "Emptying the queue, size $pending.size()")
|
||||
synchronized(pending) {
|
||||
pending.forEach { sendData(it) }
|
||||
pending.clear()
|
||||
|
@ -36,11 +36,11 @@ class OldServer(val initCallback: (String) -> List<Project>, val cleanUpCallback
|
|||
try {
|
||||
var line = serverInfo.reader.readLine()
|
||||
while (!quit && line != null) {
|
||||
log(1, "Received from client $line")
|
||||
kobaltLog(1, "Received from client $line")
|
||||
val jo = JsonParser().parse(line) as JsonObject
|
||||
commandName = jo.get("name").asString
|
||||
if ("quit" == commandName) {
|
||||
log(1, "Quitting")
|
||||
kobaltLog(1, "Quitting")
|
||||
quit = true
|
||||
} else {
|
||||
runCommand(jo, initCallback)
|
||||
|
@ -54,18 +54,18 @@ class OldServer(val initCallback: (String) -> List<Project>, val cleanUpCallback
|
|||
}
|
||||
}
|
||||
if (line == null) {
|
||||
log(1, "Received null line, resetting the server")
|
||||
kobaltLog(1, "Received null line, resetting the server")
|
||||
serverInfo.reset()
|
||||
}
|
||||
} catch(ex: SocketException) {
|
||||
log(1, "Client disconnected, resetting")
|
||||
kobaltLog(1, "Client disconnected, resetting")
|
||||
serverInfo.reset()
|
||||
} catch(ex: Throwable) {
|
||||
ex.printStackTrace()
|
||||
if (commandName != null) {
|
||||
sendData(CommandData(commandName, null, ex.message))
|
||||
}
|
||||
log(1, "Command failed: ${ex.message}")
|
||||
kobaltLog(1, "Command failed: ${ex.message}")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -111,7 +111,7 @@ class OldServer(val initCallback: (String) -> List<Project>, val cleanUpCallback
|
|||
if (serverInfo.writer != null) {
|
||||
serverInfo.writer!!.println(content)
|
||||
} else {
|
||||
log(1, "Queuing $content")
|
||||
kobaltLog(1, "Queuing $content")
|
||||
synchronized(pending) {
|
||||
pending.add(commandData)
|
||||
}
|
||||
|
|
|
@ -11,7 +11,6 @@ import com.beust.kobalt.maven.aether.Scope
|
|||
import com.beust.kobalt.misc.KFiles
|
||||
import com.beust.kobalt.misc.KobaltExecutors
|
||||
import com.beust.kobalt.misc.RunCommand
|
||||
import com.beust.kobalt.misc.log
|
||||
import com.beust.kobalt.plugin.packaging.PackageConfig
|
||||
import com.beust.kobalt.plugin.packaging.PackagingPlugin
|
||||
import com.google.inject.Inject
|
||||
|
@ -59,7 +58,9 @@ class ApplicationPlugin @Inject constructor(val configActor: ConfigActor<Applica
|
|||
if (runContributor != null && runContributor.affinity(project, context) > 0) {
|
||||
return runContributor.run(project, context, dependencyManager.dependencies(project, context))
|
||||
} else {
|
||||
log(2, "Couldn't find a runner for project ${project.name}. Please make sure your build file contains " +
|
||||
context.logger.log(project.name, 2,
|
||||
"Couldn't find a runner for project ${project.name}. Please make sure" +
|
||||
" your build file contains " +
|
||||
"an application{} directive with a mainClass=... in it")
|
||||
return TaskResult()
|
||||
}
|
||||
|
|
|
@ -5,7 +5,7 @@ import com.beust.kobalt.api.KobaltContext
|
|||
import com.beust.kobalt.api.Project
|
||||
import com.beust.kobalt.misc.JarUtils
|
||||
import com.beust.kobalt.misc.KFiles
|
||||
import com.beust.kobalt.misc.log
|
||||
import com.beust.kobalt.misc.kobaltLog
|
||||
import com.google.inject.Inject
|
||||
import java.io.File
|
||||
|
||||
|
@ -26,11 +26,11 @@ class NativeManager @Inject constructor() : IJvmFlagContributor {
|
|||
if (! buildDir.exists()) {
|
||||
buildDir.mkdirs()
|
||||
project.nativeDependencies.forEach { dep ->
|
||||
log(2, "Extracting $dep " + dep.jarFile.get() + " in $buildDir")
|
||||
kobaltLog(2, "Extracting $dep " + dep.jarFile.get() + " in $buildDir")
|
||||
JarUtils.extractJarFile(dep.jarFile.get(), buildDir)
|
||||
}
|
||||
} else {
|
||||
log(2, "Native directory $buildDir already exists, not extracting the native jar files")
|
||||
kobaltLog(2, "Native directory $buildDir already exists, not extracting the native jar files")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,7 +6,6 @@ import com.beust.kobalt.internal.ActorUtils
|
|||
import com.beust.kobalt.internal.CompilerUtils
|
||||
import com.beust.kobalt.maven.DependencyManager
|
||||
import com.beust.kobalt.misc.KFiles
|
||||
import com.beust.kobalt.misc.log
|
||||
import com.google.common.collect.ArrayListMultimap
|
||||
import com.google.inject.Inject
|
||||
import java.io.File
|
||||
|
@ -124,7 +123,7 @@ class AptPlugin @Inject constructor(val dependencyManager: DependencyManager, va
|
|||
addFlags(config.outputDir)
|
||||
}
|
||||
|
||||
log(2, "New flags from apt: " + result.joinToString(" "))
|
||||
context.logger.log(project.name, 2, "New flags from apt: " + result.joinToString(" "))
|
||||
return result
|
||||
}
|
||||
|
||||
|
|
|
@ -12,7 +12,6 @@ import com.beust.kobalt.internal.JvmCompiler
|
|||
import com.beust.kobalt.internal.ParallelLogger
|
||||
import com.beust.kobalt.misc.KFiles
|
||||
import com.beust.kobalt.misc.Strings
|
||||
import com.beust.kobalt.misc.log
|
||||
import com.beust.kobalt.misc.warn
|
||||
import com.google.inject.Inject
|
||||
import com.google.inject.Singleton
|
||||
|
@ -23,8 +22,7 @@ import javax.tools.JavaFileObject
|
|||
import javax.tools.ToolProvider
|
||||
|
||||
@Singleton
|
||||
class JavaCompiler @Inject constructor(val jvmCompiler: JvmCompiler,
|
||||
val kobaltLog: ParallelLogger) : ICompiler {
|
||||
class JavaCompiler @Inject constructor(val jvmCompiler: JvmCompiler, val kobaltLog: ParallelLogger) : ICompiler {
|
||||
fun compilerAction(executable: File) = object : ICompilerAction {
|
||||
override fun compile(projectName: String?, info: CompilerActionInfo): TaskResult {
|
||||
if (info.sourceFiles.isEmpty()) {
|
||||
|
@ -35,9 +33,10 @@ class JavaCompiler @Inject constructor(val jvmCompiler: JvmCompiler,
|
|||
var command: String
|
||||
var errorMessage: String
|
||||
val compiler = ToolProvider.getSystemJavaCompiler()
|
||||
fun logk(level: Int, message: CharSequence) = kobaltLog.log(projectName ?: "", level, message)
|
||||
val result =
|
||||
if (compiler != null) {
|
||||
log(2, "Found system Java compiler, using the compiler API")
|
||||
logk(2, "Found system Java compiler, using the compiler API")
|
||||
val allArgs = arrayListOf(
|
||||
"-d", KFiles.makeDir(info.directory!!, info.outputDir.path).path)
|
||||
if (info.dependencies.size > 0) {
|
||||
|
@ -56,7 +55,7 @@ class JavaCompiler @Inject constructor(val jvmCompiler: JvmCompiler,
|
|||
val task = compiler.getTask(writer, fileManager, dc, allArgs, classes, fileObjects)
|
||||
|
||||
command = "javac " + allArgs.joinToString(" ") + " " + info.sourceFiles.joinToString(" ")
|
||||
log(2, "Launching\n$command")
|
||||
logk(2, "Launching\n$command")
|
||||
|
||||
kobaltLog.log(projectName!!, 1,
|
||||
" Java compiling " + Strings.pluralizeAll(info.sourceFiles.size, "file"))
|
||||
|
@ -64,7 +63,7 @@ class JavaCompiler @Inject constructor(val jvmCompiler: JvmCompiler,
|
|||
errorMessage = dc.diagnostics.joinToString("\n")
|
||||
result
|
||||
} else {
|
||||
log(2, "Didn't find system Java compiler, forking javac")
|
||||
logk(2, "Didn't find system Java compiler, forking javac")
|
||||
val allArgs = arrayListOf(
|
||||
executable.absolutePath,
|
||||
"-d", KFiles.makeDir(info.directory!!, info.outputDir.path).path)
|
||||
|
@ -80,8 +79,8 @@ class JavaCompiler @Inject constructor(val jvmCompiler: JvmCompiler,
|
|||
val pb = ProcessBuilder(allArgs)
|
||||
pb.inheritIO()
|
||||
val line = allArgs.joinToString(" ")
|
||||
log(1, " Java compiling " + Strings.pluralizeAll(info.sourceFiles.size, "file"))
|
||||
log(2, " Java compiling $line")
|
||||
logk(1, " Java compiling " + Strings.pluralizeAll(info.sourceFiles.size, "file"))
|
||||
logk(2, " Java compiling $line")
|
||||
|
||||
command = allArgs.joinToString(" ") + " " + info.sourceFiles.joinToString(" ")
|
||||
val process = pb.start()
|
||||
|
@ -94,7 +93,7 @@ class JavaCompiler @Inject constructor(val jvmCompiler: JvmCompiler,
|
|||
TaskResult(true, "Compilation succeeded")
|
||||
} else {
|
||||
val message = "Compilation errors, command:\n$command" + errorMessage
|
||||
log(1, message)
|
||||
logk(1, message)
|
||||
TaskResult(false, message)
|
||||
}
|
||||
|
||||
|
|
|
@ -4,7 +4,6 @@ import com.beust.kobalt.KobaltException
|
|||
import com.beust.kobalt.TaskResult
|
||||
import com.beust.kobalt.api.*
|
||||
import com.beust.kobalt.internal.*
|
||||
import com.beust.kobalt.kotlin.ParentLastClassLoader
|
||||
import com.beust.kobalt.maven.DependencyManager
|
||||
import com.beust.kobalt.maven.dependency.FileDependency
|
||||
import com.beust.kobalt.misc.*
|
||||
|
@ -15,10 +14,7 @@ import org.jetbrains.kotlin.cli.common.messages.CompilerMessageSeverity
|
|||
import org.jetbrains.kotlin.cli.common.messages.MessageCollector
|
||||
import org.jetbrains.kotlin.cli.jvm.K2JVMCompiler
|
||||
import org.jetbrains.kotlin.config.Services
|
||||
import java.io.ByteArrayOutputStream
|
||||
import java.io.File
|
||||
import java.io.PrintStream
|
||||
import java.nio.charset.Charset
|
||||
import java.util.*
|
||||
import javax.inject.Inject
|
||||
import javax.inject.Singleton
|
||||
|
@ -87,7 +83,10 @@ class KotlinCompiler @Inject constructor(
|
|||
freeArgs = sourceFiles
|
||||
friendPaths = friends
|
||||
}
|
||||
log(2, "Invoking K2JVMCompiler with arguments:"
|
||||
|
||||
fun logk(level: Int, message: CharSequence) = kobaltLog.log(projectName ?: "", level, message)
|
||||
|
||||
logk(2, "Invoking K2JVMCompiler with arguments:"
|
||||
+ " -moduleName " + args.moduleName
|
||||
+ " -d " + args.destination
|
||||
+ " -friendPaths " + args.friendPaths.joinToString(";")
|
||||
|
@ -108,10 +107,15 @@ class KotlinCompiler @Inject constructor(
|
|||
} else if (severity == CompilerMessageSeverity.WARNING && KobaltLogger.LOG_LEVEL >= 2) {
|
||||
warn(location.dump(message))
|
||||
} else if (severity == CompilerMessageSeverity.INFO && KobaltLogger.LOG_LEVEL >= 2) {
|
||||
log(2, location.dump(message))
|
||||
logk(2, location.dump(message))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
System.setProperty("kotlin.incremental.compilation", "true")
|
||||
// TODO: experimental should be removed as soon as it becomes standard
|
||||
System.setProperty("kotlin.incremental.compilation.experimental", "true")
|
||||
|
||||
val exitCode = K2JVMCompiler().exec(collector, Services.Builder().build(), args)
|
||||
val result = TaskResult(exitCode == ExitCode.OK)
|
||||
return result
|
||||
|
@ -127,38 +131,38 @@ class KotlinCompiler @Inject constructor(
|
|||
* There are plenty of ways in which this method can break but this will be immediately
|
||||
* apparent if it happens.
|
||||
*/
|
||||
private fun invokeCompilerWithStringArgs(projectName: String, cp: List<File>, args: List<String>): TaskResult {
|
||||
val allArgs = listOf("-module-name", "project-" + projectName) + args
|
||||
log(2, "Calling kotlinc " + allArgs.joinToString(" "))
|
||||
|
||||
//
|
||||
// In order to capture the error stream, I need to invoke CLICompiler.exec(), which
|
||||
// is the first method that accepts a PrintStream for the errors in parameter
|
||||
//
|
||||
val result =
|
||||
ByteArrayOutputStream().use { baos ->
|
||||
val compilerJar = listOf(kotlinJarFiles.compiler.toURI().toURL())
|
||||
|
||||
val classLoader = ParentLastClassLoader(compilerJar)
|
||||
val compiler = classLoader.loadClass("org.jetbrains.kotlin.cli.common.CLICompiler")
|
||||
val kCompiler = classLoader.loadClass("org.jetbrains.kotlin.cli.jvm.K2JVMCompiler")
|
||||
|
||||
PrintStream(baos).use { ps ->
|
||||
val execMethod = compiler.declaredMethods.filter {
|
||||
it.name == "exec" && it.parameterTypes.size == 2
|
||||
}[0]
|
||||
val exitCode = execMethod.invoke(kCompiler.newInstance(), ps, allArgs.toTypedArray())
|
||||
val errorString = baos.toString(Charset.defaultCharset().toString())
|
||||
|
||||
// The return value is an enum
|
||||
val nameMethod = exitCode.javaClass.getMethod("name")
|
||||
val success = "OK" == nameMethod.invoke(exitCode).toString()
|
||||
TaskResult(success, errorString)
|
||||
}
|
||||
}
|
||||
|
||||
return result
|
||||
}
|
||||
// private fun invokeCompilerWithStringArgs(projectName: String, cp: List<File>, args: List<String>): TaskResult {
|
||||
// val allArgs = listOf("-module-name", "project-" + projectName) + args
|
||||
// kobaltLog(2, "Calling kotlinc " + allArgs.joinToString(" "))
|
||||
//
|
||||
// //
|
||||
// // In order to capture the error stream, I need to invoke CLICompiler.exec(), which
|
||||
// // is the first method that accepts a PrintStream for the errors in parameter
|
||||
// //
|
||||
// val result =
|
||||
// ByteArrayOutputStream().use { baos ->
|
||||
// val compilerJar = listOf(kotlinJarFiles.compiler.toURI().toURL())
|
||||
//
|
||||
// val classLoader = ParentLastClassLoader(compilerJar)
|
||||
// val compiler = classLoader.loadClass("org.jetbrains.kotlin.cli.common.CLICompiler")
|
||||
// val kCompiler = classLoader.loadClass("org.jetbrains.kotlin.cli.jvm.K2JVMCompiler")
|
||||
//
|
||||
// PrintStream(baos).use { ps ->
|
||||
// val execMethod = compiler.declaredMethods.filter {
|
||||
// it.name == "exec" && it.parameterTypes.size == 2
|
||||
// }[0]
|
||||
// val exitCode = execMethod.invoke(kCompiler.newInstance(), ps, allArgs.toTypedArray())
|
||||
// val errorString = baos.toString(Charset.defaultCharset().toString())
|
||||
//
|
||||
// // The return value is an enum
|
||||
// val nameMethod = exitCode.javaClass.getMethod("name")
|
||||
// val success = "OK" == nameMethod.invoke(exitCode).toString()
|
||||
// TaskResult(success, errorString)
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// return result
|
||||
// }
|
||||
|
||||
/**
|
||||
* Reorder the files so that the kotlin-*jar files are at the front.
|
||||
|
|
|
@ -69,9 +69,9 @@ class KotlinPlugin @Inject constructor(val executors: KobaltExecutors, val depen
|
|||
// config.sourceLinks.map { SourceLinkDefinition(it.dir, it.url, it.urlSuffix) }
|
||||
// )
|
||||
// gen.generate()
|
||||
// log(2, "Documentation generated in $outputDir")
|
||||
// kobaltLog(2, "Documentation generated in $outputDir")
|
||||
// } else {
|
||||
// log(2, "skip is true, not generating the documentation")
|
||||
// kobaltLog(2, "skip is true, not generating the documentation")
|
||||
// }
|
||||
// }
|
||||
// return TaskResult(success)
|
||||
|
|
|
@ -14,7 +14,6 @@ import com.beust.kobalt.maven.DependencyManager
|
|||
import com.beust.kobalt.maven.PomGenerator
|
||||
import com.beust.kobalt.misc.KFiles
|
||||
import com.beust.kobalt.misc.KobaltExecutors
|
||||
import com.beust.kobalt.misc.log
|
||||
import java.io.File
|
||||
import javax.inject.Inject
|
||||
import javax.inject.Singleton
|
||||
|
@ -147,7 +146,7 @@ class PackagingPlugin @Inject constructor(val dependencyManager : DependencyMana
|
|||
val buildDir = project.projectProperties.getString(LIBS_DIR)
|
||||
val buildDirFile = File(buildDir)
|
||||
if (buildDirFile.exists()) {
|
||||
log(1, "Installing from $buildDir to ${config.libDir}")
|
||||
context.logger.log(project.name, 1, "Installing from $buildDir to ${config.libDir}")
|
||||
|
||||
val toDir = KFiles.makeDir(config.libDir)
|
||||
KFiles.copyRecursively(buildDirFile, toDir, deleteFirst = true)
|
||||
|
|
|
@ -3,10 +3,14 @@ package com.beust.kobalt.plugin.publish
|
|||
import com.beust.kobalt.KobaltException
|
||||
import com.beust.kobalt.TaskResult
|
||||
import com.beust.kobalt.api.Project
|
||||
import com.beust.kobalt.internal.ParallelLogger
|
||||
import com.beust.kobalt.maven.Gpg
|
||||
import com.beust.kobalt.maven.Http
|
||||
import com.beust.kobalt.maven.Md5
|
||||
import com.beust.kobalt.misc.*
|
||||
import com.beust.kobalt.misc.CountingFileRequestBody
|
||||
import com.beust.kobalt.misc.KobaltExecutors
|
||||
import com.beust.kobalt.misc.error
|
||||
import com.beust.kobalt.misc.warn
|
||||
import com.google.gson.Gson
|
||||
import com.google.gson.JsonArray
|
||||
import com.google.gson.JsonObject
|
||||
|
@ -24,10 +28,10 @@ import javax.annotation.Nullable
|
|||
import javax.inject.Inject
|
||||
|
||||
class BintrayApi @Inject constructor(val http: Http,
|
||||
@Nullable @Assisted("username") val username: String?,
|
||||
@Nullable @Assisted("password") val password: String?,
|
||||
@Nullable @Assisted("org") val org: String?,
|
||||
val gpg: Gpg, val executors: KobaltExecutors) {
|
||||
@Nullable @Assisted("username") val username: String?,
|
||||
@Nullable @Assisted("password") val password: String?,
|
||||
@Nullable @Assisted("org") val org: String?,
|
||||
val gpg: Gpg, val executors: KobaltExecutors, val logger: ParallelLogger) {
|
||||
|
||||
companion object {
|
||||
const val BINTRAY_URL_API = "https://api.bintray.com"
|
||||
|
@ -141,7 +145,7 @@ class BintrayApi @Inject constructor(val http: Http,
|
|||
|
||||
val fileCount = filesToUpload.size
|
||||
if (fileCount > 0) {
|
||||
log(1, " Found $fileCount artifacts to upload")
|
||||
logger.log(project.name, 1, " Found $fileCount artifacts to upload")
|
||||
val errorMessages = arrayListOf<String>()
|
||||
|
||||
fun dots(total: Int, list: List<Boolean>, file: File? = null): String {
|
||||
|
@ -169,13 +173,13 @@ class BintrayApi @Inject constructor(val http: Http,
|
|||
results.add(true)
|
||||
}
|
||||
|
||||
log(1, " Uploading ${i + 1} / $fileCount " + dots(fileCount, results, file), false)
|
||||
logger.log(project.name, 1, " Uploading ${i + 1} / $fileCount " + dots(fileCount, results, file), false)
|
||||
}
|
||||
val success = results
|
||||
.filter { it }
|
||||
.count()
|
||||
log(1, " Uploaded $success / $fileCount " + dots(fileCount, results), false)
|
||||
log(1, "", true)
|
||||
logger.log(project.name, 1, " Uploaded $success / $fileCount " + dots(fileCount, results), false)
|
||||
logger.log(project.name, 1, "", true)
|
||||
if (errorMessages.isEmpty()) {
|
||||
return TaskResult()
|
||||
} else {
|
||||
|
|
|
@ -11,7 +11,10 @@ import com.beust.kobalt.internal.KobaltSettings
|
|||
import com.beust.kobalt.localMaven
|
||||
import com.beust.kobalt.maven.Md5
|
||||
import com.beust.kobalt.maven.PomGenerator
|
||||
import com.beust.kobalt.misc.*
|
||||
import com.beust.kobalt.misc.GithubApi2
|
||||
import com.beust.kobalt.misc.KFiles
|
||||
import com.beust.kobalt.misc.LocalProperties
|
||||
import com.beust.kobalt.misc.warn
|
||||
import java.io.File
|
||||
import java.net.URL
|
||||
import java.nio.file.Paths
|
||||
|
@ -68,6 +71,9 @@ public class PublishPlugin @Inject constructor(val files: KFiles, val factory: P
|
|||
return publishToMavenLocal(project)
|
||||
}
|
||||
|
||||
fun logk(projectName: String, level: Int, message: CharSequence)
|
||||
= context.logger.log(projectName, level, message)
|
||||
|
||||
private fun publishToMavenLocal(project: Project) : TaskResult {
|
||||
val files = findArtifactFiles(project)
|
||||
val allFiles = arrayListOf<File>()
|
||||
|
@ -82,12 +88,12 @@ public class PublishPlugin @Inject constructor(val files: KFiles, val factory: P
|
|||
}
|
||||
|
||||
val outputDir = URL(localMaven()).file
|
||||
log(1, "Deploying " + allFiles.size + " files to local maven " + outputDir)
|
||||
logk(project.name, 1, "Deploying " + allFiles.size + " files to local maven " + outputDir)
|
||||
val groupDir = project.group!!.replace('.', File.separatorChar)
|
||||
val targetDir = KFiles.makeDir(KFiles.joinDir(outputDir, groupDir,
|
||||
project.artifactId!!, project.version!!))
|
||||
allFiles.forEach { file ->
|
||||
log(2, " $file")
|
||||
logk(project.name, 2, " $file")
|
||||
KFiles.copy(Paths.get(file.absolutePath), Paths.get(targetDir.path, file.name),
|
||||
StandardCopyOption.REPLACE_EXISTING)
|
||||
}
|
||||
|
@ -131,7 +137,7 @@ public class PublishPlugin @Inject constructor(val files: KFiles, val factory: P
|
|||
}
|
||||
}
|
||||
} else {
|
||||
log(2, "Couldn't find any jcenter{} configuration, not uploading anything")
|
||||
context.logger.log(project.name, 2, "Couldn't find any jcenter{} configuration, not uploading anything")
|
||||
success = true
|
||||
}
|
||||
|
||||
|
@ -153,7 +159,7 @@ public class PublishPlugin @Inject constructor(val files: KFiles, val factory: P
|
|||
//
|
||||
if (configuration != null) {
|
||||
configuration.files.forEach {
|
||||
log(2, "Uploading $it tag: ${project.version}")
|
||||
logk(project.name, 2, "Uploading $it tag: ${project.version}")
|
||||
github.uploadRelease(project.name, project.version!!, it)
|
||||
}
|
||||
} else {
|
||||
|
|
|
@ -1 +1 @@
|
|||
kobalt.version=0.891
|
||||
kobalt.version=0.892
|
|
@ -1,7 +1,7 @@
|
|||
package com.beust.kobalt
|
||||
|
||||
import com.beust.kobalt.misc.KFiles
|
||||
import com.beust.kobalt.misc.log
|
||||
import com.beust.kobalt.misc.kobaltLog
|
||||
import org.testng.Assert
|
||||
import org.testng.annotations.Test
|
||||
import java.io.File
|
||||
|
@ -69,9 +69,9 @@ class VerifyKobaltZipTest : KobaltTest() {
|
|||
if (!foundWrapperJar) {
|
||||
throw KobaltException("Couldn't find wrapper jar in $zipFilePath")
|
||||
}
|
||||
log(1, "$zipFilePath looks correct")
|
||||
kobaltLog(1, "$zipFilePath looks correct")
|
||||
} else {
|
||||
log(1, "Couldn't find $zipFilePath, skipping test")
|
||||
kobaltLog(1, "Couldn't find $zipFilePath, skipping test")
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -89,7 +89,7 @@ class VerifyKobaltZipTest : KobaltTest() {
|
|||
if (file.exists()) {
|
||||
assertExistsInJarInputStream(JarInputStream(FileInputStream(file)), *fileNames)
|
||||
} else {
|
||||
log(1, "Couldn't find $file, skipping test")
|
||||
kobaltLog(1, "Couldn't find $file, skipping test")
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
package com.beust.kobalt.internal
|
||||
|
||||
import com.beust.kobalt.misc.Topological
|
||||
import com.beust.kobalt.misc.log
|
||||
import com.beust.kobalt.misc.kobaltLog
|
||||
import org.assertj.core.api.Assertions.assertThat
|
||||
import org.testng.Assert
|
||||
import org.testng.annotations.Test
|
||||
|
@ -29,7 +29,7 @@ class DynamicGraphTest {
|
|||
override val priority = 0
|
||||
override val name: String get() = "[Worker " + runNodes.map { it.toString() }.joinToString(",") + "]"
|
||||
override fun call() : TaskResult2<T> {
|
||||
log(2, "Running node $n")
|
||||
kobaltLog(2, "Running node $n")
|
||||
runNodes.add(n)
|
||||
return TaskResult2(errorFunction(n), null, n)
|
||||
}
|
||||
|
@ -159,27 +159,27 @@ class DynamicGraphTest {
|
|||
addEdge("b", "c")
|
||||
addEdge("b", "d")
|
||||
addNode("e")
|
||||
log(VERBOSE, dump())
|
||||
kobaltLog(VERBOSE, dump())
|
||||
Assert.assertEquals(freeNodes, setOf("c", "d", "e"))
|
||||
|
||||
removeNode("c")
|
||||
log(VERBOSE, dump())
|
||||
kobaltLog(VERBOSE, dump())
|
||||
Assert.assertEquals(freeNodes, setOf("d", "e"))
|
||||
|
||||
removeNode("d")
|
||||
log(VERBOSE, dump())
|
||||
kobaltLog(VERBOSE, dump())
|
||||
Assert.assertEquals(freeNodes, setOf("b", "e"))
|
||||
|
||||
removeNode("e")
|
||||
log(VERBOSE, dump())
|
||||
kobaltLog(VERBOSE, dump())
|
||||
Assert.assertEquals(freeNodes, setOf("b"))
|
||||
|
||||
removeNode("b")
|
||||
log(VERBOSE, dump())
|
||||
kobaltLog(VERBOSE, dump())
|
||||
Assert.assertEquals(freeNodes, setOf("a"))
|
||||
|
||||
removeNode("a")
|
||||
log(VERBOSE, dump())
|
||||
kobaltLog(VERBOSE, dump())
|
||||
Assert.assertTrue(freeNodes.isEmpty())
|
||||
Assert.assertTrue(nodes.isEmpty())
|
||||
}
|
||||
|
|
|
@ -46,7 +46,7 @@ class TaskManagerTest : BaseTest() {
|
|||
// alwaysRunAfter = TreeMultimap.create<String, String>().apply {
|
||||
// put("postCompile", "compile")
|
||||
// })
|
||||
// log(1, "GRAPH RUN: " + result)
|
||||
// kobaltLog((1, "GRAPH RUN: " + result)
|
||||
// return result
|
||||
// }
|
||||
//
|
||||
|
@ -84,7 +84,7 @@ class TaskManagerTest : BaseTest() {
|
|||
dependsOn, reverseDependsOn, runBefore, runAfter, alwaysRunAfter,
|
||||
{ it }, { t -> true })
|
||||
val result = DryRunGraphExecutor(graph).run()
|
||||
// log(1, "GRAPH RUN: $result")
|
||||
// kobaltLog((1, "GRAPH RUN: $result")
|
||||
return result
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue