mirror of
https://github.com/ethauvin/kobalt.git
synced 2025-04-24 23:47:11 -07:00
Better JSON.
This commit is contained in:
parent
3539e67c1a
commit
9b206d4dc5
4 changed files with 35 additions and 49 deletions
|
@ -49,7 +49,8 @@ dependencies {
|
|||
'com.google.guava:guava:18.0',
|
||||
'org.apache.maven:maven-model:3.3.3',
|
||||
'com.github.spullara.mustache.java:compiler:0.8.18',
|
||||
"io.reactivex:rxjava:1.0.14"
|
||||
"io.reactivex:rxjava:1.0.14",
|
||||
"com.google.code.gson:gson:2.4"
|
||||
|
||||
// compile files("/Users/beust/.kobalt/repository/com/beust/kobalt-example-plugin/build/libs/kobalt-example-plugin.jar")
|
||||
testCompile 'org.testng:testng:6.9.6'
|
||||
|
|
|
@ -41,5 +41,6 @@
|
|||
<orderEntry type="library" scope="TEST" name="Gradle: org.apache.ant:ant-launcher:1.7.0" level="project" />
|
||||
<orderEntry type="library" scope="TEST" name="Gradle: org.hamcrest:hamcrest-core:1.1" level="project" />
|
||||
<orderEntry type="library" name="Gradle: io.reactivex:rxjava:1.0.14" level="project" />
|
||||
<orderEntry type="library" name="Gradle: com.google.code.gson:gson:2.4" level="project" />
|
||||
</component>
|
||||
</module>
|
|
@ -60,14 +60,14 @@ val kobalt = kotlinProject(wrapper) {
|
|||
"com.beust:jcommander:1.48",
|
||||
"com.beust:klaxon:0.16",
|
||||
"com.squareup.okhttp:okhttp:2.5.0",
|
||||
"org.slf4j:slf4j-api:1.7.12",
|
||||
"org.jsoup:jsoup:1.8.3",
|
||||
"com.google.inject:guice:4.0",
|
||||
"com.google.inject.extensions:guice-assistedinject:4.0",
|
||||
"com.google.guava:guava:19.0-rc2",
|
||||
"org.apache.maven:maven-model:3.3.3",
|
||||
"com.github.spullara.mustache.java:compiler:0.9.1",
|
||||
"io.reactivex:rxjava:1.0.14"
|
||||
"io.reactivex:rxjava:1.0.14",
|
||||
"com.google.code.gson:gson:2.4"
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,24 +1,19 @@
|
|||
package com.beust.kobalt.internal
|
||||
|
||||
import com.beust.klaxon.json
|
||||
import com.beust.kobalt.Args
|
||||
import com.beust.kobalt.api.Project
|
||||
import com.beust.kobalt.kotlin.BuildFile
|
||||
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.google.gson.Gson
|
||||
import com.google.inject.Inject
|
||||
import com.google.inject.assistedinject.Assisted
|
||||
import java.io.BufferedReader
|
||||
import java.io.InputStreamReader
|
||||
import java.io.PrintWriter
|
||||
import java.net.ServerSocket
|
||||
import java.nio.file.Paths
|
||||
import java.util.concurrent.Executor
|
||||
import java.util.concurrent.ExecutorService
|
||||
|
||||
public class KobaltServer @Inject constructor(val args: Args, val executors: KobaltExecutors,
|
||||
val buildFileCompilerFactory: ScriptCompiler2.IFactory) : Runnable {
|
||||
|
@ -44,9 +39,7 @@ public class KobaltServer @Inject constructor(val args: Args, val executors: Kob
|
|||
while (inputLine != null) {
|
||||
log(1, "Received $inputLine")
|
||||
val command = getCommand(inputLine)
|
||||
if (command != null) {
|
||||
command!!.run()
|
||||
}
|
||||
command?.run()
|
||||
if (inputLine.equals("Bye."))
|
||||
break;
|
||||
inputLine = ins.readLine()
|
||||
|
@ -72,9 +65,36 @@ public class KobaltServer @Inject constructor(val args: Args, val executors: Kob
|
|||
}
|
||||
}
|
||||
|
||||
class DependencyData(val id: String, val path: String)
|
||||
|
||||
class ProjectData( val name: String, val dependencies: List<DependencyData>,
|
||||
val providedDependencies: List<DependencyData>,
|
||||
val runtimeDependencies: List<DependencyData>,
|
||||
val testDependencies: List<DependencyData>,
|
||||
val testProvidedDependencies: List<DependencyData>)
|
||||
|
||||
class GetDependenciesData(val projects: List<ProjectData>)
|
||||
|
||||
private fun toJson(info: ScriptCompiler2.BuildScriptInfo) : String {
|
||||
val executor = executors.miscExecutor
|
||||
val projects = arrayListOf<ProjectData>()
|
||||
|
||||
fun toDependencyData(d: IClasspathDependency) : DependencyData {
|
||||
val dep = MavenDependency.create(d.id, executor)
|
||||
return DependencyData(d.id, dep.jarFile.get().absolutePath)
|
||||
}
|
||||
|
||||
info.projects.forEach { project ->
|
||||
projects.add(ProjectData(project.name!!,
|
||||
project.compileDependencies.map { toDependencyData(it) },
|
||||
project.compileProvidedDependencies.map { toDependencyData(it) },
|
||||
project.compileRuntimeDependencies.map { toDependencyData(it) },
|
||||
project.testDependencies.map { toDependencyData(it) },
|
||||
project.testProvidedDependencies.map { toDependencyData(it) }))
|
||||
}
|
||||
log(1, "Returning JSON for BuildScriptInfo")
|
||||
return toJson(info, executors.miscExecutor)
|
||||
val result = Gson().toJson(GetDependenciesData(projects))
|
||||
return result
|
||||
}
|
||||
|
||||
private fun getCommand(command: String): Command? {
|
||||
|
@ -96,40 +116,4 @@ public class KobaltServer @Inject constructor(val args: Args, val executors: Kob
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
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(",") +
|
||||
"]"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue