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

Logging clean up.

This commit is contained in:
Cedric Beust 2016-08-09 02:11:43 -08:00
parent 8a672ad764
commit 8805e1c130
62 changed files with 336 additions and 320 deletions

View file

@ -1,6 +1,6 @@
package com.beust.kobalt
import com.beust.kobalt.misc.log
import com.beust.kobalt.misc.kobaltLog
import java.io.File
import java.nio.file.*
import java.nio.file.attribute.BasicFileAttributes
@ -28,15 +28,15 @@ sealed class IFileSpec {
private fun isIncluded(includeMatchers: Glob, excludes: List<Glob>, rel: Path) : Boolean {
excludes.forEach {
if (it.matches(rel)) {
log(3, "Excluding ${rel.toFile()}")
kobaltLog(3, "Excluding ${rel.toFile()}")
return false
}
}
if (includeMatchers.matches(rel)) {
log(3, "Including ${rel.toFile().path}")
kobaltLog(3, "Including ${rel.toFile().path}")
return true
}
log(2, "Excluding ${rel.toFile()} (not matching any include pattern")
kobaltLog(2, "Excluding ${rel.toFile()} (not matching any include pattern")
return false
}
@ -56,7 +56,7 @@ sealed class IFileSpec {
val path = p.normalize()
val rel = orgRootDir.relativize(path)
if (isIncluded(includes, excludes, path)) {
log(3, " including file " + rel.toFile() + " from rootDir $rootDir")
kobaltLog(3, " including file " + rel.toFile() + " from rootDir $rootDir")
result.add(rel.toFile())
}
return FileVisitResult.CONTINUE

View file

@ -36,16 +36,16 @@ class JarGenerator @Inject constructor(val dependencyManager: DependencyManager)
val normalized = Paths.get(file.path).normalize().toFile().path
includedSpecs.add(IFileSpec.FileSpec(normalized))
} else {
log(2, "Not adding ${file.path} to jar file because it's excluded")
kobaltLog(2, "Not adding ${file.path} to jar file because it's excluded")
}
}
} else {
log(2, "Directory $fromPath doesn't exist, not including it in the jar")
kobaltLog(2, "Directory $fromPath doesn't exist, not including it in the jar")
}
}
if (includedSpecs.size > 0) {
log(3, "Including specs $includedSpecs")
kobaltLog(3, "Including specs $includedSpecs")
result.add(IncludedFile(From(includedFile.from), To(includedFile.to), includedSpecs))
}
}
@ -95,7 +95,7 @@ class JarGenerator @Inject constructor(val dependencyManager: DependencyManager)
// If fatJar is true, add all the transitive dependencies as well: compile, runtime and dependent projects
//
if (jar.fatJar) {
log(2, "Finding included files for fat jar")
context.logger.log(project.name, 2, "Finding included files for fat jar")
val seen = hashSetOf<String>()
@Suppress("UNCHECKED_CAST")

View file

@ -1,6 +1,6 @@
package com.beust.kobalt
import com.beust.kobalt.misc.log
import com.beust.kobalt.misc.kobaltLog
import com.beust.kobalt.misc.warn
import java.io.File
import java.io.IOException
@ -93,7 +93,7 @@ public open class Jvm constructor(
// return false
// }
override public fun findExecutable(command: String): File {
override fun findExecutable(command: String): File {
if (javaHome != null) {
val jdkHome = if (javaHome!!.endsWith("jre")) javaHome!!.parentFile else javaHome
val exec = File(jdkHome, "bin/" + command)
@ -110,7 +110,7 @@ public open class Jvm constructor(
val pathExecutable = os.findInPath(command)
if (pathExecutable != null) {
log(2, "Unable to find the $command executable using home: " +
kobaltLog(2, "Unable to find the $command executable using home: " +
"$javaHome but found it on the PATH: $pathExecutable.")
return pathExecutable
}

View file

@ -8,10 +8,7 @@ import com.beust.kobalt.internal.PluginInfo
import com.beust.kobalt.internal.TaskManager
import com.beust.kobalt.maven.DependencyManager
import com.beust.kobalt.maven.LocalRepo
import com.beust.kobalt.misc.JarUtils
import com.beust.kobalt.misc.KFiles
import com.beust.kobalt.misc.KobaltExecutors
import com.beust.kobalt.misc.log
import com.beust.kobalt.misc.*
import com.google.inject.Provider
import java.io.File
import java.lang.reflect.Method
@ -65,7 +62,7 @@ class Plugins @Inject constructor (val taskManagerProvider : Provider<TaskManage
}
// Call apply() on each plug-in that accepts a project
log(2, "Applying plug-in \"${plugin.name}\"")
kobaltLog(2, "Applying plug-in \"${plugin.name}\"")
projects.filter { plugin.accept(it) }.forEach { project ->
plugin.apply(project, context)
}

View file

@ -6,7 +6,7 @@ import com.beust.kobalt.maven.MavenId
import com.beust.kobalt.maven.aether.KobaltAether
import com.beust.kobalt.misc.KobaltExecutors
import com.beust.kobalt.misc.Node
import com.beust.kobalt.misc.log
import com.beust.kobalt.misc.kobaltLog
import com.google.inject.Inject
import java.util.*
@ -42,7 +42,7 @@ class ResolveDependency @Inject constructor(
val seen = hashSetOf(dep.id)
root.addChildren(findChildren(root, seen))
log(1, AsciiArt.logBox(listOf(dep.id, url, dep.jarFile.get()).map { " $it" }))
kobaltLog(1, AsciiArt.logBox(listOf(dep.id, url, dep.jarFile.get()).map { " $it" }))
display(root.children)
println("")
@ -73,13 +73,13 @@ class ResolveDependency @Inject constructor(
if (! seen.contains(it.id)) {
val dep = Dep(it, root.value.level + 1)
val node = Node(dep)
log(2, "Found dependency ${dep.dep.id} level: ${dep.level}")
kobaltLog(2, "Found dependency ${dep.dep.id} level: ${dep.level}")
result.add(node)
seen.add(it.id)
node.addChildren(findChildren(node, seen))
}
}
log(2, "Children for ${root.value.dep.id}: ${result.size}")
kobaltLog(2, "Children for ${root.value.dep.id}: ${result.size}")
return result
}
}

View file

@ -2,9 +2,9 @@ package com.beust.kobalt
import com.beust.kobalt.api.*
import com.beust.kobalt.internal.ActorUtils
import com.beust.kobalt.internal.ParallelLogger
import com.beust.kobalt.internal.SourceSet
import com.beust.kobalt.misc.KFiles
import com.beust.kobalt.misc.log
import java.io.File
import java.util.*
@ -76,22 +76,21 @@ class Variant(val initialProductFlavor: ProductFlavorConfig? = null,
result.addAll(sourceDirectories)
} else {
// // The ordering of files is: 1) build type 2) product flavor 3) default
val kobaltLog = Kobalt.INJECTOR.getInstance(ParallelLogger::class.java)
buildType.let {
val dir = File(KFiles.joinDir("src", it.name, suffix))
log(3, "Adding source for build type ${it.name}: ${dir.path}")
kobaltLog.log(project.name, 3, "Adding source for build type ${it.name}: ${dir.path}")
result.add(dir)
}
productFlavor.let {
val dir = File(KFiles.joinDir("src", it.name, suffix))
log(3, "Adding source for product flavor ${it.name}: ${dir.path}")
kobaltLog.log(project.name, 3, "Adding source for product flavor ${it.name}: ${dir.path}")
result.add(dir)
}
result.addAll(allDirectories(project).map {
File(KFiles.joinDir("src", it, suffix))
}.filter {
it.exists()
})
result.addAll(allDirectories(project)
.map { File(KFiles.joinDir("src", it, suffix)) }
.filter(File::exists))
// Now that all the variant source directories have been added, add the project's default ones
result.addAll(sourceDirectories)
@ -175,7 +174,7 @@ class Variant(val initialProductFlavor: ProductFlavorConfig? = null,
val outputGeneratedSourceDirectory = File(result, pkg.replace('.', File.separatorChar))
val outputDir = File(outputGeneratedSourceDirectory, "BuildConfig." + contributor.buildConfigSuffix)
KFiles.saveFile(outputDir, code)
log(2, "Generated ${outputDir.path}")
context.logger.log(project.name, 2, "Generated ${outputDir.path}")
return result
} else {
throw KobaltException("Couldn't find a contributor to generateAndSave BuildConfig")

View file

@ -2,7 +2,7 @@ package com.beust.kobalt.api
import com.beust.kobalt.Args
import com.beust.kobalt.misc.KFiles
import com.beust.kobalt.misc.log
import com.beust.kobalt.misc.kobaltLog
import java.io.File
import java.io.FileOutputStream
import java.util.jar.JarInputStream
@ -22,7 +22,7 @@ abstract class JarTemplate(val jarName: String) : ITemplate {
continue
}
log(2, "Extracting: $entry to ${f.absolutePath}")
kobaltLog(2, "Extracting: $entry to ${f.absolutePath}")
FileOutputStream(f).use { fos ->
KFiles.copy(ins, fos)
}
@ -32,7 +32,7 @@ abstract class JarTemplate(val jarName: String) : ITemplate {
}
override fun generateTemplate(args: Args, classLoader: ClassLoader) {
log(2, "Generating template with class loader $classLoader")
kobaltLog(2, "Generating template with class loader $classLoader")
val destDir = File(".")
val ins = JarInputStream(classLoader.getResource(jarName).openConnection().inputStream)
extractFile(ins, destDir)

View file

@ -5,6 +5,7 @@ import com.beust.kobalt.api.annotation.Directive
import com.beust.kobalt.maven.DependencyManager
import com.beust.kobalt.maven.aether.KobaltAether
import com.beust.kobalt.misc.KFiles
import com.beust.kobalt.misc.kobaltLog
import com.beust.kobalt.misc.log
import org.apache.maven.model.Model
import java.io.File
@ -149,7 +150,7 @@ class Dependencies(val project: Project,
val resolved =
if (KobaltAether.isRangeVersion(it)) {
val result = Kobalt.INJECTOR.getInstance(KobaltAether::class.java).resolve(it).dependency.id
log(2, "Resolved range id $it to $result")
kobaltLog(2, "Resolved range id $it to $result")
result
} else {
it

View file

@ -36,7 +36,7 @@ class Archives {
try {
outputStreamFactory(FileOutputStream(result)).use {
JarUtils.addFiles(project.directory, includedFiles, it, expandJarFiles)
log(2, text = "Added ${includedFiles.size} files to $result")
context.logger.log(project.name, 2, "Added ${includedFiles.size} files to $result")
context.logger.log(project.name, 1, " Created $result")
}
} catch (e: Throwable) {
@ -47,7 +47,7 @@ class Archives {
}
} else {
log(3, " $result is up to date")
context.logger.log(project.name, 3, " $result is up to date")
}
project.projectProperties.put(JAR_NAME, result.absolutePath)
@ -68,7 +68,7 @@ class Archives {
File(KFiles.joinDir(directory, root.from, relFile.path))
if (file.isFile) {
if (file.lastModified() > lastModified) {
log(3, " TS - Outdated $file and $output "
kobaltLog(3, " TS - Outdated $file and $output "
+ Date(file.lastModified()) + " " + Date(output.lastModified()))
return true
}

View file

@ -3,7 +3,7 @@ package com.beust.kobalt.internal
import com.beust.kobalt.api.KobaltContext
import com.beust.kobalt.api.Project
import com.beust.kobalt.api.ProjectBuildStatus
import com.beust.kobalt.misc.log
import com.beust.kobalt.misc.kobaltLog
import com.google.common.annotations.VisibleForTesting
import com.google.common.collect.ArrayListMultimap
import com.google.common.collect.Multimap
@ -86,7 +86,7 @@ abstract class BaseProjectRunner {
val froms = nodeMap[from]
froms.forEach { f: T ->
nodeMap[to].forEach { t: T ->
log(LOG_LEVEL, " Adding edge ($text) $f -> $t")
kobaltLog(LOG_LEVEL, " Adding edge ($text) $f -> $t")
result.addEdge(f, t)
newToProcess.add(t)
}
@ -97,19 +97,19 @@ abstract class BaseProjectRunner {
* Whenever a task is added to the graph, we also add its alwaysRunAfter tasks.
*/
fun processAlways(always: Multimap<String, String>, node: T) {
log(LOG_LEVEL, " Processing always for $node")
kobaltLog(LOG_LEVEL, " Processing always for $node")
always[toName(node)]?.let { to: Collection<String> ->
to.forEach { t ->
nodeMap[t].forEach { from ->
log(LOG_LEVEL, " Adding always edge $from -> $node")
kobaltLog(LOG_LEVEL, " Adding always edge $from -> $node")
result.addEdge(from, node)
}
}
log(LOG_LEVEL, " ... done processing always for $node")
kobaltLog(LOG_LEVEL, " ... done processing always for $node")
}
}
log(LOG_LEVEL, " Current batch to process: $toProcess")
kobaltLog(LOG_LEVEL, " Current batch to process: $toProcess")
//
// Move dependsOn + reverseDependsOn in one multimap called allDepends
@ -131,7 +131,7 @@ abstract class BaseProjectRunner {
//
toProcess.forEach { taskInfo ->
val taskName = taskInfo.taskName
log(LOG_LEVEL, " ***** Current node: $taskName")
kobaltLog(LOG_LEVEL, " ***** Current node: $taskName")
nodeMap[taskName].forEach {
result.addNode(it)
processAlways(always, it)

View file

@ -3,6 +3,7 @@ package com.beust.kobalt.internal
import com.beust.kobalt.Args
import com.beust.kobalt.AsciiArt
import com.beust.kobalt.api.*
import com.beust.kobalt.misc.kobaltLog
import com.beust.kobalt.misc.log
import java.util.concurrent.ConcurrentHashMap
@ -63,11 +64,11 @@ class BuildListeners : IBuildListener, IBuildReportContributor {
val profiling = args.profiling
if (profiling) {
log(1, "\n" + AsciiArt.horizontalSingleLine + " Timings (in seconds)")
kobaltLog(1, "\n" + AsciiArt.horizontalSingleLine + " Timings (in seconds)")
timings.sortedByDescending { it.durationMillis }.forEach {
log(1, formatMillisRight(it.durationMillis, 10) + " " + it.taskName)
kobaltLog(1, formatMillisRight(it.durationMillis, 10) + " " + it.taskName)
}
log(1, "\n")
kobaltLog(1, "\n")
}
@ -90,7 +91,7 @@ class BuildListeners : IBuildListener, IBuildReportContributor {
table.append(" " + AsciiArt.verticalBar + " " + cl + " " + AsciiArt.verticalBar + "\n")
}
table.append(" " + AsciiArt.lowerBox(line.length))
log(1, table.toString())
kobaltLog(1, table.toString())
// }
}
@ -105,7 +106,7 @@ class BuildListeners : IBuildListener, IBuildReportContributor {
} else {
message.append(")")
}
log(1, message)
kobaltLog(1, message)
}

View file

@ -7,7 +7,6 @@ import com.beust.kobalt.maven.DependencyManager2
import com.beust.kobalt.maven.aether.Scope
import com.beust.kobalt.maven.dependency.FileDependency
import com.beust.kobalt.misc.KFiles
import com.beust.kobalt.misc.log
import com.google.inject.Inject
import java.io.File
import java.nio.file.Paths
@ -45,7 +44,8 @@ class CompilerUtils @Inject constructor(val files: KFiles,
failedResult = thisResult.failedResult
}
} else {
log(2, "${compiler.name} compiler not running on ${project.name} since no source files were found")
context.logger.log(project.name, 2,
"${compiler.name} compiler not running on ${project.name} since no source files were found")
}
return CompilerResult(results, failedResult)
@ -206,16 +206,17 @@ class CompilerUtils @Inject constructor(val files: KFiles,
val variantSourceDirs = context.variant.resourceDirectories(project, sourceSet)
if (variantSourceDirs.size > 0) {
JvmCompilerPlugin.lp(project, "Copying $sourceSet resources")
context.logger.log(project.name, 2, "Copying $sourceSet resources")
val absOutputDir = File(KFiles.joinDir(project.directory, project.buildDirectory, outputDir))
variantSourceDirs.map { File(project.directory, it.path) }.filter {
it.exists()
}.forEach {
log(2, "Copying from $it to $absOutputDir")
KFiles.copyRecursively(it, absOutputDir, deleteFirst = false)
}
variantSourceDirs
.map { File(project.directory, it.path) }
.filter(File::exists)
.forEach {
context.logger.log(project.name, 2, "Copying from $it to $absOutputDir")
KFiles.copyRecursively(it, absOutputDir, deleteFirst = false)
}
} else {
JvmCompilerPlugin.lp(project, "No resources to copy for $sourceSet")
context.logger.log(project.name, 2, "No resources to copy for $sourceSet")
}
}

View file

@ -5,7 +5,7 @@ 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.log
import com.beust.kobalt.misc.kobaltLog
import com.google.common.collect.HashMultimap
import java.lang.reflect.InvocationTargetException
import java.util.*
@ -16,7 +16,7 @@ open class TaskResult2<T>(success: Boolean, errorMessage: String?, val value: T)
}
class DynamicGraph<T> {
val VERBOSE = 2
val VERBOSE = 3
val values : Collection<T> get() = nodes.map { it.value }
val nodes = hashSetOf<PrivateNode<T>>()
private val dependedUpon = HashMultimap.create<PrivateNode<T>, PrivateNode<T>>()
@ -90,7 +90,7 @@ class DynamicGraph<T> {
}
fun removeNode(t: T) = synchronized(nodes) {
log(VERBOSE, " Removing node $t")
kobaltLog(VERBOSE, " Removing node $t")
PrivateNode(t).let { node ->
nodes.remove(node)
dependingOn.removeAll(node)
@ -130,7 +130,7 @@ class DynamicGraph<T> {
}
}
val result = nodes.map { it.value }.filter { !nonFree.contains(it) }.toHashSet()
log(VERBOSE, " Free nodes: $result")
kobaltLog(VERBOSE, " Free nodes: $result")
return result
}
}
@ -236,19 +236,19 @@ class DynamicGraphExecutor<T>(val graph : DynamicGraph<T>, val factory: IThreadW
running--
if (taskResult.success) {
nodesRun.add(taskResult.value)
log(2, "Task succeeded: $taskResult")
kobaltLog(3, "Task succeeded: $taskResult")
graph.removeNode(taskResult.value)
newFreeNodes.clear()
newFreeNodes.addAll(graph.freeNodes.minus(nodesRun))
} else {
log(2, "Task failed: $taskResult")
kobaltLog(3, "Task failed: $taskResult")
newFreeNodes.clear()
if (failedResult == null) {
failedResult = taskResult
}
}
} catch(ex: TimeoutException) {
log(2, "Time out")
kobaltLog(3, "Time out")
} catch(ex: Exception) {
val ite = ex.cause
if (ite is InvocationTargetException) {
@ -268,7 +268,7 @@ class DynamicGraphExecutor<T>(val graph : DynamicGraph<T>, val factory: IThreadW
}
fun dumpHistory() {
log(1, "Thread report")
kobaltLog(1, "Thread report")
val table = AsciiTable.Builder()
.columnWidth(11)
@ -323,7 +323,7 @@ fun main(argv: Array<String>) {
return nodes.map {
object: IWorker<String> {
override fun call(): TaskResult2<String>? {
log(1, " Running worker $it")
kobaltLog(1, " Running worker $it")
return TaskResult2(true, null, it)
}

View file

@ -4,7 +4,6 @@ import com.beust.kobalt.*
import com.beust.kobalt.api.*
import com.beust.kobalt.maven.DependencyManager2
import com.beust.kobalt.misc.KFiles
import com.beust.kobalt.misc.log
import com.google.common.annotations.VisibleForTesting
import java.io.File
import java.util.*
@ -55,7 +54,7 @@ abstract class GenericTestRunner: ITestRunnerContributor {
// result
// }
log(2, "Found ${result.size} test classes")
context.logger.log(project.name, 2, "Found ${result.size} test classes")
return result.map { it.second }
}
@ -118,18 +117,18 @@ abstract class GenericTestRunner: ITestRunnerContributor {
val pb = ProcessBuilder(allArgs)
pb.directory(File(project.directory))
pb.inheritIO()
log(2, "Running tests with classpath size ${classpath.size}")
log(2, "Launching " + allArgs.joinToString(" "))
context.logger.log(project.name, 2, "Running tests with classpath size ${classpath.size}")
context.logger.log(project.name, 2, "Launching " + allArgs.joinToString(" "))
val process = pb.start()
val errorCode = process.waitFor()
if (errorCode == 0) {
log(1, "All tests passed")
context.logger.log(project.name, 1, "All tests passed")
} else {
log(1, "Test failures")
context.logger.log(project.name, 1, "Test failures")
}
result = result || errorCode == 0
} else {
log(1, " No tests to run")
context.logger.log(project.name, 1, " No tests to run")
result = true
}
} else {
@ -165,7 +164,7 @@ abstract class GenericTestRunner: ITestRunnerContributor {
}
if (result.any()) {
log(2, "Final JVM test flags after running the contributors and interceptors: $result")
context.logger.log(project.name, 2, "Final JVM test flags after running the contributors and interceptors: $result")
}
return result

View file

@ -7,7 +7,7 @@ import com.beust.kobalt.Variant
import com.beust.kobalt.api.Kobalt
import com.beust.kobalt.api.Project
import com.beust.kobalt.misc.KFiles
import com.beust.kobalt.misc.log
import com.beust.kobalt.misc.kobaltLog
import com.google.gson.Gson
import com.google.gson.GsonBuilder
import com.google.inject.Inject
@ -182,5 +182,5 @@ class IncrementalManager @Inject constructor(val args: Args, @Assisted val fileN
}
val LEVEL = 2
private fun logIncremental(level: Int, s: String) = log(level, " INC - $s")
private fun logIncremental(level: Int, s: String) = kobaltLog(level, " INC - $s")
}

View file

@ -12,7 +12,10 @@ import com.beust.kobalt.maven.DependencyManager
import com.beust.kobalt.maven.DependencyManager2
import com.beust.kobalt.maven.LocalRepo
import com.beust.kobalt.maven.Md5
import com.beust.kobalt.misc.*
import com.beust.kobalt.misc.KFiles
import com.beust.kobalt.misc.KobaltExecutors
import com.beust.kobalt.misc.error
import com.beust.kobalt.misc.warn
import java.io.File
import java.util.*
import javax.inject.Inject
@ -49,13 +52,6 @@ open class JvmCompilerPlugin @Inject constructor(
const val GROUP_TEST = "test"
const val GROUP_BUILD = "build"
const val GROUP_DOCUMENTATION = "documentation"
/**
* Log with a project.
*/
fun lp(project: Project, s: String) {
log(2, "${project.name}: $s")
}
}
override val name: String = PLUGIN_NAME
@ -86,7 +82,7 @@ open class JvmCompilerPlugin @Inject constructor(
}
private fun taskTest(project: Project, configName: String): TaskResult {
lp(project, "Running tests: $configName")
context.logger.log(project.name, 2, "Running tests: $configName")
val testContributor = ActorUtils.selectAffinityActor(project, context,
context.pluginInfo.testRunnerContributors)
@ -96,7 +92,8 @@ open class JvmCompilerPlugin @Inject constructor(
val compileDependencies = dependencyManager2.resolve(project, context, isTest = false)
return testContributor.run(project, context, configName, testDependencies + compileDependencies)
} else {
lp(project, "Couldn't find a test runner for project ${project.name}, did you specify dependenciesTest{}?")
context.logger.log(project.name, 2,
"Couldn't find a test runner for project ${project.name}, did you specify dependenciesTest{}?")
return TaskResult()
}
}

View file

@ -2,7 +2,7 @@ package com.beust.kobalt.internal
import com.beust.kobalt.KobaltException
import com.beust.kobalt.api.*
import com.beust.kobalt.misc.log
import com.beust.kobalt.misc.kobaltLog
import java.io.ByteArrayInputStream
import java.io.InputStream
import javax.xml.bind.JAXBContext
@ -123,7 +123,7 @@ class PluginInfo(val xml: KobaltPluginXml, val pluginClassLoader: ClassLoader?,
fun readKobaltPluginXml(): PluginInfo {
// Note: use forward slash here since we're looking up this file in a .jar file
val url = Kobalt::class.java.classLoader.getResource(PLUGIN_CORE_XML)
log(2, "URL for core kobalt-plugin.xml: $url")
kobaltLog(2, "URL for core kobalt-plugin.xml: $url")
if (url != null) {
return readPluginXml(url.openConnection().inputStream)
} else {
@ -139,7 +139,7 @@ class PluginInfo(val xml: KobaltPluginXml, val pluginClassLoader: ClassLoader?,
val jaxbContext = JAXBContext.newInstance(KobaltPluginXml::class.java)
val kobaltPlugin: KobaltPluginXml = jaxbContext.createUnmarshaller().unmarshal(ins)
as KobaltPluginXml
log(2, "Parsed plugin XML file, found: " + kobaltPlugin.name)
kobaltLog(2, "Parsed plugin XML file, found: " + kobaltPlugin.name)
val result =
try {
PluginInfo(kobaltPlugin, pluginClassLoader, classLoader)
@ -242,7 +242,7 @@ class PluginInfo(val xml: KobaltPluginXml, val pluginClassLoader: ClassLoader?,
* Add the content of @param[pluginInfo] to this pluginInfo.
*/
fun addPluginInfo(pluginInfo: PluginInfo) {
log(2, "Found new plug-in, adding it to pluginInfo: $pluginInfo")
kobaltLog(2, "Found new plug-in, adding it to pluginInfo: $pluginInfo")
plugins.addAll(pluginInfo.plugins)
classpathContributors.addAll(pluginInfo.classpathContributors)

View file

@ -3,6 +3,7 @@ package com.beust.kobalt.internal
import com.beust.kobalt.ProxyConfig
import com.beust.kobalt.homeDir
import com.beust.kobalt.misc.KFiles
import com.beust.kobalt.misc.kobaltLog
import com.beust.kobalt.misc.log
import com.google.inject.Inject
import com.google.inject.Singleton
@ -112,7 +113,7 @@ class KobaltSettings @Inject constructor(val xmlFile: KobaltSettingsXml) {
return result
}
} else {
log(2, "Couldn't find ${KobaltSettings.SETTINGS_FILE_PATH}, using default settings")
kobaltLog(2, "Couldn't find ${KobaltSettings.SETTINGS_FILE_PATH}, using default settings")
return KobaltSettings(KobaltSettingsXml())
}
}

View file

@ -12,7 +12,7 @@ import java.util.concurrent.ConcurrentHashMap
import java.util.concurrent.ConcurrentLinkedQueue
interface ILogger {
fun log(tag: CharSequence, level: Int, message: CharSequence)
fun log(tag: CharSequence, level: Int, message: CharSequence, newLine: Boolean = true)
}
/**
@ -28,7 +28,8 @@ interface ILogger {
class ParallelLogger @Inject constructor(val args: Args) : ILogger {
enum class Type { LOG, WARN, ERROR }
class LogLine(val name: CharSequence? = null, val level: Int, val message: CharSequence, val type: Type)
class LogLine(val name: CharSequence? = null, val level: Int, val message: CharSequence, val type: Type,
val newLine: Boolean)
private val logLines = ConcurrentHashMap<CharSequence, ArrayList<LogLine>>()
private val runningProjects = ConcurrentLinkedQueue<String>()
@ -82,7 +83,7 @@ class ParallelLogger @Inject constructor(val args: Args) : ILogger {
val time = System.currentTimeMillis() - startTime!!
val m = (if (args.dev) "### [$time] " else "") + ll.message
when(ll.type) {
Type.LOG -> kobaltLog(ll.level, m)
Type.LOG -> kobaltLog(ll.level, m, ll.newLine)
Type.WARN -> kobaltWarn(m)
Type.ERROR -> kobaltError(m)
}
@ -114,11 +115,11 @@ class ParallelLogger @Inject constructor(val args: Args) : ILogger {
}
}
override fun log(tag: CharSequence, level: Int, message: CharSequence) {
override fun log(tag: CharSequence, level: Int, message: CharSequence, newLine: Boolean) {
if (args.parallel) {
addLogLine(tag, LogLine(tag, level, message, Type.LOG))
addLogLine(tag, LogLine(tag, level, message, Type.LOG, newLine))
} else {
kobaltLog(level, message)
kobaltLog(level, message, newLine)
}
}

View file

@ -7,6 +7,7 @@ import com.beust.kobalt.api.ITask
import com.beust.kobalt.api.Kobalt
import com.beust.kobalt.api.Project
import com.beust.kobalt.api.ProjectBuildStatus
import com.beust.kobalt.misc.kobaltLog
import com.google.common.collect.ListMultimap
import com.google.common.collect.TreeMultimap
import java.util.concurrent.Callable
@ -22,7 +23,7 @@ class ParallelProjectRunner(val tasksByNames: (Project) -> ListMultimap<String,
val reverseDependsOn: TreeMultimap<String, String>, val runBefore: TreeMultimap<String, String>,
val runAfter: TreeMultimap<String, String>,
val alwaysRunAfter: TreeMultimap<String, String>, val args: Args, val pluginInfo: PluginInfo,
val kobaltLog: ParallelLogger)
val logger: ParallelLogger)
: BaseProjectRunner() {
override fun runProjects(taskInfos: List<TaskManager.TaskInfo>, projects: List<Project>)
: TaskManager .RunTargetResult {
@ -42,7 +43,7 @@ class ParallelProjectRunner(val tasksByNames: (Project) -> ListMultimap<String,
ITask::name,
{ task: ITask -> task.plugin.accept(project) })
var lastResult = TaskResult()
kobaltLog.onProjectStarted(project.name)
logger.onProjectStarted(project.name)
context.logger.log(project.name, 1, AsciiArt.logBox("Building ${project.name}", indent = 5))
while (graph.freeNodes.any()) {
val toProcess = graph.freeNodes
@ -51,7 +52,7 @@ class ParallelProjectRunner(val tasksByNames: (Project) -> ListMultimap<String,
tasks.forEach { task ->
runBuildListenersForTask(project, context, task.name, start = true)
kobaltLog.log(project.name, 1,
logger.log(project.name, 1,
AsciiArt.taskColor(AsciiArt.horizontalSingleLine + " ${project.name}:${task.name}"))
val thisResult = if (dryRun) TaskResult2(true, null, task) else task.call()
if (lastResult.success) {
@ -64,7 +65,7 @@ class ParallelProjectRunner(val tasksByNames: (Project) -> ListMultimap<String,
graph.freeNodes.forEach { graph.removeNode(it) }
}
kobaltLog.onProjectStopped(project.name)
logger.onProjectStopped(project.name)
runBuildListenersForProject(project, context, false,
if (lastResult.success) ProjectBuildStatus.SUCCESS else ProjectBuildStatus.FAILED)
@ -99,9 +100,10 @@ class ParallelProjectRunner(val tasksByNames: (Project) -> ListMultimap<String,
}
val executor = DynamicGraphExecutor(projectGraph, factory, 5)
kobaltLog(1, "Parallel build starting")
val taskResult = executor.run()
kobaltLog.shutdown()
logger.shutdown()
if (args.parallel) {
executor.dumpHistory()

View file

@ -9,7 +9,6 @@ import com.beust.kobalt.api.Project
import com.beust.kobalt.api.ProjectBuildStatus
import com.beust.kobalt.misc.Strings
import com.beust.kobalt.misc.kobaltError
import com.beust.kobalt.misc.log
import com.google.common.collect.ListMultimap
import com.google.common.collect.TreeMultimap
import java.util.*
@ -33,14 +32,17 @@ class SequentialProjectRunner(val tasksByNames: (Project) -> ListMultimap<String
val messages = Collections.synchronizedList(arrayListOf<TaskManager.ProfilerInfo>())
val context = Kobalt.context!!
projects.forEach { project ->
log(1, AsciiArt.logBox("Building ${project.name}", indent = 5))
val projectName = project.name
fun klog(level: Int, message: String) = context.logger.log(projectName, level, message)
klog(1, AsciiArt.logBox("Building $projectName", indent = 5))
// Does the current project depend on any failed projects?
val fp = project.dependsOn.filter { failedProjects.contains(it.name) }.map(Project::name)
if (fp.size > 0) {
log(2, "Marking project ${project.name} as skipped")
klog(2, "Marking project $projectName as skipped")
failedProjects.add(project.name)
runBuildListenersForProject(project, context, false, ProjectBuildStatus.SKIPPED)
kobaltError("Not building project ${project.name} since it depends on failed "
@ -53,9 +55,9 @@ class SequentialProjectRunner(val tasksByNames: (Project) -> ListMultimap<String
// define "install"), so use a multimap
val tasksByNames = tasksByNames(project)
log(3, "Tasks:")
klog(3, "Tasks:")
tasksByNames.keys().forEach {
log(3, " $it: " + tasksByNames.get(it))
klog(3, " $it: " + tasksByNames.get(it))
}
val graph = createTaskGraph(project.name, taskInfos, tasksByNames,
@ -66,7 +68,7 @@ class SequentialProjectRunner(val tasksByNames: (Project) -> ListMultimap<String
//
// Now that we have a full graph, run it
//
log(2, "About to run graph:\n ${graph.dump()} ")
klog(2, "About to run graph:\n ${graph.dump()} ")
val factory = object : IThreadWorkerFactory<ITask> {
override fun createWorkers(nodes: Collection<ITask>)
@ -76,7 +78,7 @@ class SequentialProjectRunner(val tasksByNames: (Project) -> ListMultimap<String
val executor = DynamicGraphExecutor(graph, factory)
val thisResult = executor.run()
if (! thisResult.success) {
log(2, "Marking project ${project.name} as failed")
klog(2, "Marking project ${project.name} as failed")
failedProjects.add(project.name)
}

View file

@ -5,7 +5,7 @@ import com.beust.kobalt.api.*
import com.beust.kobalt.api.annotation.IncrementalTask
import com.beust.kobalt.api.annotation.Task
import com.beust.kobalt.misc.Topological
import com.beust.kobalt.misc.log
import com.beust.kobalt.misc.kobaltLog
import com.google.common.collect.ArrayListMultimap
import com.google.common.collect.ListMultimap
import com.google.common.collect.TreeMultimap
@ -240,7 +240,7 @@ class TaskManager @Inject constructor(val args: Args,
val method = staticTask.method
val methodName = method.declaringClass.toString() + "." + method.name
log(3, " Found task:${staticTask.name} method: $methodName")
kobaltLog(3, " Found task:${staticTask.name} method: $methodName")
val plugin = staticTask.plugin
projects.filter { plugin.accept(it) }.forEach { project ->
@ -303,7 +303,7 @@ class TaskWorker(val tasks: List<ITask>, val dryRun: Boolean, val pluginInfo: Pl
override fun call() : TaskResult2<ITask> {
if (tasks.size > 0) {
tasks[0].let {
log(1, AsciiArt.taskColor(AsciiArt.horizontalSingleLine + " ${it.project.name}:${it.name}"))
kobaltLog(1, AsciiArt.taskColor(AsciiArt.horizontalSingleLine + " ${it.project.name}:${it.name}"))
}
}
var success = true

View file

@ -2,7 +2,7 @@ package com.beust.kobalt.maven
import com.beust.kobalt.OperatingSystem
import com.beust.kobalt.misc.error
import com.beust.kobalt.misc.log
import com.beust.kobalt.misc.kobaltLog
import com.beust.kobalt.misc.warn
import com.google.inject.Singleton
import java.io.BufferedReader
@ -47,7 +47,7 @@ public class Gpg {
val pb = ProcessBuilder(allArgs)
pb.directory(directory)
log(2, "Signing file: " + allArgs.joinToString(" "))
kobaltLog(2, "Signing file: " + allArgs.joinToString(" "))
val process = pb.start()
val br = BufferedReader(InputStreamReader(process.errorStream))

View file

@ -3,6 +3,7 @@ package com.beust.kobalt.maven
import com.beust.kobalt.KobaltException
import com.beust.kobalt.internal.KobaltSettings
import com.beust.kobalt.misc.CountingFileRequestBody
import com.beust.kobalt.misc.kobaltLog
import com.beust.kobalt.misc.log
import com.google.inject.Inject
import okhttp3.*
@ -41,7 +42,7 @@ class Http @Inject constructor(val settings:KobaltSettings) {
fun percentProgressCallback(totalSize: Long) : (Long) -> Unit {
return { num: Long ->
val progress = num * 100 / totalSize
log(1, "\rUploaded: $progress%", newLine = false)
kobaltLog(1, "\rUploaded: $progress%", newLine = false)
}
}
@ -74,7 +75,7 @@ class Http @Inject constructor(val settings:KobaltSettings) {
requestBuilder.put(CountingFileRequestBody(file.file, file.mimeType, progressCallback)))
.build()
log(2, "Uploading $file to $url")
kobaltLog(2, "Uploading $file to $url")
val response = OkHttpClient.Builder().proxy(settings.proxyConfigs?.firstOrNull()?.toProxy()).build().newCall(request).execute()
if (! response.isSuccessful) {
error(response)

View file

@ -1,7 +1,7 @@
package com.beust.kobalt.maven
import com.beust.kobalt.misc.KFiles
import com.beust.kobalt.misc.log
import com.beust.kobalt.misc.kobaltLog
import java.io.File
import java.security.MessageDigest
import javax.xml.bind.DatatypeConverter
@ -31,13 +31,13 @@ public class Md5 {
var fileCount = 0
filesOrDirectories.filter { it.exists() }.forEach { file ->
if (file.isFile) {
log(2, " Calculating checksum of $file")
kobaltLog(2, " Calculating checksum of $file")
val bytes = toBytes(file)
md5.update(bytes, 0, bytes.size)
fileCount++
} else {
val files = KFiles.findRecursively(file) // , { f -> f.endsWith("java")})
log(2, " Calculating checksum of ${files.size} files in $file")
kobaltLog(2, " Calculating checksum of ${files.size} files in $file")
files.map {
File(file, it)
}.filter {

View file

@ -3,7 +3,7 @@ package com.beust.kobalt.maven
import com.beust.kobalt.SystemProperties
import com.beust.kobalt.api.Project
import com.beust.kobalt.misc.KFiles
import com.beust.kobalt.misc.log
import com.beust.kobalt.misc.kobaltLog
import com.google.inject.assistedinject.Assisted
import org.apache.maven.model.Developer
import org.apache.maven.model.Model
@ -30,7 +30,7 @@ class PomGenerator @Inject constructor(@Assisted val project: Project) {
val pomFile = SimpleDep(mavenId).toPomFileName()
val outputFile = File(outputDir, pomFile)
outputFile.writeText(generate(), Charset.defaultCharset())
log(1, " Created $outputFile")
kobaltLog(1, " Created $outputFile")
}
/**

View file

@ -12,7 +12,7 @@ import com.beust.kobalt.maven.LocalDep
import com.beust.kobalt.maven.LocalRepo
import com.beust.kobalt.maven.MavenId
import com.beust.kobalt.misc.Versions
import com.beust.kobalt.misc.log
import com.beust.kobalt.misc.kobaltLog
import com.beust.kobalt.misc.warn
import com.google.common.eventbus.EventBus
import com.google.inject.Inject
@ -102,7 +102,7 @@ class KobaltAether @Inject constructor (val settings: KobaltSettings, val aether
fun resolve(id: String, artifactScope: Scope? = null, filterScopes: Collection<Scope> = emptyList())
: DependencyResult {
log(ConsoleRepositoryListener.LOG_LEVEL, "Resolving $id")
kobaltLog(ConsoleRepositoryListener.LOG_LEVEL, "Resolving $id")
val result = resolveToArtifact(id, artifactScope, filterScopes)
if (result != null) {
return DependencyResult(AetherDependency(result.artifact), result.repository.toString())
@ -113,7 +113,7 @@ class KobaltAether @Inject constructor (val settings: KobaltSettings, val aether
fun resolveToArtifact(id: String, artifactScope: Scope? = null, filterScopes: Collection<Scope> = emptyList())
: AetherResult? {
log(ConsoleRepositoryListener.LOG_LEVEL, "Resolving $id")
kobaltLog(ConsoleRepositoryListener.LOG_LEVEL, "Resolving $id")
val results = aether.resolve(DefaultArtifact(MavenId.toKobaltId(id)), artifactScope, filterScopes)
if (results.size > 0) {
return results[0]
@ -287,11 +287,11 @@ class AetherDependency(val artifact: Artifact) : IClasspathDependency, Comparabl
if (!it.dependency.isOptional) {
result.add(AetherDependency(it.artifact))
} else {
log(ConsoleRepositoryListener.LOG_LEVEL, "Skipping optional dependency " + deps.root.artifact)
kobaltLog(ConsoleRepositoryListener.LOG_LEVEL, "Skipping optional dependency " + deps.root.artifact)
}
}
} else {
log(ConsoleRepositoryListener.LOG_LEVEL, "Skipping optional dependency " + deps.root.artifact)
kobaltLog(ConsoleRepositoryListener.LOG_LEVEL, "Skipping optional dependency " + deps.root.artifact)
}
} else {
warn("Couldn't resolve $artifact")

View file

@ -1,7 +1,7 @@
package com.beust.kobalt.maven.aether
import com.beust.kobalt.internal.eventbus.ArtifactDownloadedEvent
import com.beust.kobalt.misc.log
import com.beust.kobalt.misc.kobaltLog
import com.google.common.eventbus.EventBus
import org.eclipse.aether.AbstractRepositoryListener
import org.eclipse.aether.RepositoryEvent
@ -23,76 +23,76 @@ class ConsoleRepositoryListener @JvmOverloads constructor(out: PrintStream? = nu
}
override fun artifactDeployed(event: RepositoryEvent?) {
log(LOG_LEVEL, "Deployed " + event!!.artifact + " to " + event.repository)
kobaltLog(LOG_LEVEL, "Deployed " + event!!.artifact + " to " + event.repository)
}
override fun artifactDeploying(event: RepositoryEvent?) {
log(LOG_LEVEL, "Deploying " + event!!.artifact + " to " + event.repository)
kobaltLog(LOG_LEVEL, "Deploying " + event!!.artifact + " to " + event.repository)
}
override fun artifactDescriptorInvalid(event: RepositoryEvent?) {
log(LOG_LEVEL, "Invalid artifact descriptor for " + event!!.artifact + ": "
kobaltLog(LOG_LEVEL, "Invalid artifact descriptor for " + event!!.artifact + ": "
+ event.exception.message)
}
override fun artifactDescriptorMissing(event: RepositoryEvent?) {
log(LOG_LEVEL, "Missing artifact descriptor for " + event!!.artifact)
kobaltLog(LOG_LEVEL, "Missing artifact descriptor for " + event!!.artifact)
}
override fun artifactInstalled(event: RepositoryEvent?) {
log(LOG_LEVEL, "Installed " + event!!.artifact + " to " + event.file)
kobaltLog(LOG_LEVEL, "Installed " + event!!.artifact + " to " + event.file)
}
override fun artifactInstalling(event: RepositoryEvent?) {
log(LOG_LEVEL, "Installing " + event!!.artifact + " to " + event.file)
kobaltLog(LOG_LEVEL, "Installing " + event!!.artifact + " to " + event.file)
}
override fun artifactResolved(event: RepositoryEvent?) {
log(LOG_LEVEL, "Resolved artifact " + event!!.artifact + " from " + event.repository)
kobaltLog(LOG_LEVEL, "Resolved artifact " + event!!.artifact + " from " + event.repository)
}
override fun artifactDownloading(event: RepositoryEvent?) {
log(LOG_LEVEL, "Downloading artifact " + event!!.artifact + " from " + event.repository)
kobaltLog(LOG_LEVEL, "Downloading artifact " + event!!.artifact + " from " + event.repository)
}
override fun artifactDownloaded(event: RepositoryEvent?) {
if (event?.file != null && event?.artifact != null) {
val artifact = event!!.artifact
log(1, "Downloaded artifact " + artifact + " from " + event.repository)
kobaltLog(1, "Downloaded artifact " + artifact + " from " + event.repository)
eventBus.post(ArtifactDownloadedEvent(artifact.toString(), event.repository))
}
}
override fun artifactResolving(event: RepositoryEvent?) {
log(LOG_LEVEL, "Resolving artifact " + event!!.artifact)
kobaltLog(LOG_LEVEL, "Resolving artifact " + event!!.artifact)
}
override fun metadataDeployed(event: RepositoryEvent?) {
log(LOG_LEVEL, "Deployed " + event!!.metadata + " to " + event.repository)
kobaltLog(LOG_LEVEL, "Deployed " + event!!.metadata + " to " + event.repository)
}
override fun metadataDeploying(event: RepositoryEvent?) {
log(LOG_LEVEL, "Deploying " + event!!.metadata + " to " + event.repository)
kobaltLog(LOG_LEVEL, "Deploying " + event!!.metadata + " to " + event.repository)
}
override fun metadataInstalled(event: RepositoryEvent?) {
log(LOG_LEVEL, "Installed " + event!!.metadata + " to " + event.file)
kobaltLog(LOG_LEVEL, "Installed " + event!!.metadata + " to " + event.file)
}
override fun metadataInstalling(event: RepositoryEvent?) {
log(LOG_LEVEL, "Installing " + event!!.metadata + " to " + event.file)
kobaltLog(LOG_LEVEL, "Installing " + event!!.metadata + " to " + event.file)
}
override fun metadataInvalid(event: RepositoryEvent?) {
log(LOG_LEVEL, "Invalid metadata " + event!!.metadata)
kobaltLog(LOG_LEVEL, "Invalid metadata " + event!!.metadata)
}
override fun metadataResolved(event: RepositoryEvent?) {
log(LOG_LEVEL, "Resolved metadata " + event!!.metadata + " from " + event.repository)
kobaltLog(LOG_LEVEL, "Resolved metadata " + event!!.metadata + " from " + event.repository)
}
override fun metadataResolving(event: RepositoryEvent?) {
log(LOG_LEVEL, "Resolving metadata " + event!!.metadata + " from " + event.repository)
kobaltLog(LOG_LEVEL, "Resolving metadata " + event!!.metadata + " from " + event.repository)
}
}

View file

@ -1,7 +1,7 @@
package com.beust.kobalt.maven.aether
import com.beust.kobalt.misc.KobaltLogger
import com.beust.kobalt.misc.log
import com.beust.kobalt.misc.kobaltLog
import org.eclipse.aether.transfer.AbstractTransferListener
import org.eclipse.aether.transfer.MetadataNotFoundException
import org.eclipse.aether.transfer.TransferEvent
@ -27,7 +27,7 @@ class ConsoleTransferListener @JvmOverloads constructor(out: PrintStream? = null
override fun transferInitiated(event: TransferEvent?) {
val message = if (event!!.requestType == TransferEvent.RequestType.PUT) "Uploading" else "Downloading"
log(2, message + ": " + event.resource.repositoryUrl + event.resource.resourceName)
kobaltLog(2, message + ": " + event.resource.repositoryUrl + event.resource.resourceName)
}
override fun transferProgressed(event: TransferEvent?) {
@ -92,7 +92,7 @@ class ConsoleTransferListener @JvmOverloads constructor(out: PrintStream? = null
throughput = " at " + format.format(kbPerSec) + " KB/sec"
}
log(2, type + ": " + resource.repositoryUrl + resource.resourceName + " (" + len
kobaltLog(2, type + ": " + resource.repositoryUrl + resource.resourceName + " (" + len
+ throughput + ")")
}
}

View file

@ -38,17 +38,17 @@ class CheckVersions @Inject constructor(val depManager: DependencyManager,
newVersions.add(artifact.groupId + ":" + artifact.artifactId + ":" + highest)
}
} catch(e: KobaltException) {
log(1, " Cannot resolve ${dep.shortId}. ignoring")
kobaltLog(1, " Cannot resolve ${dep.shortId}. ignoring")
}
}
}
}
if (newVersions.size > 0) {
log(1, " New versions found:")
newVersions.forEach { log(1, " $it") }
kobaltLog(1, " New versions found:")
newVersions.forEach { kobaltLog(1, " $it") }
} else {
log(1, " All dependencies up to date")
kobaltLog(1, " All dependencies up to date")
}
executor.shutdown()
}

View file

@ -70,7 +70,7 @@ class GithubApi2 @Inject constructor(
class RetrofitError(var message: String = "", var errors : List<Error> = arrayListOf())
fun uploadRelease(packageName: String, tagName: String, zipFile: File) {
log(1, "Uploading release ${zipFile.name}")
kobaltLog(1, "Uploading release ${zipFile.name}")
val username = localProperties.get(PROPERTY_USERNAME, DOC_URL)
val accessToken = localProperties.get(PROPERTY_ACCESS_TOKEN, DOC_URL)
@ -86,7 +86,7 @@ class GithubApi2 @Inject constructor(
uploadAsset(accessToken, body.uploadUrl!!, Http.TypedFile("application/zip", zipFile), tagName)
.toBlocking()
.forEach { action ->
log(1, "\n${zipFile.name} successfully uploaded")
kobaltLog(1, "\n${zipFile.name} successfully uploaded")
}
}
}
@ -131,7 +131,7 @@ class GithubApi2 @Inject constructor(
warn("Didn't receive any body in the response to GitHub.getReleases()")
}
} catch(e: Exception) {
log(1, "Couldn't retrieve releases from github: " + e.message)
kobaltLog(1, "Couldn't retrieve releases from github: " + e.message)
e.printStackTrace()
// val error = parseRetrofitError(e)
// val details = if (error.errors != null) {
@ -141,7 +141,7 @@ class GithubApi2 @Inject constructor(
// }
// // TODO: If the credentials didn't work ("bad credentials"), should start again
// // using cbeust/kobalt, like above. Right now, just bailing.
// log(2, "Couldn't retrieve releases from github, ${error.message ?: e}: "
// kobaltLog(2, "Couldn't retrieve releases from github, ${error.message ?: e}: "
// + details?.code + " field: " + details?.field)
}
result

View file

@ -7,14 +7,14 @@ import java.nio.file.StandardCopyOption
class Io(val dryRun: Boolean = false) {
fun mkdirs(dir: String) {
log("mkdirs $dir")
kobaltLog("mkdirs $dir")
if (! dryRun) {
File(dir).mkdirs()
}
}
fun rm(path: String) {
log("rm $path")
kobaltLog("rm $path")
if (! dryRun) {
File(path).deleteRecursively()
@ -22,7 +22,7 @@ class Io(val dryRun: Boolean = false) {
}
fun moveFile(from: File, toDir: File) {
log("mv $from $toDir")
kobaltLog("mv $from $toDir")
if (! dryRun) {
require(from.exists(), { -> "$from should exist" })
require(from.isFile, { -> "$from should be a file" })
@ -34,7 +34,7 @@ class Io(val dryRun: Boolean = false) {
}
fun rename(from: File, to: File) {
log("rename $from $to")
kobaltLog("rename $from $to")
moveFile(from, to.parentFile)
if (from.name != to.name) {
File(to, from.name).renameTo(to)
@ -42,7 +42,7 @@ class Io(val dryRun: Boolean = false) {
}
fun copyDirectory(from: File, toDir: File) {
log("cp -r $from $toDir")
kobaltLog("cp -r $from $toDir")
if (! dryRun) {
KFiles.copyRecursively(from, toDir)
@ -56,7 +56,7 @@ class Io(val dryRun: Boolean = false) {
fun rmDir(dir: File, keep: (File) -> Boolean = { t -> false }) = rmDir(dir, keep, " ")
private fun rmDir(dir: File, keep: (File) -> Boolean, indent : String) {
log("rm -rf $dir")
kobaltLog("rm -rf $dir")
require(dir.isDirectory, { -> println("$dir should be a directory")})
@ -66,21 +66,21 @@ class Io(val dryRun: Boolean = false) {
it.deleteRecursively()
}
else {
log(indent + "rm $it")
kobaltLog(indent + "rm $it")
if (! dryRun) it.delete()
}
}
}
fun mkdir(dir: File) {
log("mkdir $dir")
kobaltLog("mkdir $dir")
if (! dryRun) {
dir.mkdirs()
}
}
private fun log(s: String) {
log(1, "[Io] $s")
private fun kobaltLog(s: String) {
kobaltLog(1, "[Io] $s")
}
}

View file

@ -47,14 +47,14 @@ public class JarUtils {
}
if (foundFile.isDirectory) {
log(2, " Writing contents of directory $foundFile")
kobaltLog(2, " Writing contents of directory $foundFile")
// Directory
val includedFile = IncludedFile(From(""), To(""), listOf(IFileSpec.GlobSpec("**")))
addSingleFile(localFile.path, includedFile, outputStream, expandJarFiles)
} else {
if (file.expandJarFiles && foundFile.name.endsWith(".jar") && ! file.from.contains("resources")) {
log(2, " Writing contents of jar file $foundFile")
kobaltLog(2, " Writing contents of jar file $foundFile")
val stream = JarInputStream(FileInputStream(localFile))
var entry = stream.nextEntry
while (entry != null) {
@ -100,7 +100,7 @@ public class JarUtils {
while (enumEntries.hasMoreElements()) {
val file = enumEntries.nextElement()
if (file.name == fileName) {
log(2, "Found $fileName in ${zip.name}")
kobaltLog(2, "Found $fileName in ${zip.name}")
zip.getInputStream(file).use { ins ->
return CharStreams.toString(InputStreamReader(ins, "UTF-8"))
}

View file

@ -135,7 +135,7 @@ class KFiles {
val seen = hashSetOf<java.nio.file.Path>()
allDirs.forEach { dir ->
if (! dir.exists()) {
log(2, "Couldn't find directory $dir")
kobaltLog(2, "Couldn't find directory $dir")
} else {
val files = findRecursively(dir, function)
files.map { Paths.get(it) }.forEach {
@ -144,7 +144,7 @@ class KFiles {
result.add(File(dir, rel.toFile().path).path)
seen.add(rel)
} else {
log(2, "Skipped file already seen in previous flavor: $rel")
kobaltLog(2, "Skipped file already seen in previous flavor: $rel")
}
}
}
@ -212,7 +212,7 @@ class KFiles {
dstFile.mkdirs()
} else {
if (Features.USE_TIMESTAMPS && dstFile.exists() && Md5.toMd5(src) == Md5.toMd5(dstFile)) {
log(3, " Identical files, not copying $src to $dstFile")
kobaltLog(3, " Identical files, not copying $src to $dstFile")
} else {
val target = src.copyTo(dstFile, true)
if (target.length() != src.length()) {
@ -242,34 +242,34 @@ class KFiles {
*/
fun findBuildScriptLocation(buildFile: BuildFile, jarFile: String) : String {
val result = joinDir(buildFile.dotKobaltDir.absolutePath, KFiles.SCRIPT_BUILD_DIR, jarFile)
log(2, "Script jar file: $result")
kobaltLog(2, "Script jar file: $result")
return result
}
fun saveFile(file: File, text: String) {
file.absoluteFile.parentFile.mkdirs()
file.writeText(text)
log(2, "Created $file")
kobaltLog(2, "Created $file")
}
private fun isWindows() = System.getProperty("os.name").contains("Windows");
fun copy(from: Path?, to: Path?, option: StandardCopyOption = StandardCopyOption.REPLACE_EXISTING) {
if (isWindows() && to!!.toFile().exists()) {
log(2, "Windows detected, not overwriting $to")
kobaltLog(2, "Windows detected, not overwriting $to")
} else {
try {
if (from != null && to != null) {
if (!Files.exists(to) || Md5.toMd5(from.toFile()) != Md5.toMd5(to.toFile())) {
log(3, "Copy from $from to $to")
kobaltLog(3, "Copy from $from to $to")
Files.copy(from, to, option)
} else {
log(3, " Not copying, indentical files: $from $to")
kobaltLog(3, " Not copying, indentical files: $from $to")
}
}
} catch(ex: IOException) {
// Windows is anal about this
log(1, "Couldn't copy $from to $to: ${ex.message}")
kobaltLog(1, "Couldn't copy $from to $to: ${ex.message}")
}
}
}
@ -326,7 +326,7 @@ class KFiles {
false
})
} else {
log(3, "Skipping nonexistent source directory $sourceDir")
kobaltLog(3, "Skipping nonexistent source directory $sourceDir")
}
}
return result

View file

@ -66,14 +66,14 @@ class KobaltExecutors {
progress(r)
result.add(r)
remainingMs -= (System.currentTimeMillis() - start)
log(3, "Received $r, remaining: $remainingMs ms")
kobaltLog(3, "Received $r, remaining: $remainingMs ms")
i++
}
if (remainingMs < 0) {
warn("Didn't receive all the results in time: $i / ${tasks.size}")
} else {
log(2, "Received all results in ${maxMs - remainingMs} ms")
kobaltLog(2, "Received all results in ${maxMs - remainingMs} ms")
}
executor.shutdown()

View file

@ -16,7 +16,7 @@ class KobaltWrapperProperties @Inject constructor() {
private val PROPERTY_DOWNLOAD_URL = "kobalt.downloadUrl"
fun create(version: String) {
log(2, "Creating $file with $version and ${defaultUrlFor(version)}")
kobaltLog(2, "Creating $file with $version and ${defaultUrlFor(version)}")
KFiles.saveFile(file, listOf(
"$PROPERTY_VERSION=$version"
// "$PROPERTY_DOWNLOAD_URL=${defaultUrlFor(version)}"

View file

@ -45,7 +45,8 @@ open class NewRunCommand(val info: RunCommandInfo) {
companion object {
val DEFAULT_SUCCESS = { output: List<String> -> }
// val DEFAULT_SUCCESS_VERBOSE = { output: List<String> -> log(2, "Success:\n " + output.joinToString("\n"))}
// val DEFAULT_SUCCESS_VERBOSE = { output: List<String> -> kobaltLog(2, "Success:\n " + output.joinToString
// ("\n"))}
// val defaultSuccess = DEFAULT_SUCCESS
val DEFAULT_ERROR = {
output: List<String> ->
@ -65,7 +66,7 @@ open class NewRunCommand(val info: RunCommandInfo) {
val pb = ProcessBuilder(allArgs)
pb.directory(info.directory)
log(2, "Running command in directory ${info.directory.absolutePath}" +
kobaltLog(2, "Running command in directory ${info.directory.absolutePath}" +
"\n " + allArgs.joinToString(" ").replace("\\", "/"))
pb.environment().let { pbEnv ->
info.env.forEach {

View file

@ -8,7 +8,7 @@ import java.util.concurrent.TimeUnit
open class RunCommand(val command: String) {
val DEFAULT_SUCCESS = { output: List<String> -> }
// val DEFAULT_SUCCESS_VERBOSE = { output: List<String> -> log(2, "Success:\n " + output.joinToString("\n"))}
// val DEFAULT_SUCCESS_VERBOSE = { output: List<String> -> kobaltLog(2, "Success:\n " + output.joinToString("\n"))}
val defaultSuccess = DEFAULT_SUCCESS
val DEFAULT_ERROR = {
output: List<String> -> error(output.joinToString("\n "))
@ -39,7 +39,7 @@ open class RunCommand(val command: String) {
val pb = ProcessBuilder(allArgs)
pb.directory(directory)
log(2, "Running command in directory ${directory.absolutePath}" +
kobaltLog(2, "Running command in directory ${directory.absolutePath}" +
"\n " + allArgs.joinToString(" "))
val process = pb.start()
pb.environment().let { pbEnv ->

View file

@ -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 }

View file

@ -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) {

View file

@ -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")
}
}

View file

@ -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

View file

@ -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

View file

@ -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")
}

View file

@ -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)
}
}
}

View file

@ -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")
}
}
}

View file

@ -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()
}
}

View file

@ -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()
}
}

View file

@ -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)
}

View file

@ -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()
}

View file

@ -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")
}
}
}

View file

@ -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
}

View file

@ -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)
}

View file

@ -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.

View file

@ -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)

View file

@ -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)

View file

@ -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 {

View file

@ -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 {

View file

@ -1 +1 @@
kobalt.version=0.891
kobalt.version=0.892

View file

@ -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")
}
}

View file

@ -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())
}

View file

@ -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
}