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

Make --server work even if there is no Build.kt.

Fixes https://github.com/cbeust/kobalt-intellij-plugin/issues/69.
This commit is contained in:
Cedric Beust 2017-03-25 07:14:10 -07:00
parent 4e4c5a7d9e
commit 8a8b5f638d
3 changed files with 5 additions and 16 deletions

View file

@ -152,6 +152,9 @@ private class Main @Inject constructor(
} else if (args.update) {
// --update
updateKobalt.updateKobalt()
} else if (args.serverMode) {
// --server
val port = serverFactory.create(args.force, args.port, { cleanUp() }).call()
} else {
//
// Everything below requires to parse the build file first
@ -165,13 +168,6 @@ private class Main @Inject constructor(
if (args.listTemplates) {
// --listTemplates
Templates().displayTemplates(pluginInfo)
} else if (args.serverMode) {
// --server
val port = serverFactory.create(args.force, args.port,
{ buildFile -> projectFinder.initForBuildFile(BuildFile(Paths.get(buildFile),
buildFile), args) },
{ cleanUp() })
.call()
} else if (args.projectInfo) {
// --projectInfo
allProjects.forEach {

View file

@ -26,13 +26,11 @@ import javax.annotation.Nullable
* To enable websocket debugging, uncomment the "debug" <root> tag in logback.xml.
*/
class KobaltServer @Inject constructor(@Assisted val force: Boolean, @Assisted @Nullable val givenPort: Int?,
@Assisted val initCallback: (String) -> List<Project>,
@Assisted val cleanUpCallback: () -> Unit,
val pluginInfo : PluginInfo) : Callable<Int> {
interface IFactory {
fun create(force: Boolean, givenPort: Int? = null,
initCallback: (String) -> List<Project>,
cleanUpCallback: () -> Unit) : KobaltServer
}
@ -78,7 +76,7 @@ class KobaltServer @Inject constructor(@Assisted val force: Boolean, @Assisted @
kobaltLog(1, "KobaltServer listening on port $port")
// OldServer(initCallback, cleanUpCallback).run(port)
// JerseyServer(initCallback, cleanUpCallback).run(port)
SparkServer(initCallback, cleanUpCallback, pluginInfo).run(port)
SparkServer(cleanUpCallback, pluginInfo).run(port)
// WasabiServer(initCallback, cleanUpCallback).run(port)
}
} catch(ex: Exception) {

View file

@ -3,7 +3,6 @@ package com.beust.kobalt.app.remote
import com.beust.kobalt.Args
import com.beust.kobalt.api.ITemplate
import com.beust.kobalt.api.Kobalt
import com.beust.kobalt.api.Project
import com.beust.kobalt.app.ProjectFinder
import com.beust.kobalt.app.Templates
import com.beust.kobalt.internal.PluginInfo
@ -23,16 +22,13 @@ import spark.Spark
import java.nio.file.Paths
import java.util.concurrent.Executors
class SparkServer(val initCallback: (String) -> List<Project>, val cleanUpCallback: () -> Unit,
val pluginInfo : PluginInfo) : KobaltServer.IServer {
class SparkServer(val cleanUpCallback: () -> Unit, val pluginInfo : PluginInfo) : KobaltServer.IServer {
companion object {
lateinit var initCallback: (String) -> List<Project>
lateinit var cleanUpCallback: () -> Unit
}
init {
SparkServer.initCallback = initCallback
SparkServer.cleanUpCallback = cleanUpCallback
}
@ -72,7 +68,6 @@ class SparkServer(val initCallback: (String) -> List<Project>, val cleanUpCallba
// (replaced by /v1 which uses WebSockets
jsonRoute("/v0/getDependencies", Route { request, response ->
val buildFile = request.queryParams("buildFile")
initCallback(buildFile)
val result =
if (buildFile != null) {
try {