1
0
Fork 0
mirror of https://github.com/ethauvin/kobalt.git synced 2025-04-26 16:28:12 -07:00

New format for command data.

This commit is contained in:
Cedric Beust 2015-10-20 23:06:11 -07:00
parent 0b704315d2
commit c355f2dcdd
2 changed files with 21 additions and 6 deletions

View file

@ -5,6 +5,7 @@ import com.beust.kobalt.SystemProperties
import com.beust.kobalt.kotlin.BuildFileCompiler import com.beust.kobalt.kotlin.BuildFileCompiler
import com.beust.kobalt.mainNoExit import com.beust.kobalt.mainNoExit
import com.beust.kobalt.misc.log import com.beust.kobalt.misc.log
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 com.google.inject.Inject import com.google.inject.Inject
@ -25,12 +26,14 @@ public class KobaltClient @Inject constructor() : Runnable {
var done = false var done = false
var attempts = 1 var attempts = 1
while (attempts < 3 && ! done) { while (attempts < 10 && ! done) {
try { try {
val socket = Socket("localhost", portNumber) val socket = Socket("localhost", portNumber)
outgoing = PrintWriter(socket.outputStream, true) outgoing = PrintWriter(socket.outputStream, true)
val testBuildfile = Paths.get(SystemProperties.homeDir, "java", "testng", "Build.kt") val testBuildfile = Paths.get(SystemProperties.homeDir, "java", "testng", "Build.kt")
.toFile().absolutePath .toFile().absolutePath
val testBuildfile2 = Paths.get(SystemProperties.homeDir, "java", "jcommander", "Build.kt")
.toFile().absolutePath
val c : String = "{ \"name\":\"GetDependencies\", \"buildFile\": \"$testBuildfile\"}" val c : String = "{ \"name\":\"GetDependencies\", \"buildFile\": \"$testBuildfile\"}"
outgoing!!.println(c) outgoing!!.println(c)
val ins = BufferedReader(InputStreamReader(socket.inputStream)) val ins = BufferedReader(InputStreamReader(socket.inputStream))
@ -40,9 +43,12 @@ public class KobaltClient @Inject constructor() : Runnable {
val jo = JsonParser().parse(line) as JsonObject val jo = JsonParser().parse(line) as JsonObject
if (jo.has("name") && "Quit" == jo.get("name").asString) { if (jo.has("name") && "Quit" == jo.get("name").asString) {
log(1, "Quitting") log(1, "Quitting")
outgoing!!.println("{ \"name\": \"Quit\" }") // outgoing!!.println("{ \"name\": \"Quit\" }")
done = true done = true
} else { } else {
val data = jo.get("data").asString
val dd = Gson().fromJson(data, KobaltServer.GetDependenciesData::class.java)
println("Read GetDependencyData, project count: ${dd.projects.size()}")
line = ins.readLine() line = ins.readLine()
} }
} }

View file

@ -26,7 +26,7 @@ public class KobaltServer @Inject constructor(val args: Args, val executors: Kob
override fun run() { override fun run() {
val portNumber = args.port val portNumber = args.port
log(1, "Starting on port $portNumber") log(1, "Listening to port $portNumber")
var quit = false var quit = false
val serverSocket = ServerSocket(portNumber) val serverSocket = ServerSocket(portNumber)
while (! quit) { while (! quit) {
@ -63,6 +63,8 @@ public class KobaltServer @Inject constructor(val args: Args, val executors: Kob
fun run(jo: JsonObject) fun run(jo: JsonObject)
} }
class CommandData(val commandName: String, val data: String)
inner class PingCommand() : Command { inner class PingCommand() : Command {
override fun run(jo: JsonObject) = sendData("{ \"response\" : \"${jo.toString()}\" }") override fun run(jo: JsonObject) = sendData("{ \"response\" : \"${jo.toString()}\" }")
} }
@ -72,7 +74,9 @@ public class KobaltServer @Inject constructor(val args: Args, val executors: Kob
val buildFile = BuildFile(Paths.get(jo.get("buildFile").asString), "GetDependenciesCommand") val buildFile = BuildFile(Paths.get(jo.get("buildFile").asString), "GetDependenciesCommand")
val scriptCompiler = buildFileCompilerFactory.create(listOf(buildFile)) val scriptCompiler = buildFileCompilerFactory.create(listOf(buildFile))
scriptCompiler.observable.subscribe { scriptCompiler.observable.subscribe {
buildScriptInfo -> sendData(toJson(buildScriptInfo)) buildScriptInfo -> if (buildScriptInfo.projects.size() > 0) {
sendData(toJson(buildScriptInfo))
}
} }
scriptCompiler.compileBuildFiles(args) scriptCompiler.compileBuildFiles(args)
sendData("{ \"name\": \"Quit\" }") sendData("{ \"name\": \"Quit\" }")
@ -87,7 +91,12 @@ public class KobaltServer @Inject constructor(val args: Args, val executors: Kob
val testDependencies: List<DependencyData>, val testDependencies: List<DependencyData>,
val testProvidedDependencies: List<DependencyData>) val testProvidedDependencies: List<DependencyData>)
class GetDependenciesData(val projects: List<ProjectData>) class GetDependenciesData(val projects: List<ProjectData>) {
fun toData() : CommandData {
val data = Gson().toJson(this)
return CommandData("GetDependencies", data)
}
}
private fun toJson(info: BuildFileCompiler.BuildScriptInfo) : String { private fun toJson(info: BuildFileCompiler.BuildScriptInfo) : String {
val executor = executors.miscExecutor val executor = executors.miscExecutor
@ -107,7 +116,7 @@ public class KobaltServer @Inject constructor(val args: Args, val executors: Kob
project.testProvidedDependencies.map { toDependencyData(it) })) project.testProvidedDependencies.map { toDependencyData(it) }))
} }
log(1, "Returning BuildScriptInfo") log(1, "Returning BuildScriptInfo")
val result = Gson().toJson(GetDependenciesData(projects)) val result = Gson().toJson(GetDependenciesData(projects).toData())
log(2, " $result") log(2, " $result")
return result return result
} }