diff --git a/src/main/kotlin/com/beust/kobalt/Main.kt b/src/main/kotlin/com/beust/kobalt/Main.kt index b0710cc6..a67adc42 100644 --- a/src/main/kotlin/com/beust/kobalt/Main.kt +++ b/src/main/kotlin/com/beust/kobalt/Main.kt @@ -120,13 +120,14 @@ private class Main @Inject constructor( try { allProjects = buildFileCompilerFactory.create(listOf(buildFile)).compileBuildFiles(args) } catch(ex: Throwable) { + error("Couldn't build", ex) log(2, "Couldn't parse preBuildScript.jar: ${ex.message}") - if (! File(".kobalt").deleteRecursively()) { - warn("Couldn't delete .kobalt, please delete it manually") - } else { - log(1, "Deleted .kobalt") - allProjects = buildFileCompilerFactory.create(listOf(buildFile)).compileBuildFiles(args) - } +// if (! File(".kobalt").deleteRecursively()) { +// warn("Couldn't delete .kobalt, please delete it manually") +// } else { +// log(1, "Deleted .kobalt") +// allProjects = buildFileCompilerFactory.create(listOf(buildFile)).compileBuildFiles(args) +// } } if (args.tasks) { diff --git a/src/main/kotlin/com/beust/kobalt/internal/remote/KobaltServer.kt b/src/main/kotlin/com/beust/kobalt/internal/remote/KobaltServer.kt index 93f8cc8a..fb215ea5 100644 --- a/src/main/kotlin/com/beust/kobalt/internal/remote/KobaltServer.kt +++ b/src/main/kotlin/com/beust/kobalt/internal/remote/KobaltServer.kt @@ -6,13 +6,13 @@ import com.beust.kobalt.misc.log import com.google.gson.Gson import com.google.gson.JsonObject import com.google.gson.JsonParser -import javax.inject.Inject import com.google.inject.Singleton import java.io.BufferedReader import java.io.InputStreamReader import java.io.PrintWriter import java.net.ServerSocket import java.net.SocketException +import javax.inject.Inject /** * All commands implement this interface. @@ -51,7 +51,7 @@ interface ICommandSender { * it into a Kotlin *Data class. The downside of this approach is a double parsing, * but since the data part is parsed as a string first, this is probably not a huge deal. */ -class CommandData(val name: String, val data: String) +class CommandData(val name: String, val data: String?, val error: String? = null) @Singleton public class KobaltServer @Inject constructor(val args: Args) : Runnable, ICommandSender { @@ -69,7 +69,7 @@ public class KobaltServer @Inject constructor(val args: Args) : Runnable, IComma log(1, "Listening to port $portNumber") var quit = false val serverSocket = ServerSocket(portNumber) - val clientSocket = serverSocket.accept() + var clientSocket = serverSocket.accept() while (!quit) { outgoing = PrintWriter(clientSocket.outputStream, true) if (pending.size > 0) { @@ -80,12 +80,14 @@ public class KobaltServer @Inject constructor(val args: Args) : Runnable, IComma } } val ins = BufferedReader(InputStreamReader(clientSocket.inputStream)) + var commandName: String? = null try { var line = ins.readLine() while (!quit && line != null) { log(1, "Received from client $line") val jo = JsonParser().parse(line) as JsonObject - if ("quit" == jo.get("name").asString) { + commandName = jo.get("name").asString + if ("quit" == commandName) { log(1, "Quitting") quit = true } else { @@ -99,7 +101,10 @@ public class KobaltServer @Inject constructor(val args: Args) : Runnable, IComma } } catch(ex: SocketException) { log(1, "Client disconnected, resetting") - } catch(ex: Exception) { + clientSocket = serverSocket.accept() + } catch(ex: Throwable) { + ex.printStackTrace() + sendData(CommandData(commandName!!, null, ex.message)) log(1, "Command failed: ${ex.message}") } } diff --git a/src/main/kotlin/com/beust/kobalt/kotlin/BuildFileCompiler.kt b/src/main/kotlin/com/beust/kobalt/kotlin/BuildFileCompiler.kt index 35a4976b..a9e116cd 100644 --- a/src/main/kotlin/com/beust/kobalt/kotlin/BuildFileCompiler.kt +++ b/src/main/kotlin/com/beust/kobalt/kotlin/BuildFileCompiler.kt @@ -199,10 +199,14 @@ public class BuildFileCompiler @Inject constructor(@Assisted("buildFiles") val b cls.methods.forEach { method -> // Invoke vals and see if they return a Project if (method.name.startsWith("get") && Modifier.isStatic(method.modifiers)) { - val r = method.invoke(null) - if (r is Project) { - log(2, "Found project $r in class $cls") - projects.add(r) + try { + val r = method.invoke(null) + if (r is Project) { + log(2, "Found project $r in class $cls") + projects.add(r) + } + } catch(ex: Throwable) { + throw ex.cause ?: KobaltException(ex) } } else { val taskAnnotation = method.getAnnotation(Task::class.java)