mirror of
https://github.com/ethauvin/kobalt.git
synced 2025-04-26 16:28:12 -07:00
Handle errors better in KobaltServer.
This commit is contained in:
parent
00722cc637
commit
d26ae330a7
3 changed files with 25 additions and 15 deletions
|
@ -120,13 +120,14 @@ private class Main @Inject constructor(
|
||||||
try {
|
try {
|
||||||
allProjects = buildFileCompilerFactory.create(listOf(buildFile)).compileBuildFiles(args)
|
allProjects = buildFileCompilerFactory.create(listOf(buildFile)).compileBuildFiles(args)
|
||||||
} catch(ex: Throwable) {
|
} catch(ex: Throwable) {
|
||||||
|
error("Couldn't build", ex)
|
||||||
log(2, "Couldn't parse preBuildScript.jar: ${ex.message}")
|
log(2, "Couldn't parse preBuildScript.jar: ${ex.message}")
|
||||||
if (! File(".kobalt").deleteRecursively()) {
|
// if (! File(".kobalt").deleteRecursively()) {
|
||||||
warn("Couldn't delete .kobalt, please delete it manually")
|
// warn("Couldn't delete .kobalt, please delete it manually")
|
||||||
} else {
|
// } else {
|
||||||
log(1, "Deleted .kobalt")
|
// log(1, "Deleted .kobalt")
|
||||||
allProjects = buildFileCompilerFactory.create(listOf(buildFile)).compileBuildFiles(args)
|
// allProjects = buildFileCompilerFactory.create(listOf(buildFile)).compileBuildFiles(args)
|
||||||
}
|
// }
|
||||||
}
|
}
|
||||||
|
|
||||||
if (args.tasks) {
|
if (args.tasks) {
|
||||||
|
|
|
@ -6,13 +6,13 @@ import com.beust.kobalt.misc.log
|
||||||
import com.google.gson.Gson
|
import com.google.gson.Gson
|
||||||
import com.google.gson.JsonObject
|
import com.google.gson.JsonObject
|
||||||
import com.google.gson.JsonParser
|
import com.google.gson.JsonParser
|
||||||
import javax.inject.Inject
|
|
||||||
import com.google.inject.Singleton
|
import com.google.inject.Singleton
|
||||||
import java.io.BufferedReader
|
import java.io.BufferedReader
|
||||||
import java.io.InputStreamReader
|
import java.io.InputStreamReader
|
||||||
import java.io.PrintWriter
|
import java.io.PrintWriter
|
||||||
import java.net.ServerSocket
|
import java.net.ServerSocket
|
||||||
import java.net.SocketException
|
import java.net.SocketException
|
||||||
|
import javax.inject.Inject
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* All commands implement this interface.
|
* 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,
|
* 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.
|
* 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
|
@Singleton
|
||||||
public class KobaltServer @Inject constructor(val args: Args) : Runnable, ICommandSender {
|
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")
|
log(1, "Listening to port $portNumber")
|
||||||
var quit = false
|
var quit = false
|
||||||
val serverSocket = ServerSocket(portNumber)
|
val serverSocket = ServerSocket(portNumber)
|
||||||
val clientSocket = serverSocket.accept()
|
var clientSocket = serverSocket.accept()
|
||||||
while (!quit) {
|
while (!quit) {
|
||||||
outgoing = PrintWriter(clientSocket.outputStream, true)
|
outgoing = PrintWriter(clientSocket.outputStream, true)
|
||||||
if (pending.size > 0) {
|
if (pending.size > 0) {
|
||||||
|
@ -80,12 +80,14 @@ public class KobaltServer @Inject constructor(val args: Args) : Runnable, IComma
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
val ins = BufferedReader(InputStreamReader(clientSocket.inputStream))
|
val ins = BufferedReader(InputStreamReader(clientSocket.inputStream))
|
||||||
|
var commandName: String? = null
|
||||||
try {
|
try {
|
||||||
var line = ins.readLine()
|
var line = ins.readLine()
|
||||||
while (!quit && line != null) {
|
while (!quit && line != null) {
|
||||||
log(1, "Received from client $line")
|
log(1, "Received from client $line")
|
||||||
val jo = JsonParser().parse(line) as JsonObject
|
val jo = JsonParser().parse(line) as JsonObject
|
||||||
if ("quit" == jo.get("name").asString) {
|
commandName = jo.get("name").asString
|
||||||
|
if ("quit" == commandName) {
|
||||||
log(1, "Quitting")
|
log(1, "Quitting")
|
||||||
quit = true
|
quit = true
|
||||||
} else {
|
} else {
|
||||||
|
@ -99,7 +101,10 @@ public class KobaltServer @Inject constructor(val args: Args) : Runnable, IComma
|
||||||
}
|
}
|
||||||
} catch(ex: SocketException) {
|
} catch(ex: SocketException) {
|
||||||
log(1, "Client disconnected, resetting")
|
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}")
|
log(1, "Command failed: ${ex.message}")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -199,10 +199,14 @@ public class BuildFileCompiler @Inject constructor(@Assisted("buildFiles") val b
|
||||||
cls.methods.forEach { method ->
|
cls.methods.forEach { method ->
|
||||||
// Invoke vals and see if they return a Project
|
// Invoke vals and see if they return a Project
|
||||||
if (method.name.startsWith("get") && Modifier.isStatic(method.modifiers)) {
|
if (method.name.startsWith("get") && Modifier.isStatic(method.modifiers)) {
|
||||||
val r = method.invoke(null)
|
try {
|
||||||
if (r is Project) {
|
val r = method.invoke(null)
|
||||||
log(2, "Found project $r in class $cls")
|
if (r is Project) {
|
||||||
projects.add(r)
|
log(2, "Found project $r in class $cls")
|
||||||
|
projects.add(r)
|
||||||
|
}
|
||||||
|
} catch(ex: Throwable) {
|
||||||
|
throw ex.cause ?: KobaltException(ex)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
val taskAnnotation = method.getAnnotation(Task::class.java)
|
val taskAnnotation = method.getAnnotation(Task::class.java)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue