mirror of
https://github.com/ethauvin/kobalt.git
synced 2025-04-26 08:27:12 -07:00
JSON server.
This commit is contained in:
parent
e792680dd5
commit
05c6da10f9
2 changed files with 47 additions and 3 deletions
|
@ -1,15 +1,22 @@
|
||||||
package com.beust.kobalt.internal
|
package com.beust.kobalt.internal
|
||||||
|
|
||||||
import com.beust.kobalt.Args
|
import com.beust.kobalt.Args
|
||||||
|
import com.beust.kobalt.api.Project
|
||||||
import com.beust.kobalt.kotlin.ScriptCompiler2
|
import com.beust.kobalt.kotlin.ScriptCompiler2
|
||||||
|
import com.beust.kobalt.maven.IClasspathDependency
|
||||||
|
import com.beust.kobalt.maven.MavenDependency
|
||||||
|
import com.beust.kobalt.maven.SimpleDep
|
||||||
|
import com.beust.kobalt.misc.KobaltExecutors
|
||||||
import com.beust.kobalt.misc.log
|
import com.beust.kobalt.misc.log
|
||||||
import com.google.inject.Inject
|
import com.google.inject.Inject
|
||||||
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.util.concurrent.Executor
|
||||||
|
import java.util.concurrent.ExecutorService
|
||||||
|
|
||||||
public class KobaltServer @Inject constructor() : Runnable {
|
public class KobaltServer @Inject constructor(val executors: KobaltExecutors) : Runnable {
|
||||||
var outgoing: PrintWriter? = null
|
var outgoing: PrintWriter? = null
|
||||||
val pending = arrayListOf<ScriptCompiler2.BuildScriptInfo>()
|
val pending = arrayListOf<ScriptCompiler2.BuildScriptInfo>()
|
||||||
|
|
||||||
|
@ -39,7 +46,8 @@ public class KobaltServer @Inject constructor() : Runnable {
|
||||||
|
|
||||||
fun sendInfo(info: ScriptCompiler2.BuildScriptInfo) {
|
fun sendInfo(info: ScriptCompiler2.BuildScriptInfo) {
|
||||||
if (outgoing != null) {
|
if (outgoing != null) {
|
||||||
outgoing!!.println("Sending info with project count: " + info.projects.size())
|
val json = toJson(info, executors.miscExecutor)
|
||||||
|
outgoing!!.println(json)
|
||||||
} else {
|
} else {
|
||||||
log(1, "Queuing $info")
|
log(1, "Queuing $info")
|
||||||
synchronized(pending) {
|
synchronized(pending) {
|
||||||
|
@ -47,4 +55,40 @@ public class KobaltServer @Inject constructor() : Runnable {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
companion object {
|
||||||
|
internal fun toJson(info: ScriptCompiler2.BuildScriptInfo, executor: ExecutorService): String {
|
||||||
|
val result = "{ projects: [" +
|
||||||
|
info.projects.map { toJson(it, executor) }.join(",\n") +
|
||||||
|
"]\n}\n"
|
||||||
|
return result
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun toJson(project: Project, executor: ExecutorService): String {
|
||||||
|
var result = "{\n" +
|
||||||
|
arrayListOf(
|
||||||
|
"\"name\" : \"${project.name}\"",
|
||||||
|
toJson("dependencies", project.compileDependencies, executor),
|
||||||
|
toJson("providedDependencies", project.compileProvidedDependencies, executor),
|
||||||
|
toJson("runtimeDependencies", project.compileRuntimeDependencies, executor),
|
||||||
|
toJson("testDependencies", project.testDependencies, executor),
|
||||||
|
toJson("testProvidedDependencies", project.testProvidedDependencies, executor)
|
||||||
|
).join(",\n") +
|
||||||
|
"}\n"
|
||||||
|
return result
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun toJson(name: String, dependencies: List<IClasspathDependency>, executor: ExecutorService) : String {
|
||||||
|
return "\"$name\" : [" +
|
||||||
|
dependencies.map {
|
||||||
|
val dep = MavenDependency.create(it.id, executor)
|
||||||
|
val path = dep.jarFile.get()
|
||||||
|
"{\n" +
|
||||||
|
"\"id\" : \"${it.id}\",\n" +
|
||||||
|
"\"path\" : \"$path\"" +
|
||||||
|
"}\n"
|
||||||
|
}.join(",") +
|
||||||
|
"]"
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -25,7 +25,7 @@ open public class SimpleDep(override val groupId: String, override val artifactI
|
||||||
|
|
||||||
fun toPomFile(r: RepoFinder.RepoResult) = toFile(r.version, r.snapshotVersion, ".pom")
|
fun toPomFile(r: RepoFinder.RepoResult) = toFile(r.version, r.snapshotVersion, ".pom")
|
||||||
|
|
||||||
fun toJarFile(v: String) = toFile(v, "", ".jar")
|
fun toJarFile(v: String = version) = toFile(v, "", ".jar")
|
||||||
|
|
||||||
fun toJarFile(r: RepoFinder.RepoResult) = toFile(r.version, r.snapshotVersion, ".jar")
|
fun toJarFile(r: RepoFinder.RepoResult) = toFile(r.version, r.snapshotVersion, ".jar")
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue