mirror of
https://github.com/ethauvin/kobalt.git
synced 2025-04-26 08:27:12 -07:00
New format for command data.
This commit is contained in:
parent
0b704315d2
commit
c355f2dcdd
2 changed files with 21 additions and 6 deletions
|
@ -5,6 +5,7 @@ import com.beust.kobalt.SystemProperties
|
|||
import com.beust.kobalt.kotlin.BuildFileCompiler
|
||||
import com.beust.kobalt.mainNoExit
|
||||
import com.beust.kobalt.misc.log
|
||||
import com.google.gson.Gson
|
||||
import com.google.gson.JsonObject
|
||||
import com.google.gson.JsonParser
|
||||
import com.google.inject.Inject
|
||||
|
@ -25,12 +26,14 @@ public class KobaltClient @Inject constructor() : Runnable {
|
|||
|
||||
var done = false
|
||||
var attempts = 1
|
||||
while (attempts < 3 && ! done) {
|
||||
while (attempts < 10 && ! done) {
|
||||
try {
|
||||
val socket = Socket("localhost", portNumber)
|
||||
outgoing = PrintWriter(socket.outputStream, true)
|
||||
val testBuildfile = Paths.get(SystemProperties.homeDir, "java", "testng", "Build.kt")
|
||||
.toFile().absolutePath
|
||||
val testBuildfile2 = Paths.get(SystemProperties.homeDir, "java", "jcommander", "Build.kt")
|
||||
.toFile().absolutePath
|
||||
val c : String = "{ \"name\":\"GetDependencies\", \"buildFile\": \"$testBuildfile\"}"
|
||||
outgoing!!.println(c)
|
||||
val ins = BufferedReader(InputStreamReader(socket.inputStream))
|
||||
|
@ -40,9 +43,12 @@ public class KobaltClient @Inject constructor() : Runnable {
|
|||
val jo = JsonParser().parse(line) as JsonObject
|
||||
if (jo.has("name") && "Quit" == jo.get("name").asString) {
|
||||
log(1, "Quitting")
|
||||
outgoing!!.println("{ \"name\": \"Quit\" }")
|
||||
// outgoing!!.println("{ \"name\": \"Quit\" }")
|
||||
done = true
|
||||
} 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()
|
||||
}
|
||||
}
|
||||
|
|
|
@ -26,7 +26,7 @@ public class KobaltServer @Inject constructor(val args: Args, val executors: Kob
|
|||
override fun run() {
|
||||
val portNumber = args.port
|
||||
|
||||
log(1, "Starting on port $portNumber")
|
||||
log(1, "Listening to port $portNumber")
|
||||
var quit = false
|
||||
val serverSocket = ServerSocket(portNumber)
|
||||
while (! quit) {
|
||||
|
@ -63,6 +63,8 @@ public class KobaltServer @Inject constructor(val args: Args, val executors: Kob
|
|||
fun run(jo: JsonObject)
|
||||
}
|
||||
|
||||
class CommandData(val commandName: String, val data: String)
|
||||
|
||||
inner class PingCommand() : Command {
|
||||
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 scriptCompiler = buildFileCompilerFactory.create(listOf(buildFile))
|
||||
scriptCompiler.observable.subscribe {
|
||||
buildScriptInfo -> sendData(toJson(buildScriptInfo))
|
||||
buildScriptInfo -> if (buildScriptInfo.projects.size() > 0) {
|
||||
sendData(toJson(buildScriptInfo))
|
||||
}
|
||||
}
|
||||
scriptCompiler.compileBuildFiles(args)
|
||||
sendData("{ \"name\": \"Quit\" }")
|
||||
|
@ -87,7 +91,12 @@ public class KobaltServer @Inject constructor(val args: Args, val executors: Kob
|
|||
val testDependencies: 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 {
|
||||
val executor = executors.miscExecutor
|
||||
|
@ -107,7 +116,7 @@ public class KobaltServer @Inject constructor(val args: Args, val executors: Kob
|
|||
project.testProvidedDependencies.map { toDependencyData(it) }))
|
||||
}
|
||||
log(1, "Returning BuildScriptInfo")
|
||||
val result = Gson().toJson(GetDependenciesData(projects))
|
||||
val result = Gson().toJson(GetDependenciesData(projects).toData())
|
||||
log(2, " $result")
|
||||
return result
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue