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

Removing KobaltLogger.

This commit is contained in:
Cedric Beust 2015-10-14 00:03:55 -07:00
parent 5d80dc9203
commit 27857f48ab
41 changed files with 140 additions and 170 deletions

View file

@ -43,9 +43,6 @@ dependencies {
'com.beust:jcommander:1.48',
'com.beust:klaxon:0.16',
'com.squareup.okhttp:okhttp:2.4.0',
'org.slf4j:slf4j-api:1.7.12',
'org.slf4j:slf4j-simple:1.7.12',
'ch.qos.logback:logback-classic:1.1.2',
'org.jsoup:jsoup:1.8.2',
'com.google.inject:guice:4.0',
'com.google.inject.extensions:guice-assistedinject:4.0',

View file

@ -22,9 +22,6 @@
<orderEntry type="library" name="Gradle: com.google.guava:guava:18.0" level="project" />
<orderEntry type="library" name="Gradle: com.beust:klaxon:0.16" level="project" />
<orderEntry type="library" name="Gradle: com.squareup.okhttp:okhttp:2.4.0" level="project" />
<orderEntry type="library" name="Gradle: org.slf4j:slf4j-api:1.7.12" level="project" />
<orderEntry type="library" name="Gradle: org.slf4j:slf4j-simple:1.7.12" level="project" />
<orderEntry type="library" name="Gradle: ch.qos.logback:logback-classic:1.1.2" level="project" />
<orderEntry type="library" name="Gradle: org.jsoup:jsoup:1.8.2" level="project" />
<orderEntry type="library" name="Gradle: com.google.inject:guice:4.0" level="project" />
<orderEntry type="library" name="Gradle: com.google.inject.extensions:guice-assistedinject:4.0" level="project" />
@ -32,7 +29,6 @@
<orderEntry type="library" name="Gradle: com.github.spullara.mustache.java:compiler:0.8.18" level="project" />
<orderEntry type="library" name="Gradle: org.jetbrains.kotlin:kotlin-runtime:0.14.449" level="project" />
<orderEntry type="library" name="Gradle: com.squareup.okio:okio:1.4.0" level="project" />
<orderEntry type="library" name="Gradle: ch.qos.logback:logback-core:1.1.2" level="project" />
<orderEntry type="library" name="Gradle: javax.inject:javax.inject:1" level="project" />
<orderEntry type="library" name="Gradle: aopalliance:aopalliance:1.0" level="project" />
<orderEntry type="library" name="Gradle: org.codehaus.plexus:plexus-utils:3.0.20" level="project" />

View file

@ -6,16 +6,13 @@ import com.beust.kobalt.plugin.packaging.assemble
import com.beust.kobalt.plugin.kotlin.kotlinCompiler
import com.beust.kobalt.plugin.publish.jcenter
//import com.beust.kobalt.plugin.linecount.lineCount
//
////val repos = repos("https://dl.bintray.com/cbeust/maven/")
//
//val plugins = plugins(
// "com.beust.kobalt:kobalt-line-count:0.15"
//// file(homeDir("kotlin/kobalt-line-count/kobaltBuild/libs/kobalt-line-count-0.14.jar"))
//)
//
//val lc = lineCount {
// suffix = "**Plugin.kt"
// suffix = "**.md"
//}
fun readVersion() : String {
@ -43,13 +40,13 @@ val kobalt = kotlinProject(wrapper) {
group = "com.beust"
artifactId = name
version = readVersion()
description = "A build system in Kotlin"
url = "http://beust.com/kobalt"
licenses = listOf(com.beust.kobalt.api.License("Apache 2.0", "http://www.apache.org/licenses/LICENSE-2.0"))
scm = com.beust.kobalt.api.Scm(
url = "http://github.com/cbeust/kobalt",
connection = "https://github.com/cbeust/kobalt.git",
developerConnection = "git@github.com:cbeust/kobalt.git")
// description = "A build system in Kotlin"
// url = "http://beust.com/kobalt"
// licenses = listOf(com.beust.kobalt.api.License("Apache 2.0", "http://www.apache.org/licenses/LICENSE-2.0"))
// scm = com.beust.kobalt.api.Scm(
// url = "http://github.com/cbeust/kobalt",
// connection = "https://github.com/cbeust/kobalt.git",
// developerConnection = "git@github.com:cbeust/kobalt.git")
dependenciesTest {
compile("org.testng:testng:6.9.6")
@ -64,8 +61,6 @@ val kobalt = kotlinProject(wrapper) {
"com.beust:klaxon:0.16",
"com.squareup.okhttp:okhttp:2.5.0",
"org.slf4j:slf4j-api:1.7.12",
"org.slf4j:slf4j-simple:1.7.12",
"ch.qos.logback:logback-classic:1.1.3",
"org.jsoup:jsoup:1.8.3",
"com.google.inject:guice:4.0",
"com.google.inject.extensions:guice-assistedinject:4.0",

View file

@ -1 +1 @@
java -jar $(dirname $0)/kobalt/wrapper/kobalt-wrapper.jar $*
java -jar $(dirname $0)/kobalt/wrapper/kobalt-wrapper.jar $*

View file

@ -13,6 +13,9 @@ class Args {
"dependencies")
var checkVersions = false
@Parameter(names = arrayOf("--dev"), description = "Turn of dev mode, resulting in a more verbose log output")
var dev: Boolean = false
@Parameter(names = arrayOf("--dryRun"), description = "Display all the tasks that will get run without " +
"actually running them")
var dryRun: Boolean = false

View file

@ -1,7 +1,6 @@
package com.beust.kobalt
import com.beust.kobalt.api.Project
import com.beust.kobalt.misc.KobaltLogger
import com.beust.kobalt.misc.log
import java.io.File
import java.nio.file.*
import java.nio.file.attribute.BasicFileAttributes
@ -15,7 +14,7 @@ sealed class IFileSpec {
override public fun toString() = spec
}
class Glob(val spec: String) : IFileSpec(), KobaltLogger {
class Glob(val spec: String) : IFileSpec() {
override public fun toFiles(directory: String): List<File> {
val result = arrayListOf<File>()

View file

@ -1,15 +1,14 @@
package com.beust.kobalt
import com.beust.kobalt.misc.KobaltLogger
import com.beust.kobalt.maven.KobaltException
import com.beust.kobalt.OperatingSystem
import com.beust.kobalt.misc.log
import com.beust.kobalt.misc.warn
import java.io.File
import java.io.IOException
import java.util.HashMap
public open class Jvm constructor(
val os: com.beust.kobalt.OperatingSystem,
var javaBase: File? = null) : JavaInfo(), KobaltLogger {
var javaBase: File? = null) : JavaInfo() {
private var _javaHome: File? = null
override public var javaHome: File? = null

View file

@ -40,12 +40,12 @@ private class Main @Inject constructor(
val depFactory: DepFactory,
val checkVersions: CheckVersions,
val github: GithubApi,
val updateKobalt: UpdateKobalt)
: KobaltLogger {
val updateKobalt: UpdateKobalt) {
data class RunInfo(val jc: JCommander, val args: Args)
public fun run(jc: JCommander, args: Args) {
val latestVersionFuture = github.latestKobaltVersion
benchmark("Build", {
println(Banner.get() + Kobalt.version + "\n")
@ -69,7 +69,7 @@ private class Main @Inject constructor(
}
}
public class Worker<T>(val runNodes: ArrayList<T>, val n: T) : IWorker<T>, KobaltLogger {
public class Worker<T>(val runNodes: ArrayList<T>, val n: T) : IWorker<T> {
override val priority = 0
override fun call() : TaskResult2<T> {

View file

@ -10,7 +10,7 @@ import com.beust.kobalt.maven.KobaltException
import com.beust.kobalt.maven.LocalRepo
import com.beust.kobalt.misc.KFiles
import com.beust.kobalt.misc.KobaltExecutors
import com.beust.kobalt.misc.KobaltLogger
import com.beust.kobalt.misc.log
import com.beust.kobalt.plugin.DefaultPlugin
import com.beust.kobalt.plugin.java.JavaPlugin
import com.beust.kobalt.plugin.kotlin.KotlinPlugin
@ -31,7 +31,7 @@ public class Plugins @Inject constructor (val taskManagerProvider : Provider<Tas
val files: KFiles,
val depFactory: DepFactory,
val localRepo: LocalRepo,
val executors: KobaltExecutors): KobaltLogger {
val executors: KobaltExecutors) {
companion object {
public val MANIFEST_PLUGIN_CLASS : String = "Kobalt-Plugin-Class"

View file

@ -5,7 +5,7 @@ import com.beust.kobalt.api.Kobalt
import com.beust.kobalt.maven.Pom
import com.beust.kobalt.maven.Pom.Dependency
import com.beust.kobalt.misc.KFiles
import com.beust.kobalt.misc.KobaltLogger
import com.beust.kobalt.misc.log
import com.github.mustachejava.DefaultMustacheFactory
import java.io.File
import java.io.InputStreamReader
@ -18,7 +18,7 @@ import java.util.HashMap
/**
* Generate a new project.
*/
public class ProjectGenerator : KobaltLogger {
public class ProjectGenerator {
companion object {
/**
* Turns a dot property into a proper Kotlin identifier, e.g. common.version -> commonVersion

View file

@ -1,11 +1,9 @@
package com.beust.kobalt.internal
import com.beust.kobalt.misc.KobaltLogger
import com.beust.kobalt.misc.NamedThreadFactory
import com.beust.kobalt.misc.ToString
import com.beust.kobalt.misc.log
import com.google.common.collect.ArrayListMultimap
import com.google.common.collect.HashMultimap
import com.google.common.collect.TreeMultimap
import java.util.*
import java.util.concurrent.*
@ -38,17 +36,17 @@ public interface IThreadWorkerFactory<T> {
}
public class DynamicGraphExecutor<T>(val graph: DynamicGraph<T>,
val factory: IThreadWorkerFactory<T>) : KobaltLogger {
val factory: IThreadWorkerFactory<T>) {
val executor = Executors.newFixedThreadPool(5, NamedThreadFactory("DynamicGraphExecutor"))
val completion = ExecutorCompletionService<TaskResult2<T>>(executor)
public fun run() {
while (graph.freeNodes.size() > 0) {
log(2, "Current count: ${graph.nodeCount}")
log(3, "Current count: ${graph.nodeCount}")
synchronized(graph) {
val freeNodes = graph.freeNodes
freeNodes.forEach { graph.setStatus(it, DynamicGraph.Status.RUNNING)}
log(2, "submitting free nodes ${freeNodes}")
log(3, "submitting free nodes ${freeNodes}")
val callables : List<IWorker<T>> = factory.createWorkers(freeNodes)
callables.forEach { completion.submit(it) }
var n = callables.size()
@ -58,7 +56,7 @@ public class DynamicGraphExecutor<T>(val graph: DynamicGraph<T>,
try {
val future = completion.take()
val taskResult = future.get(2, TimeUnit.SECONDS)
log(2, "Received task result ${taskResult}")
log(3, "Received task result ${taskResult}")
n--
graph.setStatus(taskResult.value,
if (taskResult.success) {
@ -79,7 +77,7 @@ public class DynamicGraphExecutor<T>(val graph: DynamicGraph<T>,
/**
* Representation of the graph of methods.
*/
public class DynamicGraph<T> : KobaltLogger {
public class DynamicGraph<T> {
private val DEBUG = false
private val nodesReady = linkedSetOf<T>()
@ -148,7 +146,7 @@ public class DynamicGraph<T> : KobaltLogger {
// }
// }
log(2, "freeNodes: ${result}")
log(3, "freeNodes: ${result}")
return result
}
@ -178,7 +176,7 @@ public class DynamicGraph<T> : KobaltLogger {
private fun setSkipStatus(node: T, status: Status) {
dependingOn.get(node).forEach {
if (! nodesSkipped.contains(it)) {
log(2, "Node skipped: ${it}")
log(3, "Node skipped: ${it}")
nodesSkipped.add(it)
nodesReady.remove(it)
setSkipStatus(it, status)
@ -196,7 +194,7 @@ public class DynamicGraph<T> : KobaltLogger {
Status.RUNNING -> nodesRunning.add(node)
Status.FINISHED -> nodesFinished.add(node)
Status.ERROR -> {
log(2, "Node in error: ${node}")
log(3, "Node in error: ${node}")
nodesReady.remove(node)
nodesInError.add(node)
setSkipStatus(node, status)

View file

@ -3,13 +3,12 @@ package com.beust.kobalt.internal
import com.beust.kobalt.api.Project
import com.beust.kobalt.maven.IClasspathDependency
import com.beust.kobalt.misc.KFiles
import com.beust.kobalt.misc.KobaltLogger
import com.beust.kobalt.JavaInfo
import com.beust.kobalt.SystemProperties
import com.beust.kobalt.misc.log
import java.io.File
abstract class GenericTestRunner(open val project: Project, open val classpath: List<IClasspathDependency>)
: KobaltLogger {
abstract class GenericTestRunner(open val project: Project, open val classpath: List<IClasspathDependency>) {
abstract val mainClass: String
abstract val args: List<String>

View file

@ -2,11 +2,6 @@ package com.beust.kobalt.internal
import com.beust.kobalt.api.Project
import com.beust.kobalt.maven.IClasspathDependency
import com.beust.kobalt.misc.KFiles
import com.beust.kobalt.misc.KobaltLogger
import com.beust.kobalt.JavaInfo
import com.beust.kobalt.SystemProperties
import java.io.File
public class JUnitRunner(override val project: Project, override val classpath: List<IClasspathDependency>)
: GenericTestRunner(project, classpath) {

View file

@ -7,7 +7,7 @@ import com.beust.kobalt.api.annotation.Task
import com.beust.kobalt.maven.*
import com.beust.kobalt.misc.KFiles
import com.beust.kobalt.misc.KobaltExecutors
import com.beust.kobalt.misc.KobaltLogger
import com.beust.kobalt.misc.log
import java.io.File
import java.util.ArrayList
import javax.inject.Inject
@ -19,7 +19,7 @@ abstract public class JvmCompilerPlugin @Inject constructor(
open val files: KFiles,
open val depFactory: DepFactory,
open val dependencyManager: DependencyManager,
open val executors: KobaltExecutors) : BasePlugin(), KobaltLogger {
open val executors: KobaltExecutors) : BasePlugin() {
companion object {
const val TASK_CLEAN = "clean"

View file

@ -4,15 +4,15 @@ import com.beust.kobalt.Args
import com.beust.kobalt.Plugins
import com.beust.kobalt.api.PluginTask
import com.beust.kobalt.api.Project
import com.beust.kobalt.misc.KobaltLogger
import com.beust.kobalt.maven.KobaltException
import com.beust.kobalt.misc.log
import com.google.common.collect.TreeMultimap
import java.util.*
import javax.inject.Inject
import javax.inject.Singleton
@Singleton
public class TaskManager @Inject constructor(val plugins: Plugins, val args: Args) : KobaltLogger {
public class TaskManager @Inject constructor(val plugins: Plugins, val args: Args) {
private val runBefore = TreeMultimap.create<String, String>()
private val runAfter = TreeMultimap.create<String, String>()
private val alwaysRunAfter = TreeMultimap.create<String, String>()
@ -206,7 +206,7 @@ public class TaskManager @Inject constructor(val plugins: Plugins, val args: Arg
}
}
class TaskWorker(val tasks: List<PluginTask>, val dryRun: Boolean) : IWorker<PluginTask>, KobaltLogger {
class TaskWorker(val tasks: List<PluginTask>, val dryRun: Boolean) : IWorker<PluginTask> {
// override fun compareTo(other: IWorker2<PluginTask>): Int {
// return priority.compareTo(other.priority)
// }

View file

@ -3,11 +3,7 @@ package com.beust.kobalt.internal
import com.beust.kobalt.api.Project
import com.beust.kobalt.maven.IClasspathDependency
import com.beust.kobalt.misc.KFiles
import com.beust.kobalt.misc.KobaltLogger
import com.beust.kobalt.JavaInfo
import com.beust.kobalt.SystemProperties
import java.io.File
import java.util.*
public class TestNgRunner(override val project: Project, override val classpath: List<IClasspathDependency>)
: GenericTestRunner(project, classpath) {

View file

@ -7,8 +7,8 @@ import com.beust.kobalt.api.Project
import com.beust.kobalt.api.annotation.Task
import com.beust.kobalt.maven.KobaltException
import com.beust.kobalt.misc.KFiles
import com.beust.kobalt.misc.KobaltLogger
import com.beust.kobalt.misc.countChar
import com.beust.kobalt.misc.log
import com.beust.kobalt.plugin.kotlin.kotlinCompilePrivate
import com.google.inject.assistedinject.Assisted
import java.io.File
@ -23,7 +23,7 @@ import java.util.jar.JarInputStream
import javax.inject.Inject
public class ScriptCompiler2 @Inject constructor(@Assisted("buildFiles") val buildFiles: List<BuildFile>,
val files: KFiles, val plugins: Plugins) : KobaltLogger {
val files: KFiles, val plugins: Plugins) {
interface IFactory {
fun create(@Assisted("buildFiles") buildFiles: List<BuildFile>) : ScriptCompiler2

View file

@ -1,14 +1,13 @@
package com.beust.kobalt.maven
import com.beust.kobalt.misc.KFiles
import com.beust.kobalt.misc.KobaltLogger
import com.beust.kobalt.misc.log
import com.google.common.cache.CacheBuilder
import com.google.common.cache.CacheLoader
import com.google.common.cache.LoadingCache
import com.google.inject.assistedinject.Assisted
import java.io.ByteArrayOutputStream
import java.io.File
import java.security.MessageDigest
import java.util.concurrent.Callable
import java.util.concurrent.ExecutorService
import java.util.concurrent.Future
@ -43,7 +42,7 @@ class DownloadManager @Inject constructor(val factory: ArtifactFetcher.IFactory)
*/
class ArtifactFetcher @Inject constructor(@Assisted("url") val url: String,
@Assisted("fileName") val fileName: String,
val files: KFiles, val http: Http) : Callable<File>, KobaltLogger {
val files: KFiles, val http: Http) : Callable<File> {
interface IFactory {
fun create(@Assisted("url") url: String, @Assisted("fileName") fileName: String) : ArtifactFetcher
}

View file

@ -1,12 +1,6 @@
package com.beust.kobalt.maven
import com.beust.kobalt.maven.DownloadManager
import com.beust.kobalt.maven.KobaltException
import com.beust.kobalt.maven.Pom
import com.beust.kobalt.misc.KobaltExecutors
import com.beust.kobalt.misc.KobaltLogger
import java.util.ArrayList
import java.util.concurrent.ConcurrentHashMap
import java.util.concurrent.ExecutorService
import javax.inject.Inject
@ -14,7 +8,7 @@ public class DepFactory @Inject constructor(val localRepo: LocalRepo,
val repoFinder: RepoFinder,
val executors: KobaltExecutors,
val downloadManager: DownloadManager,
val pomFactory: Pom.IFactory) : KobaltLogger {
val pomFactory: Pom.IFactory) {
/**
* Parse the id and return the correct IClasspathDependency

View file

@ -1,6 +1,6 @@
package com.beust.kobalt.maven
import com.beust.kobalt.misc.KobaltLogger
import com.beust.kobalt.misc.log
import com.squareup.okhttp.*
import java.io.File
import java.io.IOException
@ -8,7 +8,7 @@ import java.io.InputStream
import javax.inject.Singleton
@Singleton
public class Http : KobaltLogger {
public class Http {
class Body(val body: ResponseBody, val code: Int) {
public fun getAsString() : String {
return body.string()

View file

@ -1,16 +1,13 @@
package com.beust.kobalt.maven
import com.beust.kobalt.misc.KFiles
import com.beust.kobalt.misc.KobaltLogger
import com.beust.kobalt.misc.Versions
import com.beust.kobalt.SystemProperties
import java.io.File
import java.util.Collections
import javax.inject.Inject
import javax.inject.Singleton
@Singleton
open public class LocalRepo(open val localRepo: String = KFiles.localRepo) : KobaltLogger {
open public class LocalRepo(open val localRepo: String = KFiles.localRepo) {
init {
val l = File(localRepo)
if (! l.exists()) {

View file

@ -18,7 +18,7 @@ public class MavenDependency @Inject constructor(override @Assisted("groupId") v
val repoFinder: RepoFinder,
val pomFactory: Pom.IFactory,
val downloadManager: DownloadManager)
: LocalDep(groupId, artifactId, version, localRepo), KobaltLogger, IClasspathDependency,
: LocalDep(groupId, artifactId, version, localRepo), IClasspathDependency,
Comparable<MavenDependency> {
override var jarFile: Future<File> by Delegates.notNull()
var pomFile: Future<File> by Delegates.notNull()

View file

@ -1,7 +1,7 @@
package com.beust.kobalt.maven
import com.beust.kobalt.misc.KobaltLogger
import com.beust.kobalt.misc.ToString
import com.beust.kobalt.misc.log
import com.google.inject.assistedinject.Assisted
import org.w3c.dom.Element
import org.w3c.dom.NodeList
@ -11,7 +11,7 @@ import javax.xml.xpath.XPathConstants
import kotlin.dom.childElements
public class Pom @javax.inject.Inject constructor(@Assisted val id: String,
@Assisted documentFile: java.io.File) : KobaltLogger {
@Assisted documentFile: java.io.File) {
val XPATH_FACTORY = javax.xml.xpath.XPathFactory.newInstance()
val XPATH = XPATH_FACTORY.newXPath()
var groupId: String? = null
@ -26,7 +26,7 @@ public class Pom @javax.inject.Inject constructor(@Assisted val id: String,
}
data public class Dependency(val groupId: String, val artifactId: String, val version: String,
val optional: Boolean = false, val scope: String? = null) : KobaltLogger {
val optional: Boolean = false, val scope: String? = null) {
/** When a variable is used in a maven file, e.g. ${version} */
private val VAR = "$" + "{"

View file

@ -1,22 +1,20 @@
package com.beust.kobalt.maven
import com.beust.kobalt.api.Project
import com.beust.kobalt.misc.KobaltLogger
import com.beust.kobalt.SystemProperties
import com.beust.kobalt.misc.log
import com.google.common.base.Preconditions
import com.google.inject.assistedinject.Assisted
import org.apache.maven.model.Developer
import org.apache.maven.model.License
import org.apache.maven.model.Model
import org.apache.maven.model.Scm
import org.apache.maven.model.io.xpp3.MavenXpp3Writer
import java.io.File
import java.io.StringWriter
import java.nio.charset.Charset
import java.util.*
import javax.inject.Inject
public class PomGenerator @Inject constructor(@Assisted val project: Project) : KobaltLogger {
public class PomGenerator @Inject constructor(@Assisted val project: Project) {
interface IFactory {
fun create(project: Project) : PomGenerator
}

View file

@ -2,8 +2,9 @@ package com.beust.kobalt.maven
import com.beust.kobalt.api.Kobalt
import com.beust.kobalt.misc.KobaltExecutors
import com.beust.kobalt.misc.KobaltLogger
import com.beust.kobalt.misc.Strings
import com.beust.kobalt.misc.log
import com.beust.kobalt.misc.warn
import com.google.common.cache.CacheBuilder
import com.google.common.cache.CacheLoader
import com.google.common.cache.LoadingCache
@ -20,7 +21,7 @@ import kotlin.dom.parseXml
* Find the repo that contains the given dependency among a list of repos. Searches are performed in parallel and
* cached so we never make a network call for the same dependency more than once.
*/
public class RepoFinder @Inject constructor(val http: Http, val executors: KobaltExecutors) : KobaltLogger {
public class RepoFinder @Inject constructor(val http: Http, val executors: KobaltExecutors) {
public fun findCorrectRepo(id: String): RepoResult {
return FOUND_REPOS.get(id)
}

View file

@ -10,7 +10,7 @@ import com.google.inject.Inject
* Find out if any newer versions of the dependencies are available.
*/
public class CheckVersions @Inject constructor(val depFactory : DepFactory,
val executors : KobaltExecutors) : KobaltLogger {
val executors : KobaltExecutors) {
fun run(projects: List<Project>) {
val executor = executors.newExecutor("CheckVersions", 5)

View file

@ -13,7 +13,7 @@ import java.util.concurrent.Future
/**
* Retrieve Kobalt's latest release version from github.
*/
public class GithubApi @Inject constructor(val executors: KobaltExecutors) : KobaltLogger {
public class GithubApi @Inject constructor(val executors: KobaltExecutors) {
companion object {
const val HOST = "https://api.github.com/"
}

View file

@ -20,7 +20,7 @@ public class KFiles {
val jarFile = File(jar)
val envJar = System.getenv("KOBALT_JAR")
if (! jarFile.exists() && envJar != null) {
KobaltLogger.debug("Using kobalt jar $envJar")
debug("Using kobalt jar $envJar")
return File(envJar).absolutePath
}
if (! jarFile.exists()) {
@ -80,7 +80,7 @@ public class KFiles {
allDirs.forEach {
if (! it.exists()) {
KobaltLogger.log(2, "Couldn't find directory ${it}")
log(2, "Couldn't find directory ${it}")
} else {
result.addAll(findRecursively(it, function))
}
@ -126,28 +126,28 @@ public class KFiles {
*/
fun findBuildScriptLocation(buildFile: BuildFile, jarFile: String) : String {
val result = joinDir(findDotDir(buildFile.directory).absolutePath, KFiles.SCRIPT_BUILD_DIR, jarFile)
KobaltLogger.log(2, "Script jar file: ${result}")
log(2, "Script jar file: ${result}")
return result
}
public fun saveFile(file: File, text: String) {
file.absoluteFile.parentFile.mkdirs()
file.writeText(text)
KobaltLogger.log(2, "Wrote ${file}")
log(2, "Wrote ${file}")
}
private fun isWindows() = System.getProperty("os.name").contains("Windows");
public fun copy(from: Path?, to: Path?, option: StandardCopyOption) {
if (isWindows() && to!!.toFile().exists()) {
KobaltLogger.log(2, "Windows detected, not overwriting ${to!!}")
log(2, "Windows detected, not overwriting ${to!!}")
} else {
try {
KobaltLogger.log(2, "Copy from $from!! to ${to!!}")
log(2, "Copy from $from!! to ${to!!}")
Files.copy(from, to, option)
} catch(ex: IOException) {
// Windows is anal about this
KobaltLogger.log(1, "Couldn't copy ${from} to ${to}: ${ex.getMessage()}")
log(1, "Couldn't copy ${from} to ${to}: ${ex.getMessage()}")
}
}
}

View file

@ -1,10 +1,6 @@
package com.beust.kobalt.misc
import com.beust.kobalt.maven.KobaltException
import com.google.inject.Provides
import java.util.concurrent.*
import javax.inject.Singleton
import kotlin.properties.Delegates
class NamedThreadFactory(val n: String) : ThreadFactory {
private val PREFIX = "K-"
@ -21,11 +17,11 @@ class NamedThreadFactory(val n: String) : ThreadFactory {
}
class KobaltExecutor(name: String, threadCount: Int)
: KobaltLogger, ThreadPoolExecutor(threadCount, threadCount, 5L, TimeUnit.SECONDS,
: ThreadPoolExecutor(threadCount, threadCount, 5L, TimeUnit.SECONDS,
LinkedBlockingQueue<Runnable>(), NamedThreadFactory(name)) {
override protected fun afterExecute(r: Runnable, t: Throwable?) {
super<ThreadPoolExecutor>.afterExecute(r, t)
super.afterExecute(r, t)
var ex : Throwable? = null
if (t == null && r is Future<*>) {
try {
@ -44,7 +40,7 @@ class KobaltExecutor(name: String, threadCount: Int)
}
}
public class KobaltExecutors : KobaltLogger {
public class KobaltExecutors {
public fun newExecutor(name: String, threadCount: Int) : ExecutorService
= KobaltExecutor(name, threadCount)

View file

@ -1,34 +1,33 @@
package com.beust.kobalt.misc
import org.slf4j.Logger
import org.slf4j.LoggerFactory
public interface KobaltLogger {
val logger : Logger
get() = LoggerFactory.getLogger(javaClass.simpleName)
import com.beust.kobalt.api.Kobalt
import java.text.SimpleDateFormat
import java.util.*
internal interface KobaltLogger {
companion object {
public var LOG_LEVEL : Int = 1
val logger : Logger get() = Logger(Kobalt.context!!.args.dev)
fun log(level: Int, s: String) {
if (level <= LOG_LEVEL) {
LoggerFactory.getLogger(KobaltLogger::class.java.simpleName).info(s)
logger.log("Logger", s)
}
}
fun warn(s: String, e: Throwable? = null) {
LoggerFactory.getLogger(KobaltLogger::class.java.simpleName).warn(s, e)
logger.warn("Logger", s, e)
}
fun debug(s: String) {
LoggerFactory.getLogger(KobaltLogger::class.java.simpleName).debug(s)
logger.debug(s)
}
}
final fun log(level: Int = 1, message: String) {
if (level <= LOG_LEVEL) {
logger.info(message)
logger.log("Logger", message)
}
}
@ -37,10 +36,48 @@ public interface KobaltLogger {
}
final fun error(message: String, e: Throwable? = null) {
logger.error("***** $message", e)
logger.error("Logger", "***** $message", e)
}
final fun warn(message: String, e: Throwable? = null) {
logger.warn(message, e)
logger.warn("Logger", message, e)
}
}
fun Any.log(level: Int, text: String) {
if (level <= KobaltLogger.LOG_LEVEL) {
KobaltLogger.logger.log(javaClass.simpleName, text)
}
}
fun Any.debug(text: String) {
KobaltLogger.logger.debug(javaClass.simpleName, text)
}
fun Any.warn(text: String) {
KobaltLogger.logger.warn(javaClass.simpleName, text)
}
class Logger(val dev: Boolean) {
val FORMAT = SimpleDateFormat("HH:mm:ss.SSS")
private fun getPattern(type: String, tag: String, message: String) =
if (dev) {
val ts = FORMAT.format(Date())
"$type/$ts [" + Thread.currentThread().name + "] $tag - $message"
} else {
message
}
final fun debug(tag: String, message: String) =
println(getPattern("D", tag, message))
final fun error(tag: String, message: String, e: Throwable? = null) =
println(getPattern("E", tag, message))
final fun warn(tag: String, message: String, e: Throwable? = null) =
println(getPattern("W", tag, message))
final fun log(tag: String, message: String) =
println(getPattern("L", tag, message))
}

View file

@ -16,7 +16,7 @@ public class Versions {
try {
return java.lang.Long.parseLong(s, radix)
} catch(ex: NumberFormatException) {
KobaltLogger.warn("Couldn't parse version \"${version}\"")
warn("Couldn't parse version \"${version}\"")
return 0L
}
}

View file

@ -1,20 +1,13 @@
package com.beust.kobalt.plugin
import com.beust.kobalt.Plugins
import com.beust.kobalt.api.BasePlugin
import com.beust.kobalt.api.Dependencies
import com.beust.kobalt.api.Project
import com.beust.kobalt.api.annotation.Directive
import com.beust.kobalt.api.annotation.Task
import com.beust.kobalt.internal.TaskResult
import com.beust.kobalt.misc.KobaltLogger
import javax.inject.Singleton
/**
* This plugin is used to gather tasks defined in build files, since these tasks don't really belong to any plugin.
*/
@Singleton
public class DefaultPlugin : BasePlugin(), KobaltLogger {
public class DefaultPlugin : BasePlugin() {
companion object {
public val NAME = "Default"
}

View file

@ -1,6 +1,5 @@
package com.beust.kobalt.plugin.apt
import com.beust.kobalt.Plugins
import com.beust.kobalt.api.BasePlugin
import com.beust.kobalt.api.Dependencies
import com.beust.kobalt.api.Kobalt
@ -8,11 +7,11 @@ import com.beust.kobalt.api.Project
import com.beust.kobalt.api.annotation.Directive
import com.beust.kobalt.api.annotation.Task
import com.beust.kobalt.internal.TaskResult
import com.beust.kobalt.misc.KobaltLogger
import com.beust.kobalt.misc.log
import javax.inject.Singleton
@Singleton
public class AptPlugin : BasePlugin(), KobaltLogger {
public class AptPlugin : BasePlugin() {
companion object {
public const val TASK_APT: String = "runApt"
}

View file

@ -10,10 +10,10 @@ import com.beust.kobalt.internal.TaskResult
import com.beust.kobalt.maven.*
import com.beust.kobalt.misc.KFiles
import com.beust.kobalt.misc.KobaltExecutors
import com.beust.kobalt.misc.KobaltLogger
import com.beust.kobalt.JavaInfo
import com.beust.kobalt.Jvm
import com.beust.kobalt.SystemProperties
import com.beust.kobalt.misc.log
import java.io.File
import javax.inject.Inject
import javax.inject.Singleton
@ -25,7 +25,7 @@ public class JavaPlugin @Inject constructor(
override val depFactory: DepFactory,
override val dependencyManager: DependencyManager,
override val executors: KobaltExecutors)
: JvmCompilerPlugin(localRepo, files, depFactory, dependencyManager, executors), KobaltLogger {
: JvmCompilerPlugin(localRepo, files, depFactory, dependencyManager, executors) {
init {
Kobalt.registerCompiler(JavaCompilerInfo())

View file

@ -4,9 +4,8 @@ import com.beust.kobalt.api.Kobalt
import com.beust.kobalt.internal.JvmCompilerPlugin
import com.beust.kobalt.internal.TaskResult
import com.beust.kobalt.maven.*
import com.beust.kobalt.misc.KFiles
import com.beust.kobalt.misc.KobaltExecutors
import com.beust.kobalt.misc.KobaltLogger
import com.beust.kobalt.misc.log
import org.jetbrains.kotlin.cli.jvm.K2JVMCompiler
import java.io.File
import javax.inject.Inject
@ -23,7 +22,7 @@ class KotlinCompiler @Inject constructor(override val localRepo : LocalRepo,
override val depFactory: DepFactory,
override val dependencyManager: DependencyManager,
override val executors: KobaltExecutors)
: JvmCompilerPlugin(localRepo, files, depFactory, dependencyManager, executors), KobaltLogger {
: JvmCompilerPlugin(localRepo, files, depFactory, dependencyManager, executors) {
private val KOTLIN_VERSION = "0.14.449"
override val name = "kotlin"

View file

@ -1,20 +1,15 @@
package com.beust.kobalt.plugin.kotlin
import com.beust.kobalt.Plugins
import com.beust.kobalt.api.ICompilerInfo
import com.beust.kobalt.api.Kobalt
import com.beust.kobalt.api.KobaltContext
import com.beust.kobalt.api.Project
import com.beust.kobalt.api.annotation.Directive
import com.beust.kobalt.api.annotation.Task
import com.beust.kobalt.internal.JvmCompilerPlugin
import com.beust.kobalt.internal.TaskResult
import com.beust.kobalt.internal.TaskResult2
import com.beust.kobalt.maven.*
import com.beust.kobalt.misc.KFiles
import com.beust.kobalt.misc.KobaltExecutors
import com.beust.kobalt.misc.KobaltLogger
import com.beust.kobalt.plugin.java.JavaProject
import com.beust.kobalt.misc.log
import java.io.File
import javax.inject.Inject
import javax.inject.Singleton
@ -26,7 +21,7 @@ public class KotlinPlugin @Inject constructor(
override val depFactory: DepFactory,
override val dependencyManager: DependencyManager,
override val executors: KobaltExecutors)
: JvmCompilerPlugin(localRepo, files, depFactory, dependencyManager, executors), KobaltLogger {
: JvmCompilerPlugin(localRepo, files, depFactory, dependencyManager, executors) {
init {
Kobalt.registerCompiler(KotlinCompilerInfo())

View file

@ -1,7 +1,7 @@
package com.beust.kobalt.plugin.packaging
import com.beust.kobalt.IFileSpec
import com.beust.kobalt.misc.KobaltLogger
import com.beust.kobalt.misc.log
import java.io.*
import java.util.jar.JarEntry
import java.util.jar.JarFile
@ -10,7 +10,7 @@ import java.util.jar.JarOutputStream
import java.util.zip.ZipEntry
import java.util.zip.ZipOutputStream
public class JarUtils : KobaltLogger {
public class JarUtils {
companion object {
// private fun isExcluded(entryName: String) : Boolean {
// val isAuth = entryName.startsWith("META-INF") and (
@ -90,7 +90,7 @@ public class JarUtils : KobaltLogger {
addSingleFile(directory, subFiles, outputStream, expandJarFiles)
} else {
if (expandJarFiles and source.name.endsWith(".jar")) {
KobaltLogger.log(2, "Writing contents of jar file ${source}")
log(2, "Writing contents of jar file ${source}")
val stream = JarInputStream(FileInputStream(source))
var entry = stream.nextEntry
while (entry != null) {
@ -151,7 +151,7 @@ public class JarUtils : KobaltLogger {
}
os.close()
KobaltLogger.log(1, "Deduplicated $fromFile.name")
log(1, "Deduplicated $fromFile.name")
}
}

View file

@ -14,22 +14,15 @@ import com.beust.kobalt.internal.JvmCompilerPlugin
import com.beust.kobalt.internal.TaskResult
import com.beust.kobalt.maven.DependencyManager
import com.beust.kobalt.maven.LocalRepo
import com.beust.kobalt.maven.MavenDependency
import com.beust.kobalt.maven.SimpleDep
import com.beust.kobalt.misc.KFiles
import com.beust.kobalt.misc.KobaltExecutors
import com.beust.kobalt.misc.KobaltLogger
import com.beust.kobalt.misc.ToString
import com.beust.kobalt.misc.*
import com.beust.kobalt.plugin.java.JavaPlugin
import java.io.File
import java.io.FileInputStream
import java.io.FileOutputStream
import java.io.OutputStream
import java.nio.file.FileSystems
import java.nio.file.PathMatcher
import java.nio.file.Paths
import java.nio.file.StandardCopyOption
import java.util.ArrayList
import java.util.jar.JarOutputStream
import java.util.zip.ZipOutputStream
import javax.inject.Inject
@ -44,7 +37,7 @@ public fun assemble(project: Project, init: Package.(p: Project) -> Unit): Packa
@Singleton
public class PackagingPlugin @Inject constructor(val dependencyManager : DependencyManager,
val executors: KobaltExecutors, val localRepo: LocalRepo) : BasePlugin(), KobaltLogger {
val executors: KobaltExecutors, val localRepo: LocalRepo) : BasePlugin() {
companion object {
public const val TASK_ASSEMBLE : String = "assemble"

View file

@ -6,15 +6,13 @@ import com.beust.kobalt.internal.TaskResult
import com.beust.kobalt.maven.Http
import com.beust.kobalt.maven.KobaltException
import com.beust.kobalt.maven.Md5
import com.beust.kobalt.misc.KobaltLogger
import com.beust.kobalt.misc.log
import com.google.inject.assistedinject.Assisted
import com.squareup.okhttp.Response
import org.jetbrains.annotations.Nullable
import java.io.ByteArrayInputStream
import java.io.File
import java.nio.charset.Charset
import java.nio.file.Files
import java.nio.file.Paths
import javax.inject.Inject
data class JCenterPackage(val jo: JsonObject) {
@ -45,7 +43,7 @@ open public class UnauthenticatedJCenterApi @Inject constructor(open val http: H
public class JCenterApi @Inject constructor (@Nullable @Assisted("username") val username: String?,
@Nullable @Assisted("password") val password: String?,
override val http: Http) : UnauthenticatedJCenterApi(http), KobaltLogger {
override val http: Http) : UnauthenticatedJCenterApi(http) {
interface IFactory {
fun create(@Nullable @Assisted("username") username: String?,

View file

@ -1,7 +1,5 @@
package com.beust.kobalt.plugin.publish
import com.beust.klaxon.string
import com.beust.kobalt.Plugins
import com.beust.kobalt.api.BasePlugin
import com.beust.kobalt.api.Kobalt
import com.beust.kobalt.api.Project
@ -9,10 +7,7 @@ import com.beust.kobalt.api.annotation.Directive
import com.beust.kobalt.api.annotation.Task
import com.beust.kobalt.internal.TaskResult
import com.beust.kobalt.maven.Http
import com.beust.kobalt.maven.KobaltException
import com.beust.kobalt.misc.KobaltLogger
import com.google.common.base.Preconditions
import org.jetbrains.kotlin.utils.sure
import java.io.File
import javax.inject.Inject
import javax.inject.Singleton
@ -21,7 +16,7 @@ import javax.inject.Singleton
public class PublishPlugin @Inject constructor(val http: Http, val files: com.beust.kobalt.misc.KFiles,
val factory: com.beust.kobalt.maven.PomGenerator.IFactory,
val jcenterFactory: JCenterApi.IFactory)
: BasePlugin(), KobaltLogger {
: BasePlugin() {
override val name = "publish"

View file

@ -2,13 +2,12 @@ package com.beust.kobalt.wrapper
import com.beust.kobalt.maven.Http
import com.beust.kobalt.misc.KFiles
import com.beust.kobalt.misc.KobaltLogger
import com.beust.kobalt.misc.benchmark
import com.beust.kobalt.JavaInfo
import com.beust.kobalt.SystemProperties
import com.beust.kobalt.misc.log
import java.io.File
import java.io.FileReader
import java.io.IOException
import java.io.InputStream
import java.nio.file.Files
import java.nio.file.Path
@ -23,7 +22,7 @@ public fun main(argv: Array<String>) {
/**
* Download and install a new wrapper if requested.
*/
public class Wrapper : KobaltLogger {
public class Wrapper {
// kobalt.properties
private val KOBALT_PROPERTIES = "kobalt.properties"
private val KOBALTW = "kobaltw"