mirror of
https://github.com/ethauvin/kobalt.git
synced 2025-04-26 08:27:12 -07:00
Better types.
This commit is contained in:
parent
683afdb569
commit
66aeb19929
3 changed files with 10 additions and 12 deletions
|
@ -35,7 +35,7 @@ class GetDependenciesCommand @Inject constructor(val executors: KobaltExecutors,
|
||||||
scriptCompiler.compileBuildFiles(args)
|
scriptCompiler.compileBuildFiles(args)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun toJson(info: BuildFileCompiler.BuildScriptInfo) : String {
|
private fun toJson(info: BuildFileCompiler.BuildScriptInfo) : CommandData {
|
||||||
val executor = executors.miscExecutor
|
val executor = executors.miscExecutor
|
||||||
val projects = arrayListOf<ProjectData>()
|
val projects = arrayListOf<ProjectData>()
|
||||||
|
|
||||||
|
@ -55,7 +55,7 @@ class GetDependenciesCommand @Inject constructor(val executors: KobaltExecutors,
|
||||||
projects.add(ProjectData(project.name!!, allDependencies))
|
projects.add(ProjectData(project.name!!, allDependencies))
|
||||||
}
|
}
|
||||||
log(1, "Returning BuildScriptInfo")
|
log(1, "Returning BuildScriptInfo")
|
||||||
val result = toCommandDataJson(Gson().toJson(GetDependenciesData(projects)))
|
val result = toCommandData(Gson().toJson(GetDependenciesData(projects)))
|
||||||
log(2, " $result")
|
log(2, " $result")
|
||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
|
|
|
@ -29,7 +29,7 @@ interface ICommand {
|
||||||
*/
|
*/
|
||||||
fun run(sender: ICommandSender, received: JsonObject)
|
fun run(sender: ICommandSender, received: JsonObject)
|
||||||
|
|
||||||
fun toCommandDataJson(data: String) = Gson().toJson(CommandData(name, data))
|
fun toCommandData(data: String) = CommandData(name, data)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -37,7 +37,7 @@ interface ICommand {
|
||||||
* @param The string content that will be sent in the "data" field.
|
* @param The string content that will be sent in the "data" field.
|
||||||
*/
|
*/
|
||||||
interface ICommandSender {
|
interface ICommandSender {
|
||||||
fun sendData(data: String)
|
fun sendData(commandData: CommandData)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -56,7 +56,7 @@ class CommandData(val commandName: String, val data: String)
|
||||||
@Singleton
|
@Singleton
|
||||||
public class KobaltServer @Inject constructor(val args: Args) : Runnable, ICommandSender {
|
public class KobaltServer @Inject constructor(val args: Args) : Runnable, ICommandSender {
|
||||||
var outgoing: PrintWriter? = null
|
var outgoing: PrintWriter? = null
|
||||||
val pending = arrayListOf<String>()
|
val pending = arrayListOf<CommandData>()
|
||||||
|
|
||||||
private val COMMAND_CLASSES = listOf(GetDependenciesCommand::class.java, PingCommand::class.java)
|
private val COMMAND_CLASSES = listOf(GetDependenciesCommand::class.java, PingCommand::class.java)
|
||||||
private val COMMANDS = COMMAND_CLASSES.map {
|
private val COMMANDS = COMMAND_CLASSES.map {
|
||||||
|
@ -92,7 +92,7 @@ public class KobaltServer @Inject constructor(val args: Args) : Runnable, IComma
|
||||||
runCommand(jo)
|
runCommand(jo)
|
||||||
|
|
||||||
// Done, send a quit to the client
|
// Done, send a quit to the client
|
||||||
sendData("{ \"name\": \"quit\" }")
|
sendData(CommandData("quit", ""))
|
||||||
|
|
||||||
line = ins.readLine()
|
line = ins.readLine()
|
||||||
}
|
}
|
||||||
|
@ -112,13 +112,14 @@ public class KobaltServer @Inject constructor(val args: Args) : Runnable, IComma
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun sendData(content: String) {
|
override fun sendData(commandData: CommandData) {
|
||||||
|
val content = Gson().toJson(commandData)
|
||||||
if (outgoing != null) {
|
if (outgoing != null) {
|
||||||
outgoing!!.println(content)
|
outgoing!!.println(content)
|
||||||
} else {
|
} else {
|
||||||
log1("Queuing $content")
|
log1("Queuing $content")
|
||||||
synchronized(pending) {
|
synchronized(pending) {
|
||||||
pending.add(content)
|
pending.add(commandData)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,10 +16,7 @@ class PingCommand() : ICommand {
|
||||||
override val name = "ping"
|
override val name = "ping"
|
||||||
|
|
||||||
override fun run(sender: ICommandSender, received: JsonObject) {
|
override fun run(sender: ICommandSender, received: JsonObject) {
|
||||||
val commandData = toCommandDataJson(Gson().toJson(PingData(received.toString())))
|
sender.sendData(toCommandData(Gson().toJson(PingData(received.toString()))))
|
||||||
val result = Gson().toJson(commandData)
|
|
||||||
log(1, "ping returning: $result")
|
|
||||||
sender.sendData(result)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
class PingData(val received: String)
|
class PingData(val received: String)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue