From 8805e1c130c240a4ab3d0e988386a4003a2217c8 Mon Sep 17 00:00:00 2001 From: Cedric Beust Date: Tue, 9 Aug 2016 02:11:43 -0800 Subject: [PATCH] Logging clean up. --- .../main/kotlin/com/beust/kobalt/FileSpec.kt | 10 +-- .../kotlin/com/beust/kobalt/JarGenerator.kt | 8 +- .../src/main/kotlin/com/beust/kobalt/Jvm.kt | 6 +- .../main/kotlin/com/beust/kobalt/Plugins.kt | 7 +- .../com/beust/kobalt/ResolveDependency.kt | 8 +- .../main/kotlin/com/beust/kobalt/Variant.kt | 17 ++-- .../com/beust/kobalt/api/JarTemplate.kt | 6 +- .../kotlin/com/beust/kobalt/api/Project.kt | 3 +- .../com/beust/kobalt/archive/Archives.kt | 6 +- .../kobalt/internal/BaseProjectRunner.kt | 14 ++-- .../beust/kobalt/internal/BuildListeners.kt | 11 +-- .../beust/kobalt/internal/CompilerUtils.kt | 21 ++--- .../com/beust/kobalt/internal/DynamicGraph.kt | 18 ++--- .../beust/kobalt/internal/GenericRunner.kt | 15 ++-- .../kobalt/internal/IncrementalManager.kt | 4 +- .../kobalt/internal/JvmCompilerPlugin.kt | 17 ++-- .../beust/kobalt/internal/KobaltPluginXml.kt | 8 +- .../kobalt/internal/KobaltSettingsXml.kt | 3 +- .../beust/kobalt/internal/ParallelLogger.kt | 13 +-- .../kobalt/internal/ParallelProjectRunner.kt | 12 +-- .../internal/SequentialProjectRunner.kt | 16 ++-- .../com/beust/kobalt/internal/TaskManager.kt | 6 +- .../main/kotlin/com/beust/kobalt/maven/Gpg.kt | 4 +- .../kotlin/com/beust/kobalt/maven/Http.kt | 5 +- .../main/kotlin/com/beust/kobalt/maven/Md5.kt | 6 +- .../com/beust/kobalt/maven/PomGenerator.kt | 4 +- .../com/beust/kobalt/maven/aether/Aether.kt | 10 +-- .../maven/aether/ConsoleRepositoryListener.kt | 36 ++++----- .../maven/aether/ConsoleTransferListener.kt | 6 +- .../com/beust/kobalt/misc/CheckVersions.kt | 8 +- .../com/beust/kobalt/misc/GithubApi2.kt | 8 +- .../main/kotlin/com/beust/kobalt/misc/Io.kt | 20 ++--- .../kotlin/com/beust/kobalt/misc/JarUtils.kt | 6 +- .../kotlin/com/beust/kobalt/misc/KFiles.kt | 20 ++--- .../com/beust/kobalt/misc/KobaltExecutors.kt | 4 +- .../kobalt/misc/KobaltWrapperProperties.kt | 2 +- .../com/beust/kobalt/misc/NewRunCommand.kt | 5 +- .../com/beust/kobalt/misc/RunCommand.kt | 4 +- .../com/beust/kobalt/app/BuildFileCompiler.kt | 10 +-- .../com/beust/kobalt/app/BuildScriptUtil.kt | 4 +- .../kobalt/app/LanguageTemplateGenerator.kt | 5 +- .../com/beust/kobalt/app/ParsedBuildFile.kt | 6 +- .../com/beust/kobalt/app/ProjectFinder.kt | 4 +- .../com/beust/kobalt/app/ProjectGenerator.kt | 8 +- .../kotlin/com/beust/kobalt/app/Templates.kt | 6 +- .../com/beust/kobalt/app/UpdateKobalt.kt | 6 +- .../beust/kobalt/app/remote/KobaltClient.kt | 16 ++-- .../beust/kobalt/app/remote/KobaltServer.kt | 10 +-- .../com/beust/kobalt/app/remote/OldServer.kt | 18 ++--- .../plugin/application/ApplicationPlugin.kt | 5 +- .../plugin/application/NativeManager.kt | 6 +- .../com/beust/kobalt/plugin/apt/AptPlugin.kt | 3 +- .../beust/kobalt/plugin/java/JavaCompiler.kt | 17 ++-- .../kobalt/plugin/kotlin/KotlinCompiler.kt | 80 ++++++++++--------- .../kobalt/plugin/kotlin/KotlinPlugin.kt | 4 +- .../plugin/packaging/PackagingPlugin.kt | 3 +- .../beust/kobalt/plugin/publish/BintrayApi.kt | 22 ++--- .../kobalt/plugin/publish/PublishPlugin.kt | 16 ++-- src/main/resources/kobalt.properties | 2 +- .../com/beust/kobalt/VerifyKobaltZipTest.kt | 8 +- .../beust/kobalt/internal/DynamicGraphTest.kt | 16 ++-- .../beust/kobalt/internal/TaskManagerTest.kt | 4 +- 62 files changed, 336 insertions(+), 320 deletions(-) diff --git a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/FileSpec.kt b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/FileSpec.kt index 043e2bac..715c4221 100644 --- a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/FileSpec.kt +++ b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/FileSpec.kt @@ -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, 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 diff --git a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/JarGenerator.kt b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/JarGenerator.kt index b3cd661d..43c7c0a8 100644 --- a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/JarGenerator.kt +++ b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/JarGenerator.kt @@ -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() @Suppress("UNCHECKED_CAST") diff --git a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/Jvm.kt b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/Jvm.kt index 7dda6015..cfbdee25 100644 --- a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/Jvm.kt +++ b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/Jvm.kt @@ -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 } diff --git a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/Plugins.kt b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/Plugins.kt index e794ae8d..83c197cd 100644 --- a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/Plugins.kt +++ b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/Plugins.kt @@ -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 plugin.apply(project, context) } diff --git a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/ResolveDependency.kt b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/ResolveDependency.kt index d27afc0d..356db58a 100644 --- a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/ResolveDependency.kt +++ b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/ResolveDependency.kt @@ -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 } } diff --git a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/Variant.kt b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/Variant.kt index 2bafde37..04b428a8 100644 --- a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/Variant.kt +++ b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/Variant.kt @@ -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") diff --git a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/api/JarTemplate.kt b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/api/JarTemplate.kt index 1966b747..8c68b2b8 100644 --- a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/api/JarTemplate.kt +++ b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/api/JarTemplate.kt @@ -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) diff --git a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/api/Project.kt b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/api/Project.kt index 77aa6df3..10168808 100644 --- a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/api/Project.kt +++ b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/api/Project.kt @@ -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 diff --git a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/archive/Archives.kt b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/archive/Archives.kt index 96f88367..21c254c2 100644 --- a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/archive/Archives.kt +++ b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/archive/Archives.kt @@ -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 } diff --git a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/internal/BaseProjectRunner.kt b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/internal/BaseProjectRunner.kt index c75e4330..ccab2d69 100644 --- a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/internal/BaseProjectRunner.kt +++ b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/internal/BaseProjectRunner.kt @@ -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, node: T) { - log(LOG_LEVEL, " Processing always for $node") + kobaltLog(LOG_LEVEL, " Processing always for $node") always[toName(node)]?.let { to: Collection -> 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) diff --git a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/internal/BuildListeners.kt b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/internal/BuildListeners.kt index 7337b40d..fdfdcc50 100644 --- a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/internal/BuildListeners.kt +++ b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/internal/BuildListeners.kt @@ -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) } diff --git a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/internal/CompilerUtils.kt b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/internal/CompilerUtils.kt index bab12aee..93b2dd2b 100644 --- a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/internal/CompilerUtils.kt +++ b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/internal/CompilerUtils.kt @@ -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") } } diff --git a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/internal/DynamicGraph.kt b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/internal/DynamicGraph.kt index 1271f6cf..921a69a7 100644 --- a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/internal/DynamicGraph.kt +++ b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/internal/DynamicGraph.kt @@ -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(success: Boolean, errorMessage: String?, val value: T) } class DynamicGraph { - val VERBOSE = 2 + val VERBOSE = 3 val values : Collection get() = nodes.map { it.value } val nodes = hashSetOf>() private val dependedUpon = HashMultimap.create, PrivateNode>() @@ -90,7 +90,7 @@ class DynamicGraph { } 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 { } } 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(val graph : DynamicGraph, 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(val graph : DynamicGraph, 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) { return nodes.map { object: IWorker { override fun call(): TaskResult2? { - log(1, " Running worker $it") + kobaltLog(1, " Running worker $it") return TaskResult2(true, null, it) } diff --git a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/internal/GenericRunner.kt b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/internal/GenericRunner.kt index 77e45e49..19a035b4 100644 --- a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/internal/GenericRunner.kt +++ b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/internal/GenericRunner.kt @@ -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 diff --git a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/internal/IncrementalManager.kt b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/internal/IncrementalManager.kt index 135c55df..067cf0c1 100644 --- a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/internal/IncrementalManager.kt +++ b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/internal/IncrementalManager.kt @@ -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") } diff --git a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/internal/JvmCompilerPlugin.kt b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/internal/JvmCompilerPlugin.kt index 397de088..40035a65 100644 --- a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/internal/JvmCompilerPlugin.kt +++ b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/internal/JvmCompilerPlugin.kt @@ -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() } } diff --git a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/internal/KobaltPluginXml.kt b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/internal/KobaltPluginXml.kt index 1454f0fd..154ffcdb 100644 --- a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/internal/KobaltPluginXml.kt +++ b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/internal/KobaltPluginXml.kt @@ -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) diff --git a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/internal/KobaltSettingsXml.kt b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/internal/KobaltSettingsXml.kt index 2fad8ec1..407f8186 100644 --- a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/internal/KobaltSettingsXml.kt +++ b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/internal/KobaltSettingsXml.kt @@ -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()) } } diff --git a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/internal/ParallelLogger.kt b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/internal/ParallelLogger.kt index 29ae7b62..0ffd44d4 100644 --- a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/internal/ParallelLogger.kt +++ b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/internal/ParallelLogger.kt @@ -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>() private val runningProjects = ConcurrentLinkedQueue() @@ -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) } } diff --git a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/internal/ParallelProjectRunner.kt b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/internal/ParallelProjectRunner.kt index 8fb665e2..b2f0ec02 100644 --- a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/internal/ParallelProjectRunner.kt +++ b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/internal/ParallelProjectRunner.kt @@ -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, val runBefore: TreeMultimap, val runAfter: TreeMultimap, val alwaysRunAfter: TreeMultimap, val args: Args, val pluginInfo: PluginInfo, - val kobaltLog: ParallelLogger) + val logger: ParallelLogger) : BaseProjectRunner() { override fun runProjects(taskInfos: List, projects: List) : TaskManager .RunTargetResult { @@ -42,7 +43,7 @@ class ParallelProjectRunner(val tasksByNames: (Project) -> ListMultimap 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 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 ListMultimap ListMultimap()) 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 ListMultimap { override fun createWorkers(nodes: Collection) @@ -76,7 +78,7 @@ class SequentialProjectRunner(val tasksByNames: (Project) -> ListMultimap @@ -303,7 +303,7 @@ class TaskWorker(val tasks: List, val dryRun: Boolean, val pluginInfo: Pl override fun call() : TaskResult2 { 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 diff --git a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/maven/Gpg.kt b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/maven/Gpg.kt index 7078abb9..7ba988c5 100644 --- a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/maven/Gpg.kt +++ b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/maven/Gpg.kt @@ -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)) diff --git a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/maven/Http.kt b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/maven/Http.kt index 672d10b2..df286a47 100644 --- a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/maven/Http.kt +++ b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/maven/Http.kt @@ -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) diff --git a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/maven/Md5.kt b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/maven/Md5.kt index f2b0f4b8..7a50a69a 100644 --- a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/maven/Md5.kt +++ b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/maven/Md5.kt @@ -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 { diff --git a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/maven/PomGenerator.kt b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/maven/PomGenerator.kt index 8f349c99..d3972b86 100644 --- a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/maven/PomGenerator.kt +++ b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/maven/PomGenerator.kt @@ -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") } /** diff --git a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/maven/aether/Aether.kt b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/maven/aether/Aether.kt index 287b6169..1b812529 100644 --- a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/maven/aether/Aether.kt +++ b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/maven/aether/Aether.kt @@ -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 = 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 = 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") diff --git a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/maven/aether/ConsoleRepositoryListener.kt b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/maven/aether/ConsoleRepositoryListener.kt index 0fa2b981..eb1fe8c7 100644 --- a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/maven/aether/ConsoleRepositoryListener.kt +++ b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/maven/aether/ConsoleRepositoryListener.kt @@ -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) } } diff --git a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/maven/aether/ConsoleTransferListener.kt b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/maven/aether/ConsoleTransferListener.kt index ebd21a2c..90db0abf 100644 --- a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/maven/aether/ConsoleTransferListener.kt +++ b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/maven/aether/ConsoleTransferListener.kt @@ -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 + ")") } } diff --git a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/misc/CheckVersions.kt b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/misc/CheckVersions.kt index 106dfcad..9a0c275b 100644 --- a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/misc/CheckVersions.kt +++ b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/misc/CheckVersions.kt @@ -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() } diff --git a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/misc/GithubApi2.kt b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/misc/GithubApi2.kt index ad9b2095..6745e88d 100644 --- a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/misc/GithubApi2.kt +++ b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/misc/GithubApi2.kt @@ -70,7 +70,7 @@ class GithubApi2 @Inject constructor( class RetrofitError(var message: String = "", var errors : List = 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 diff --git a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/misc/Io.kt b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/misc/Io.kt index a354043e..df5fa340 100644 --- a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/misc/Io.kt +++ b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/misc/Io.kt @@ -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") } } diff --git a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/misc/JarUtils.kt b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/misc/JarUtils.kt index a17c2196..39091228 100644 --- a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/misc/JarUtils.kt +++ b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/misc/JarUtils.kt @@ -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")) } diff --git a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/misc/KFiles.kt b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/misc/KFiles.kt index 36f242d8..eaf9b01c 100644 --- a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/misc/KFiles.kt +++ b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/misc/KFiles.kt @@ -135,7 +135,7 @@ class KFiles { val seen = hashSetOf() 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 diff --git a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/misc/KobaltExecutors.kt b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/misc/KobaltExecutors.kt index 9e0ac2d6..1dc9ab41 100644 --- a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/misc/KobaltExecutors.kt +++ b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/misc/KobaltExecutors.kt @@ -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() diff --git a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/misc/KobaltWrapperProperties.kt b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/misc/KobaltWrapperProperties.kt index 8af0da44..06d01e7b 100644 --- a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/misc/KobaltWrapperProperties.kt +++ b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/misc/KobaltWrapperProperties.kt @@ -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)}" diff --git a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/misc/NewRunCommand.kt b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/misc/NewRunCommand.kt index a0178c68..ea18b30f 100644 --- a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/misc/NewRunCommand.kt +++ b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/misc/NewRunCommand.kt @@ -45,7 +45,8 @@ open class NewRunCommand(val info: RunCommandInfo) { companion object { val DEFAULT_SUCCESS = { output: List -> } - // val DEFAULT_SUCCESS_VERBOSE = { output: List -> log(2, "Success:\n " + output.joinToString("\n"))} + // val DEFAULT_SUCCESS_VERBOSE = { output: List -> kobaltLog(2, "Success:\n " + output.joinToString + // ("\n"))} // val defaultSuccess = DEFAULT_SUCCESS val DEFAULT_ERROR = { output: List -> @@ -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 { diff --git a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/misc/RunCommand.kt b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/misc/RunCommand.kt index 76231527..bad2995c 100644 --- a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/misc/RunCommand.kt +++ b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/misc/RunCommand.kt @@ -8,7 +8,7 @@ import java.util.concurrent.TimeUnit open class RunCommand(val command: String) { val DEFAULT_SUCCESS = { output: List -> } -// val DEFAULT_SUCCESS_VERBOSE = { output: List -> log(2, "Success:\n " + output.joinToString("\n"))} +// val DEFAULT_SUCCESS_VERBOSE = { output: List -> kobaltLog(2, "Success:\n " + output.joinToString("\n"))} val defaultSuccess = DEFAULT_SUCCESS val DEFAULT_ERROR = { output: List -> 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 -> diff --git a/src/main/kotlin/com/beust/kobalt/app/BuildFileCompiler.kt b/src/main/kotlin/com/beust/kobalt/app/BuildFileCompiler.kt index cda7557d..c79f9a2e 100644 --- a/src/main/kotlin/com/beust/kobalt/app/BuildFileCompiler.kt +++ b/src/main/kotlin/com/beust/kobalt/app/BuildFileCompiler.kt @@ -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) : 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 } diff --git a/src/main/kotlin/com/beust/kobalt/app/BuildScriptUtil.kt b/src/main/kotlin/com/beust/kobalt/app/BuildScriptUtil.kt index 0a633ab0..0e519d27 100644 --- a/src/main/kotlin/com/beust/kobalt/app/BuildScriptUtil.kt +++ b/src/main/kotlin/com/beust/kobalt/app/BuildScriptUtil.kt @@ -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) { diff --git a/src/main/kotlin/com/beust/kobalt/app/LanguageTemplateGenerator.kt b/src/main/kotlin/com/beust/kobalt/app/LanguageTemplateGenerator.kt index 403c8f5c..441939a2 100644 --- a/src/main/kotlin/com/beust/kobalt/app/LanguageTemplateGenerator.kt +++ b/src/main/kotlin/com/beust/kobalt/app/LanguageTemplateGenerator.kt @@ -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") } } diff --git a/src/main/kotlin/com/beust/kobalt/app/ParsedBuildFile.kt b/src/main/kotlin/com/beust/kobalt/app/ParsedBuildFile.kt index f3a1364c..9029358b 100644 --- a/src/main/kotlin/com/beust/kobalt/app/ParsedBuildFile.kt +++ b/src/main/kotlin/com/beust/kobalt/app/ParsedBuildFile.kt @@ -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).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 diff --git a/src/main/kotlin/com/beust/kobalt/app/ProjectFinder.kt b/src/main/kotlin/com/beust/kobalt/app/ProjectFinder.kt index 3e32cc9a..4a182678 100644 --- a/src/main/kotlin/com/beust/kobalt/app/ProjectFinder.kt +++ b/src/main/kotlin/com/beust/kobalt/app/ProjectFinder.kt @@ -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 diff --git a/src/main/kotlin/com/beust/kobalt/app/ProjectGenerator.kt b/src/main/kotlin/com/beust/kobalt/app/ProjectGenerator.kt index 7733076e..5c436547 100644 --- a/src/main/kotlin/com/beust/kobalt/app/ProjectGenerator.kt +++ b/src/main/kotlin/com/beust/kobalt/app/ProjectGenerator.kt @@ -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") } diff --git a/src/main/kotlin/com/beust/kobalt/app/Templates.kt b/src/main/kotlin/com/beust/kobalt/app/Templates.kt index c034504d..c43c5d5a 100644 --- a/src/main/kotlin/com/beust/kobalt/app/Templates.kt +++ b/src/main/kotlin/com/beust/kobalt/app/Templates.kt @@ -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) } } } diff --git a/src/main/kotlin/com/beust/kobalt/app/UpdateKobalt.kt b/src/main/kotlin/com/beust/kobalt/app/UpdateKobalt.kt index 0c989662..838d37f1 100644 --- a/src/main/kotlin/com/beust/kobalt/app/UpdateKobalt.kt +++ b/src/main/kotlin/com/beust/kobalt/app/UpdateKobalt.kt @@ -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") } } } diff --git a/src/main/kotlin/com/beust/kobalt/app/remote/KobaltClient.kt b/src/main/kotlin/com/beust/kobalt/app/remote/KobaltClient.kt index 35d9f24e..e4788867 100644 --- a/src/main/kotlin/com/beust/kobalt/app/remote/KobaltClient.kt +++ b/src/main/kotlin/com/beust/kobalt/app/remote/KobaltClient.kt @@ -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() } } diff --git a/src/main/kotlin/com/beust/kobalt/app/remote/KobaltServer.kt b/src/main/kotlin/com/beust/kobalt/app/remote/KobaltServer.kt index 5c696d16..4fe9b023 100644 --- a/src/main/kotlin/com/beust/kobalt/app/remote/KobaltServer.kt +++ b/src/main/kotlin/com/beust/kobalt/app/remote/KobaltServer.kt @@ -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() } } diff --git a/src/main/kotlin/com/beust/kobalt/app/remote/OldServer.kt b/src/main/kotlin/com/beust/kobalt/app/remote/OldServer.kt index e997364a..d95c9964 100644 --- a/src/main/kotlin/com/beust/kobalt/app/remote/OldServer.kt +++ b/src/main/kotlin/com/beust/kobalt/app/remote/OldServer.kt @@ -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, val cleanUpCallback val pending = arrayListOf() 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, 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, 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, val cleanUpCallback if (serverInfo.writer != null) { serverInfo.writer!!.println(content) } else { - log(1, "Queuing $content") + kobaltLog(1, "Queuing $content") synchronized(pending) { pending.add(commandData) } diff --git a/src/main/kotlin/com/beust/kobalt/plugin/application/ApplicationPlugin.kt b/src/main/kotlin/com/beust/kobalt/plugin/application/ApplicationPlugin.kt index fdd36316..5dba74c4 100644 --- a/src/main/kotlin/com/beust/kobalt/plugin/application/ApplicationPlugin.kt +++ b/src/main/kotlin/com/beust/kobalt/plugin/application/ApplicationPlugin.kt @@ -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 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() } diff --git a/src/main/kotlin/com/beust/kobalt/plugin/application/NativeManager.kt b/src/main/kotlin/com/beust/kobalt/plugin/application/NativeManager.kt index 7579e1c9..b6c0c945 100644 --- a/src/main/kotlin/com/beust/kobalt/plugin/application/NativeManager.kt +++ b/src/main/kotlin/com/beust/kobalt/plugin/application/NativeManager.kt @@ -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") } } } diff --git a/src/main/kotlin/com/beust/kobalt/plugin/apt/AptPlugin.kt b/src/main/kotlin/com/beust/kobalt/plugin/apt/AptPlugin.kt index 8fbef3dd..569a2ec9 100644 --- a/src/main/kotlin/com/beust/kobalt/plugin/apt/AptPlugin.kt +++ b/src/main/kotlin/com/beust/kobalt/plugin/apt/AptPlugin.kt @@ -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 } diff --git a/src/main/kotlin/com/beust/kobalt/plugin/java/JavaCompiler.kt b/src/main/kotlin/com/beust/kobalt/plugin/java/JavaCompiler.kt index 708d45e7..47bcb909 100644 --- a/src/main/kotlin/com/beust/kobalt/plugin/java/JavaCompiler.kt +++ b/src/main/kotlin/com/beust/kobalt/plugin/java/JavaCompiler.kt @@ -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) } diff --git a/src/main/kotlin/com/beust/kobalt/plugin/kotlin/KotlinCompiler.kt b/src/main/kotlin/com/beust/kobalt/plugin/kotlin/KotlinCompiler.kt index caf1d2df..67c9a3c7 100644 --- a/src/main/kotlin/com/beust/kobalt/plugin/kotlin/KotlinCompiler.kt +++ b/src/main/kotlin/com/beust/kobalt/plugin/kotlin/KotlinCompiler.kt @@ -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, args: List): 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, args: List): 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. diff --git a/src/main/kotlin/com/beust/kobalt/plugin/kotlin/KotlinPlugin.kt b/src/main/kotlin/com/beust/kobalt/plugin/kotlin/KotlinPlugin.kt index 8cfd752c..40860bc2 100644 --- a/src/main/kotlin/com/beust/kobalt/plugin/kotlin/KotlinPlugin.kt +++ b/src/main/kotlin/com/beust/kobalt/plugin/kotlin/KotlinPlugin.kt @@ -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) diff --git a/src/main/kotlin/com/beust/kobalt/plugin/packaging/PackagingPlugin.kt b/src/main/kotlin/com/beust/kobalt/plugin/packaging/PackagingPlugin.kt index d3540a41..576af59b 100644 --- a/src/main/kotlin/com/beust/kobalt/plugin/packaging/PackagingPlugin.kt +++ b/src/main/kotlin/com/beust/kobalt/plugin/packaging/PackagingPlugin.kt @@ -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) diff --git a/src/main/kotlin/com/beust/kobalt/plugin/publish/BintrayApi.kt b/src/main/kotlin/com/beust/kobalt/plugin/publish/BintrayApi.kt index 5c76c3bb..1b5de7bd 100644 --- a/src/main/kotlin/com/beust/kobalt/plugin/publish/BintrayApi.kt +++ b/src/main/kotlin/com/beust/kobalt/plugin/publish/BintrayApi.kt @@ -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() fun dots(total: Int, list: List, 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 { diff --git a/src/main/kotlin/com/beust/kobalt/plugin/publish/PublishPlugin.kt b/src/main/kotlin/com/beust/kobalt/plugin/publish/PublishPlugin.kt index 9032b056..a6cb8c60 100644 --- a/src/main/kotlin/com/beust/kobalt/plugin/publish/PublishPlugin.kt +++ b/src/main/kotlin/com/beust/kobalt/plugin/publish/PublishPlugin.kt @@ -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() @@ -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 { diff --git a/src/main/resources/kobalt.properties b/src/main/resources/kobalt.properties index a4a0d680..6ccbfcdf 100644 --- a/src/main/resources/kobalt.properties +++ b/src/main/resources/kobalt.properties @@ -1 +1 @@ -kobalt.version=0.891 \ No newline at end of file +kobalt.version=0.892 \ No newline at end of file diff --git a/src/test/kotlin/com/beust/kobalt/VerifyKobaltZipTest.kt b/src/test/kotlin/com/beust/kobalt/VerifyKobaltZipTest.kt index 4dd0402a..dab2690f 100644 --- a/src/test/kotlin/com/beust/kobalt/VerifyKobaltZipTest.kt +++ b/src/test/kotlin/com/beust/kobalt/VerifyKobaltZipTest.kt @@ -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") } } diff --git a/src/test/kotlin/com/beust/kobalt/internal/DynamicGraphTest.kt b/src/test/kotlin/com/beust/kobalt/internal/DynamicGraphTest.kt index 66f8c691..11fdb80c 100644 --- a/src/test/kotlin/com/beust/kobalt/internal/DynamicGraphTest.kt +++ b/src/test/kotlin/com/beust/kobalt/internal/DynamicGraphTest.kt @@ -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 { - 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()) } diff --git a/src/test/kotlin/com/beust/kobalt/internal/TaskManagerTest.kt b/src/test/kotlin/com/beust/kobalt/internal/TaskManagerTest.kt index 3cf4f5ec..1342cd35 100644 --- a/src/test/kotlin/com/beust/kobalt/internal/TaskManagerTest.kt +++ b/src/test/kotlin/com/beust/kobalt/internal/TaskManagerTest.kt @@ -46,7 +46,7 @@ class TaskManagerTest : BaseTest() { // alwaysRunAfter = TreeMultimap.create().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 }