mirror of
https://github.com/ethauvin/kobalt.git
synced 2025-04-26 08:27:12 -07:00
Better error reporting.
This commit is contained in:
parent
9d02f020a6
commit
48ae5d966f
19 changed files with 71 additions and 47 deletions
|
@ -1,6 +1,5 @@
|
|||
package com.beust.kobalt
|
||||
|
||||
import com.beust.kobalt.maven.KobaltException
|
||||
import com.beust.kobalt.misc.log
|
||||
import com.beust.kobalt.misc.warn
|
||||
import java.io.File
|
||||
|
@ -31,7 +30,7 @@ public open class Jvm constructor(
|
|||
if (javaBase == null) {
|
||||
//discover based on what's in the sys. property
|
||||
try {
|
||||
javaBase = File(System.getProperty("java.home")).getCanonicalFile()
|
||||
javaBase = File(System.getProperty("java.home")).canonicalFile
|
||||
} catch (e: IOException) {
|
||||
throw KobaltException(e)
|
||||
}
|
||||
|
@ -52,10 +51,10 @@ public open class Jvm constructor(
|
|||
private fun findJavaHome(javaBase: File): File {
|
||||
val toolsJar = findToolsJar(javaBase)
|
||||
if (toolsJar != null) {
|
||||
return toolsJar.getParentFile().getParentFile()
|
||||
} else if (javaBase.getName().equals("jre", true) && File(javaBase.getParentFile(),
|
||||
return toolsJar.parentFile.parentFile
|
||||
} else if (javaBase.name.equals("jre", true) && File(javaBase.parentFile,
|
||||
"bin/java").exists()) {
|
||||
return javaBase.getParentFile()
|
||||
return javaBase.parentFile
|
||||
} else {
|
||||
return javaBase
|
||||
}
|
||||
|
|
7
src/main/kotlin/com/beust/kobalt/KobaltException.kt
Normal file
7
src/main/kotlin/com/beust/kobalt/KobaltException.kt
Normal file
|
@ -0,0 +1,7 @@
|
|||
package com.beust.kobalt
|
||||
|
||||
class KobaltException(s: String? = null, ex: Throwable? = null, val docUrl: String? = null)
|
||||
: RuntimeException(s, ex) {
|
||||
constructor(ex: Throwable?) : this(null, ex, null)
|
||||
}
|
||||
|
|
@ -11,7 +11,6 @@ import com.beust.kobalt.kotlin.BuildFile
|
|||
import com.beust.kobalt.kotlin.BuildFileCompiler
|
||||
import com.beust.kobalt.maven.DepFactory
|
||||
import com.beust.kobalt.maven.Http
|
||||
import com.beust.kobalt.maven.KobaltException
|
||||
import com.beust.kobalt.maven.LocalRepo
|
||||
import com.beust.kobalt.misc.*
|
||||
import com.google.inject.Guice
|
||||
|
@ -95,7 +94,7 @@ private class Main @Inject constructor(
|
|||
try {
|
||||
result = runWithArgs(jc, args, argv)
|
||||
} catch(ex: KobaltException) {
|
||||
error(ex.message ?: "", ex)
|
||||
error("", ex)
|
||||
result = 1
|
||||
} finally {
|
||||
executors.shutdown()
|
||||
|
|
|
@ -6,7 +6,6 @@ import com.beust.kobalt.internal.PluginInfo
|
|||
import com.beust.kobalt.internal.TaskManager
|
||||
import com.beust.kobalt.maven.DepFactory
|
||||
import com.beust.kobalt.maven.IClasspathDependency
|
||||
import com.beust.kobalt.maven.KobaltException
|
||||
import com.beust.kobalt.maven.LocalRepo
|
||||
import com.beust.kobalt.misc.KFiles
|
||||
import com.beust.kobalt.misc.KobaltExecutors
|
||||
|
@ -100,11 +99,7 @@ public class Plugins @Inject constructor (val taskManagerProvider : Provider<Tas
|
|||
|
||||
fun toTask(m: Method, project: Project, plugin: IPlugin): (Project) -> TaskResult {
|
||||
val result: (Project) -> TaskResult = {
|
||||
try {
|
||||
m.invoke(plugin, project) as TaskResult
|
||||
} catch(ex: Throwable) {
|
||||
throw KobaltException("Error while invoking task $m on plugin $plugin")
|
||||
}
|
||||
m.invoke(plugin, project) as TaskResult
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
|
11
src/main/kotlin/com/beust/kobalt/internal/DocUrl.kt
Normal file
11
src/main/kotlin/com/beust/kobalt/internal/DocUrl.kt
Normal file
|
@ -0,0 +1,11 @@
|
|||
package com.beust.kobalt.internal
|
||||
|
||||
class DocUrl {
|
||||
companion object {
|
||||
private const val HOST = "http://beust.com/kobalt/"
|
||||
private fun url(path: String) = HOST + path
|
||||
|
||||
val PUBLISH_PLUGIN_URL = url("plug-ins/index.html#publishing")
|
||||
}
|
||||
}
|
||||
|
|
@ -1,10 +1,13 @@
|
|||
package com.beust.kobalt.internal
|
||||
|
||||
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.*
|
||||
import com.beust.kobalt.misc.toString
|
||||
import com.google.common.collect.HashMultimap
|
||||
import java.lang.reflect.InvocationTargetException
|
||||
import java.util.concurrent.*
|
||||
|
||||
open class TaskResult2<T>(success: Boolean, val value: T) : TaskResult(success) {
|
||||
|
@ -73,8 +76,13 @@ public class DynamicGraphExecutor<T>(val graph: DynamicGraph<T>,
|
|||
} catch(ex: TimeoutException) {
|
||||
log(2, "Time out")
|
||||
} catch(ex: Exception) {
|
||||
error("Error: ${ex.message}", ex)
|
||||
gotError = true
|
||||
if (ex.cause is InvocationTargetException
|
||||
&& (ex.cause as InvocationTargetException).targetException is KobaltException) {
|
||||
throw (ex.cause as InvocationTargetException).targetException
|
||||
} else {
|
||||
error("Error: ${ex.message}", ex)
|
||||
gotError = true
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,12 +1,12 @@
|
|||
package com.beust.kobalt.internal
|
||||
|
||||
import com.beust.kobalt.KobaltException
|
||||
import com.beust.kobalt.TaskResult
|
||||
import com.beust.kobalt.api.IClasspathContributor
|
||||
import com.beust.kobalt.api.KobaltContext
|
||||
import com.beust.kobalt.api.Project
|
||||
import com.beust.kobalt.maven.DependencyManager
|
||||
import com.beust.kobalt.maven.IClasspathDependency
|
||||
import com.beust.kobalt.maven.KobaltException
|
||||
import com.google.inject.Inject
|
||||
import java.io.File
|
||||
import java.util.*
|
||||
|
|
|
@ -1,12 +1,8 @@
|
|||
package com.beust.kobalt.internal
|
||||
|
||||
import com.beust.kobalt.Args
|
||||
import com.beust.kobalt.AsciiArt
|
||||
import com.beust.kobalt.Plugins
|
||||
import com.beust.kobalt.TaskResult
|
||||
import com.beust.kobalt.*
|
||||
import com.beust.kobalt.api.PluginTask
|
||||
import com.beust.kobalt.api.Project
|
||||
import com.beust.kobalt.maven.KobaltException
|
||||
import com.beust.kobalt.misc.log
|
||||
import com.google.common.collect.TreeMultimap
|
||||
import java.util.*
|
||||
|
|
|
@ -1,13 +1,13 @@
|
|||
package com.beust.kobalt.kotlin
|
||||
|
||||
import com.beust.kobalt.Args
|
||||
import com.beust.kobalt.KobaltException
|
||||
import com.beust.kobalt.Plugins
|
||||
import com.beust.kobalt.api.*
|
||||
import com.beust.kobalt.api.annotation.Task
|
||||
import com.beust.kobalt.internal.JvmCompiler
|
||||
import com.beust.kobalt.internal.PluginInfo
|
||||
import com.beust.kobalt.maven.IClasspathDependency
|
||||
import com.beust.kobalt.maven.KobaltException
|
||||
import com.beust.kobalt.misc.KFiles
|
||||
import com.beust.kobalt.misc.Topological
|
||||
import com.beust.kobalt.misc.countChar
|
||||
|
|
|
@ -1,12 +1,12 @@
|
|||
package com.beust.kobalt.maven
|
||||
|
||||
import com.beust.kobalt.KobaltException
|
||||
import com.beust.kobalt.misc.KFiles
|
||||
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.util.concurrent.Callable
|
||||
import java.util.concurrent.ExecutorService
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package com.beust.kobalt.maven
|
||||
|
||||
import com.beust.kobalt.KobaltException
|
||||
import com.beust.kobalt.misc.KobaltExecutors
|
||||
import java.util.concurrent.ExecutorService
|
||||
import javax.inject.Inject
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package com.beust.kobalt.maven
|
||||
|
||||
import com.beust.kobalt.KobaltException
|
||||
import com.beust.kobalt.misc.CountingFileRequestBody
|
||||
import com.beust.kobalt.misc.log
|
||||
import com.squareup.okhttp.*
|
||||
|
@ -84,7 +85,3 @@ public class Http {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
class KobaltException(s: String? = null, ex: Throwable? = null) : RuntimeException(s, ex) {
|
||||
constructor(ex: Throwable?) : this(null, ex)
|
||||
}
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package com.beust.kobalt.maven
|
||||
|
||||
import com.beust.kobalt.KobaltException
|
||||
import com.beust.kobalt.api.Kobalt
|
||||
import com.beust.kobalt.misc.DependencyExecutor
|
||||
import com.beust.kobalt.misc.Versions
|
||||
|
|
|
@ -1,7 +1,8 @@
|
|||
package com.beust.kobalt.misc
|
||||
|
||||
import com.beust.kobalt.KobaltException
|
||||
import com.beust.kobalt.internal.DocUrl
|
||||
import com.beust.kobalt.maven.Http
|
||||
import com.beust.kobalt.maven.KobaltException
|
||||
import com.google.gson.Gson
|
||||
import com.google.gson.JsonArray
|
||||
import com.google.gson.JsonObject
|
||||
|
@ -51,8 +52,9 @@ public class GithubApi @Inject constructor(val executors: KobaltExecutors,
|
|||
fun uploadRelease(packageName: String, tagName: String, zipFile: File) {
|
||||
log(1, "Uploading release ${zipFile.name}")
|
||||
|
||||
val username = localProperties.get(PROPERTY_USERNAME)
|
||||
val accessToken = localProperties.get(PROPERTY_ACCESS_TOKEN)
|
||||
val docUrl = DocUrl.PUBLISH_PLUGIN_URL
|
||||
val username = localProperties.get(PROPERTY_USERNAME, docUrl)
|
||||
val accessToken = localProperties.get(PROPERTY_ACCESS_TOKEN, docUrl)
|
||||
try {
|
||||
service.createRelease(username, accessToken, packageName, CreateRelease(tagName))
|
||||
.flatMap { response ->
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package com.beust.kobalt.misc
|
||||
|
||||
import com.beust.kobalt.KobaltException
|
||||
import com.beust.kobalt.api.Kobalt
|
||||
import java.text.SimpleDateFormat
|
||||
import java.util.*
|
||||
|
@ -48,9 +49,15 @@ class Logger(val dev: Boolean) {
|
|||
println(getPattern("D", "Debug ", tag, message))
|
||||
|
||||
final fun error(tag: String, message: String, e: Throwable? = null) {
|
||||
println(getPattern("***** E", "***** ERROR ", tag, message) +
|
||||
if (e != null && KobaltLogger.LOG_LEVEL > 1) " Exception: " + e.message else "")
|
||||
if (KobaltLogger.LOG_LEVEL > 0) {
|
||||
val docUrl = if (e is KobaltException && e.docUrl != null) e.docUrl else null
|
||||
val shortMessage = if (e != null) e.message else { "<unknown error>" }
|
||||
val longMessage = "*****\n***** ERROR " + shortMessage + "\n" +
|
||||
docUrl?.let { "***** Documentation: $docUrl" } +
|
||||
"\n*****"
|
||||
|
||||
println(getPattern("***** E $shortMessage " + docUrl?.let { " Documentation: $docUrl" },
|
||||
longMessage, tag, message))
|
||||
if (KobaltLogger.LOG_LEVEL > 1) {
|
||||
e?.printStackTrace()
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
package com.beust.kobalt.misc
|
||||
|
||||
import com.beust.kobalt.maven.KobaltException
|
||||
import com.beust.kobalt.KobaltException
|
||||
import com.google.inject.Singleton
|
||||
import java.nio.file.Files
|
||||
import java.nio.file.Paths
|
||||
|
@ -8,11 +8,12 @@ import java.util.*
|
|||
|
||||
@Singleton
|
||||
class LocalProperties {
|
||||
var docUrl: String? = null
|
||||
val localProperties: Properties by lazy {
|
||||
val result = Properties()
|
||||
val filePath = Paths.get("local.properties")
|
||||
if (! Files.exists(filePath)) {
|
||||
throw KobaltException("Couldn't find a local.properties file")
|
||||
throw KobaltException("Couldn't find a local.properties file", docUrl = docUrl)
|
||||
}
|
||||
|
||||
filePath.let { path ->
|
||||
|
@ -26,8 +27,10 @@ class LocalProperties {
|
|||
result
|
||||
}
|
||||
|
||||
fun get(name: String) : String {
|
||||
val result = localProperties.get(name) ?: throw KobaltException("Couldn't find $name in local.properties")
|
||||
fun get(name: String, docUrl: String? = null) : String {
|
||||
this.docUrl = docUrl
|
||||
val result = localProperties[name]
|
||||
?: throw KobaltException("Couldn't find $name in local.properties", docUrl = docUrl)
|
||||
return result as String
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,14 +1,10 @@
|
|||
package com.beust.kobalt.plugin.application
|
||||
|
||||
import com.beust.kobalt.JavaInfo
|
||||
import com.beust.kobalt.Plugins
|
||||
import com.beust.kobalt.SystemProperties
|
||||
import com.beust.kobalt.*
|
||||
import com.beust.kobalt.api.BasePlugin
|
||||
import com.beust.kobalt.api.Project
|
||||
import com.beust.kobalt.api.annotation.Directive
|
||||
import com.beust.kobalt.api.annotation.Task
|
||||
import com.beust.kobalt.TaskResult
|
||||
import com.beust.kobalt.maven.KobaltException
|
||||
import com.beust.kobalt.misc.KobaltExecutors
|
||||
import com.beust.kobalt.misc.RunCommand
|
||||
import com.beust.kobalt.plugin.packaging.PackagingPlugin
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
package com.beust.kobalt.plugin.publish
|
||||
|
||||
import com.beust.kobalt.KobaltException
|
||||
import com.beust.kobalt.api.Project
|
||||
import com.beust.kobalt.TaskResult
|
||||
import com.beust.kobalt.maven.Gpg
|
||||
import com.beust.kobalt.maven.Http
|
||||
import com.beust.kobalt.maven.KobaltException
|
||||
import com.beust.kobalt.maven.Md5
|
||||
import com.beust.kobalt.misc.KobaltExecutors
|
||||
import com.beust.kobalt.misc.error
|
||||
|
|
|
@ -1,11 +1,12 @@
|
|||
package com.beust.kobalt.plugin.publish
|
||||
|
||||
import com.beust.kobalt.TaskResult
|
||||
import com.beust.kobalt.api.BasePlugin
|
||||
import com.beust.kobalt.api.Kobalt
|
||||
import com.beust.kobalt.api.Project
|
||||
import com.beust.kobalt.api.annotation.Directive
|
||||
import com.beust.kobalt.api.annotation.Task
|
||||
import com.beust.kobalt.TaskResult
|
||||
import com.beust.kobalt.internal.DocUrl
|
||||
import com.beust.kobalt.maven.PomGenerator
|
||||
import com.beust.kobalt.misc.*
|
||||
import com.google.common.base.Preconditions
|
||||
|
@ -85,8 +86,9 @@ public class PublishPlugin @Inject constructor(val files: KFiles, val factory: P
|
|||
}
|
||||
|
||||
private fun uploadJcenter(project: Project) : TaskResult {
|
||||
val user = localProperties.get(PROPERTY_BINTRAY_USER)
|
||||
val password = localProperties.get(PROPERTY_BINTRAY_PASSWORD)
|
||||
val docUrl = DocUrl.PUBLISH_PLUGIN_URL
|
||||
val user = localProperties.get(PROPERTY_BINTRAY_USER, docUrl)
|
||||
val password = localProperties.get(PROPERTY_BINTRAY_PASSWORD, docUrl)
|
||||
|
||||
val jcenter = jcenterFactory.create(user, password)
|
||||
var success = false
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue