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

/v1/getDependencyGraph?projectRoot=...

Deprecated buildFile=.
This commit is contained in:
Cedric Beust 2017-03-26 07:32:56 -07:00
parent 5c7d6a20cb
commit 043fc31c9f
4 changed files with 46 additions and 27 deletions

View file

@ -386,6 +386,19 @@ class KFiles {
return false return false
} }
} }
fun findBuildFile(projectRoot: String = "."): File {
val deprecatedLocation = File(Constants.BUILD_FILE_NAME)
val result: File =
if (deprecatedLocation.exists()) {
warn(Constants.BUILD_FILE_NAME + " is in a deprecated location, please move it to "
+ Constants.BUILD_FILE_DIRECTORY)
deprecatedLocation
} else {
File(KFiles.joinDir(projectRoot, Constants.BUILD_FILE_DIRECTORY, Constants.BUILD_FILE_NAME))
}
return result
}
} }
fun findRecursively(directory: File, function: Function1<String, Boolean>): List<String> { fun findRecursively(directory: File, function: Function1<String, Boolean>): List<String> {

View file

@ -126,7 +126,7 @@ private class Main @Inject constructor(
// val md5 = Md5.toMd5(file) // val md5 = Md5.toMd5(file)
// val md52 = MessageDigest.getInstance("MD5").digest(file.readBytes()).toHexString() // val md52 = MessageDigest.getInstance("MD5").digest(file.readBytes()).toHexString()
var result = 0 var result = 0
val p = if (args.buildFile != null) File(args.buildFile) else findBuildFile() val p = if (args.buildFile != null) File(args.buildFile) else KFiles.findBuildFile()
args.buildFile = p.absolutePath args.buildFile = p.absolutePath
val buildFile = BuildFile(Paths.get(p.absolutePath), p.name) val buildFile = BuildFile(Paths.get(p.absolutePath), p.name)
@ -219,19 +219,6 @@ private class Main @Inject constructor(
} }
} }
private fun findBuildFile(): File {
val deprecatedLocation = File(Constants.BUILD_FILE_NAME)
val result: File =
if (deprecatedLocation.exists()) {
warn(Constants.BUILD_FILE_NAME + " is in a deprecated location, please move it to "
+ Constants.BUILD_FILE_DIRECTORY)
deprecatedLocation
} else {
File(KFiles.joinDir(Constants.BUILD_FILE_DIRECTORY, Constants.BUILD_FILE_NAME))
}
return result
}
private fun cleanUp() { private fun cleanUp() {
pluginInfo.cleanUp() pluginInfo.cleanUp()
taskManager.cleanUp() taskManager.cleanUp()

View file

@ -6,6 +6,7 @@ import com.beust.kobalt.app.ProjectFinder
import com.beust.kobalt.internal.build.BuildFile import com.beust.kobalt.internal.build.BuildFile
import com.beust.kobalt.internal.eventbus.ArtifactDownloadedEvent import com.beust.kobalt.internal.eventbus.ArtifactDownloadedEvent
import com.beust.kobalt.maven.aether.Exceptions import com.beust.kobalt.maven.aether.Exceptions
import com.beust.kobalt.misc.KFiles
import com.google.common.eventbus.EventBus import com.google.common.eventbus.EventBus
import com.google.common.eventbus.Subscribe import com.google.common.eventbus.Subscribe
import com.google.gson.Gson import com.google.gson.Gson
@ -22,6 +23,9 @@ class GetDependencyGraphHandler : WebSocketListener {
// so I have to do dependency injections manually :-( // so I have to do dependency injections manually :-(
val projectFinder = Kobalt.INJECTOR.getInstance(ProjectFinder::class.java) val projectFinder = Kobalt.INJECTOR.getInstance(ProjectFinder::class.java)
val PARAMETER_PROJECT_ROOT = "projectRoot"
val PARAMETER_BUILD_FILE = "buildFile"
var session: Session? = null var session: Session? = null
override fun onWebSocketClose(code: Int, reason: String?) { override fun onWebSocketClose(code: Int, reason: String?) {
@ -39,15 +43,29 @@ class GetDependencyGraphHandler : WebSocketListener {
errorMessage = errorMessage))) errorMessage = errorMessage)))
} }
private fun findBuildFile(map: Map<String, List<String>>) : String? {
val projectRoot = map[PARAMETER_PROJECT_ROOT]
val buildFile = map[PARAMETER_BUILD_FILE]
val result =
if (projectRoot != null) {
KFiles.findBuildFile(projectRoot[0]).absolutePath
} else if (buildFile != null) {
buildFile[0]
} else {
null
}
return result
}
override fun onWebSocketConnect(s: Session) { override fun onWebSocketConnect(s: Session) {
session = s session = s
val buildFileParams = s.upgradeRequest.parameterMap["buildFile"] val buildFile = findBuildFile(s.upgradeRequest.parameterMap)
if (buildFileParams != null) {
val buildFile = buildFileParams[0]
fun <T> getInstance(cls: Class<T>) : T = Kobalt.INJECTOR.getInstance(cls) fun <T> getInstance(cls: Class<T>) : T = Kobalt.INJECTOR.getInstance(cls)
val result = if (buildFile != null) { // Parse the request
val result =
if (buildFile != null) {
// Track all the downloads that this dependency call might trigger and // Track all the downloads that this dependency call might trigger and
// send them as a progress message to the web socket // send them as a progress message to the web socket
val eventBus = getInstance(EventBus::class.java) val eventBus = getInstance(EventBus::class.java)
@ -76,8 +94,7 @@ class GetDependencyGraphHandler : WebSocketListener {
}, useGraph = true) }, useGraph = true)
} catch(ex: Throwable) { } catch(ex: Throwable) {
Exceptions.printStackTrace(ex) Exceptions.printStackTrace(ex)
val errorMessage = ex.message RemoteDependencyData.GetDependenciesData(errorMessage = ex.message)
RemoteDependencyData.GetDependenciesData(errorMessage = errorMessage)
} finally { } finally {
SparkServer.cleanUpCallback() SparkServer.cleanUpCallback()
eventBus.unregister(busListener) eventBus.unregister(busListener)
@ -86,10 +103,11 @@ class GetDependencyGraphHandler : WebSocketListener {
RemoteDependencyData.GetDependenciesData( RemoteDependencyData.GetDependenciesData(
errorMessage = "buildFile wasn't passed in the query parameter") errorMessage = "buildFile wasn't passed in the query parameter")
} }
sendWebsocketCommand(s.remote, RemoteDependencyData.GetDependenciesData.NAME, result,
errorMessage = result.errorMessage) // Respond to the request
s.close() sendWebsocketCommand(s.remote, RemoteDependencyData.GetDependenciesData.NAME, result,
} errorMessage = result.errorMessage)
s.close()
} }
override fun onWebSocketText(message: String?) { override fun onWebSocketText(message: String?) {

View file

@ -32,10 +32,11 @@ class KobaltClient : Runnable {
val client = OkHttpClient() val client = OkHttpClient()
val port = KobaltServer.port ?: 1240 val port = KobaltServer.port ?: 1240
val url = "ws://localhost:$port/v1/getDependencyGraph" val url = "ws://localhost:$port/v1/getDependencyGraph"
val buildFile = KFiles.fixSlashes(homeDir("kotlin/kobalt/kobalt/src/Build.kt")) val buildFile = KFiles.fixSlashes(homeDir("java/testng/kobalt/src/Build.kt"))
val projectRoot = KFiles.fixSlashes(homeDir("java/testng"))
val request = Request.Builder() val request = Request.Builder()
// .url("ws://echo.websocket.org") // .url("ws://echo.websocket.org")
.url("$url?buildFile=$buildFile") .url("$url?projectRoot=$projectRoot&buildFile=$buildFile")
.build() .build()
var webSocket: WebSocket? = null var webSocket: WebSocket? = null
val ws = WebSocketCall.create(client, request).enqueue(object: WebSocketListener { val ws = WebSocketCall.create(client, request).enqueue(object: WebSocketListener {