mirror of
https://github.com/ethauvin/kobalt.git
synced 2025-04-27 00:38:11 -07:00
Tasks were no longer being sent in GetDependencyData.
Caused by the fact that the Kobalt server was not initializing itself with the build file sent in the command, so it didn't initialize any tasks. Fixed by extracting this logic in the new ProjectFinder class which is now used by both Main.kt and KobaltServer.kt.
This commit is contained in:
parent
443ed190cb
commit
a5cd7f168a
3 changed files with 113 additions and 88 deletions
|
@ -4,9 +4,7 @@ import com.beust.jcommander.JCommander
|
||||||
import com.beust.kobalt.api.IClasspathDependency
|
import com.beust.kobalt.api.IClasspathDependency
|
||||||
import com.beust.kobalt.api.Kobalt
|
import com.beust.kobalt.api.Kobalt
|
||||||
import com.beust.kobalt.api.PluginTask
|
import com.beust.kobalt.api.PluginTask
|
||||||
import com.beust.kobalt.api.Project
|
|
||||||
import com.beust.kobalt.app.*
|
import com.beust.kobalt.app.*
|
||||||
import com.beust.kobalt.app.remote.DependencyData
|
|
||||||
import com.beust.kobalt.app.remote.KobaltClient
|
import com.beust.kobalt.app.remote.KobaltClient
|
||||||
import com.beust.kobalt.app.remote.KobaltServer
|
import com.beust.kobalt.app.remote.KobaltServer
|
||||||
import com.beust.kobalt.internal.Gc
|
import com.beust.kobalt.internal.Gc
|
||||||
|
@ -22,7 +20,6 @@ import com.google.common.collect.HashMultimap
|
||||||
import java.io.File
|
import java.io.File
|
||||||
import java.net.URLClassLoader
|
import java.net.URLClassLoader
|
||||||
import java.nio.file.Paths
|
import java.nio.file.Paths
|
||||||
import java.util.*
|
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
|
|
||||||
fun main(argv: Array<String>) {
|
fun main(argv: Array<String>) {
|
||||||
|
@ -53,7 +50,6 @@ fun mainNoExit(argv: Array<String>): Int {
|
||||||
}
|
}
|
||||||
|
|
||||||
private class Main @Inject constructor(
|
private class Main @Inject constructor(
|
||||||
val buildFileCompilerFactory: BuildFileCompiler.IFactory,
|
|
||||||
val plugins: Plugins,
|
val plugins: Plugins,
|
||||||
val taskManager: TaskManager,
|
val taskManager: TaskManager,
|
||||||
val http: Http,
|
val http: Http,
|
||||||
|
@ -65,9 +61,9 @@ private class Main @Inject constructor(
|
||||||
val updateKobalt: UpdateKobalt,
|
val updateKobalt: UpdateKobalt,
|
||||||
val client: KobaltClient,
|
val client: KobaltClient,
|
||||||
val pluginInfo: PluginInfo,
|
val pluginInfo: PluginInfo,
|
||||||
val dependencyData: DependencyData,
|
|
||||||
val projectGenerator: ProjectGenerator,
|
val projectGenerator: ProjectGenerator,
|
||||||
val serverFactory: KobaltServer.IFactory,
|
val serverFactory: KobaltServer.IFactory,
|
||||||
|
val projectFinder: ProjectFinder,
|
||||||
val resolveDependency: ResolveDependency) {
|
val resolveDependency: ResolveDependency) {
|
||||||
|
|
||||||
data class RunInfo(val jc: JCommander, val args: Args)
|
data class RunInfo(val jc: JCommander, val args: Args)
|
||||||
|
@ -160,7 +156,7 @@ private class Main @Inject constructor(
|
||||||
} else if (args.serverMode) {
|
} else if (args.serverMode) {
|
||||||
// --server
|
// --server
|
||||||
val port = serverFactory.create(args.force, args.port,
|
val port = serverFactory.create(args.force, args.port,
|
||||||
{ buildFile -> initForBuildFile(BuildFile(Paths.get(buildFile), buildFile), args)},
|
{ buildFile -> projectFinder.initForBuildFile(BuildFile(Paths.get(buildFile), buildFile), args)},
|
||||||
{ cleanUp() })
|
{ cleanUp() })
|
||||||
.call()
|
.call()
|
||||||
} else {
|
} else {
|
||||||
|
@ -178,7 +174,7 @@ private class Main @Inject constructor(
|
||||||
error(buildFile.path.toFile().path + " does not exist")
|
error(buildFile.path.toFile().path + " does not exist")
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
val allProjects = initForBuildFile(buildFile, args)
|
val allProjects = projectFinder.initForBuildFile(buildFile, args)
|
||||||
|
|
||||||
// DONOTCOMMIT
|
// DONOTCOMMIT
|
||||||
// val data = dependencyData.dependenciesDataFor(homeDir("kotlin/klaxon/kobalt/src/Build.kt"), Args())
|
// val data = dependencyData.dependenciesDataFor(homeDir("kotlin/klaxon/kobalt/src/Build.kt"), Args())
|
||||||
|
@ -221,48 +217,24 @@ private class Main @Inject constructor(
|
||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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()
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun initForBuildFile(buildFile: BuildFile, args: Args): List<Project> {
|
|
||||||
val findProjectResult = buildFileCompilerFactory.create(listOf(buildFile), pluginInfo)
|
|
||||||
.compileBuildFiles(args)
|
|
||||||
if (! findProjectResult.taskResult.success) {
|
|
||||||
throw KobaltException("Couldn't compile build file: "
|
|
||||||
+ findProjectResult.taskResult.errorMessage)
|
|
||||||
}
|
|
||||||
|
|
||||||
val allProjects = findProjectResult.projects
|
|
||||||
findProjectResult.context.allProjects.addAll(allProjects)
|
|
||||||
|
|
||||||
//
|
|
||||||
// Now that we have projects, add all the repos from repo contributors that need a Project
|
|
||||||
//
|
|
||||||
allProjects.forEach { project ->
|
|
||||||
pluginInfo.repoContributors.forEach {
|
|
||||||
it.reposFor(project).forEach {
|
|
||||||
Kobalt.addRepo(it)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
// Run all the dependencies through the IDependencyInterceptors
|
|
||||||
//
|
|
||||||
runClasspathInterceptors(allProjects)
|
|
||||||
|
|
||||||
log(2, "Final list of repos:\n " + Kobalt.repos.joinToString("\n "))
|
|
||||||
|
|
||||||
//
|
|
||||||
// Call apply() on all plug-ins now that the repos are set up
|
|
||||||
//
|
|
||||||
plugins.applyPlugins(Kobalt.context!!, allProjects)
|
|
||||||
|
|
||||||
return allProjects
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun displayTasks() {
|
private fun displayTasks() {
|
||||||
//
|
//
|
||||||
// List of tasks, --tasks
|
// List of tasks, --tasks
|
||||||
|
@ -286,48 +258,4 @@ private class Main @Inject constructor(
|
||||||
|
|
||||||
println(sb.toString())
|
println(sb.toString())
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun runClasspathInterceptors(allProjects: List<Project>) {
|
|
||||||
allProjects.forEach {
|
|
||||||
runClasspathInterceptors(it, it.compileDependencies)
|
|
||||||
runClasspathInterceptors(it, it.compileProvidedDependencies)
|
|
||||||
runClasspathInterceptors(it, it.compileRuntimeDependencies)
|
|
||||||
runClasspathInterceptors(it, it.testProvidedDependencies)
|
|
||||||
runClasspathInterceptors(it, it.testDependencies)
|
|
||||||
runClasspathInterceptors(it, it.nativeDependencies)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun runClasspathInterceptors(project: Project, dependencies: ArrayList<IClasspathDependency>)
|
|
||||||
= with(dependencies) {
|
|
||||||
if (pluginInfo.classpathInterceptors.size > 0) {
|
|
||||||
val deps = interceptDependencies(project, pluginInfo, this)
|
|
||||||
clear()
|
|
||||||
addAll(deps)
|
|
||||||
} else {
|
|
||||||
this
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun interceptDependencies(project: Project, pluginInfo: PluginInfo,
|
|
||||||
dependencies: ArrayList<IClasspathDependency>) : ArrayList<IClasspathDependency> {
|
|
||||||
val result = arrayListOf<IClasspathDependency>()
|
|
||||||
pluginInfo.classpathInterceptors.forEach {
|
|
||||||
result.addAll(it.intercept(project, dependencies))
|
|
||||||
}
|
|
||||||
return result
|
|
||||||
}
|
|
||||||
|
|
||||||
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
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
87
src/main/kotlin/com/beust/kobalt/app/ProjectFinder.kt
Normal file
87
src/main/kotlin/com/beust/kobalt/app/ProjectFinder.kt
Normal file
|
@ -0,0 +1,87 @@
|
||||||
|
package com.beust.kobalt.app
|
||||||
|
|
||||||
|
import com.beust.kobalt.Args
|
||||||
|
import com.beust.kobalt.KobaltException
|
||||||
|
import com.beust.kobalt.Plugins
|
||||||
|
import com.beust.kobalt.api.IClasspathDependency
|
||||||
|
import com.beust.kobalt.api.Kobalt
|
||||||
|
import com.beust.kobalt.api.Project
|
||||||
|
import com.beust.kobalt.internal.PluginInfo
|
||||||
|
import com.beust.kobalt.internal.build.BuildFile
|
||||||
|
import com.beust.kobalt.misc.log
|
||||||
|
import com.google.inject.Inject
|
||||||
|
import java.util.*
|
||||||
|
|
||||||
|
class ProjectFinder @Inject constructor(val buildFileCompilerFactory: BuildFileCompiler.IFactory,
|
||||||
|
val pluginInfo: PluginInfo, val plugins: Plugins) {
|
||||||
|
|
||||||
|
fun initForBuildFile(buildFile: BuildFile, args: Args): List<Project> {
|
||||||
|
val findProjectResult = buildFileCompilerFactory.create(listOf(buildFile), pluginInfo)
|
||||||
|
.compileBuildFiles(args)
|
||||||
|
if (! findProjectResult.taskResult.success) {
|
||||||
|
throw KobaltException("Couldn't compile build file: "
|
||||||
|
+ findProjectResult.taskResult.errorMessage)
|
||||||
|
}
|
||||||
|
|
||||||
|
val allProjects = findProjectResult.projects
|
||||||
|
findProjectResult.context.allProjects.addAll(allProjects)
|
||||||
|
|
||||||
|
//
|
||||||
|
// Now that we have projects, add all the repos from repo contributors that need a Project
|
||||||
|
//
|
||||||
|
allProjects.forEach { project ->
|
||||||
|
pluginInfo.repoContributors.forEach {
|
||||||
|
it.reposFor(project).forEach {
|
||||||
|
Kobalt.addRepo(it)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Run all the dependencies through the IDependencyInterceptors
|
||||||
|
//
|
||||||
|
runClasspathInterceptors(allProjects)
|
||||||
|
|
||||||
|
log(2, "Final list of repos:\n " + Kobalt.repos.joinToString("\n "))
|
||||||
|
|
||||||
|
//
|
||||||
|
// Call apply() on all plug-ins now that the repos are set up
|
||||||
|
//
|
||||||
|
plugins.applyPlugins(Kobalt.context!!, allProjects)
|
||||||
|
|
||||||
|
return allProjects
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun runClasspathInterceptors(allProjects: List<Project>) {
|
||||||
|
allProjects.forEach {
|
||||||
|
runClasspathInterceptors(it, it.compileDependencies)
|
||||||
|
runClasspathInterceptors(it, it.compileProvidedDependencies)
|
||||||
|
runClasspathInterceptors(it, it.compileRuntimeDependencies)
|
||||||
|
runClasspathInterceptors(it, it.testProvidedDependencies)
|
||||||
|
runClasspathInterceptors(it, it.testDependencies)
|
||||||
|
runClasspathInterceptors(it, it.nativeDependencies)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun runClasspathInterceptors(project: Project, dependencies: ArrayList<IClasspathDependency>)
|
||||||
|
= with(dependencies) {
|
||||||
|
if (pluginInfo.classpathInterceptors.size > 0) {
|
||||||
|
val deps = interceptDependencies(project, pluginInfo, this)
|
||||||
|
clear()
|
||||||
|
addAll(deps)
|
||||||
|
} else {
|
||||||
|
this
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun interceptDependencies(project: Project, pluginInfo: PluginInfo,
|
||||||
|
dependencies: ArrayList<IClasspathDependency>) : ArrayList<IClasspathDependency> {
|
||||||
|
val result = arrayListOf<IClasspathDependency>()
|
||||||
|
pluginInfo.classpathInterceptors.forEach {
|
||||||
|
result.addAll(it.intercept(project, dependencies))
|
||||||
|
}
|
||||||
|
return result
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
|
@ -4,8 +4,10 @@ import com.beust.kobalt.Args
|
||||||
import com.beust.kobalt.api.ITemplate
|
import com.beust.kobalt.api.ITemplate
|
||||||
import com.beust.kobalt.api.Kobalt
|
import com.beust.kobalt.api.Kobalt
|
||||||
import com.beust.kobalt.api.Project
|
import com.beust.kobalt.api.Project
|
||||||
|
import com.beust.kobalt.app.ProjectFinder
|
||||||
import com.beust.kobalt.app.Templates
|
import com.beust.kobalt.app.Templates
|
||||||
import com.beust.kobalt.internal.PluginInfo
|
import com.beust.kobalt.internal.PluginInfo
|
||||||
|
import com.beust.kobalt.internal.build.BuildFile
|
||||||
import com.beust.kobalt.internal.eventbus.ArtifactDownloadedEvent
|
import com.beust.kobalt.internal.eventbus.ArtifactDownloadedEvent
|
||||||
import com.google.common.collect.ListMultimap
|
import com.google.common.collect.ListMultimap
|
||||||
import com.google.common.eventbus.EventBus
|
import com.google.common.eventbus.EventBus
|
||||||
|
@ -17,6 +19,7 @@ import org.eclipse.jetty.websocket.api.WebSocketListener
|
||||||
import spark.ResponseTransformer
|
import spark.ResponseTransformer
|
||||||
import spark.Route
|
import spark.Route
|
||||||
import spark.Spark
|
import spark.Spark
|
||||||
|
import java.nio.file.Paths
|
||||||
import java.util.concurrent.Executors
|
import java.util.concurrent.Executors
|
||||||
|
|
||||||
class SparkServer(val initCallback: (String) -> List<Project>, val cleanUpCallback: () -> Unit,
|
class SparkServer(val initCallback: (String) -> List<Project>, val cleanUpCallback: () -> Unit,
|
||||||
|
@ -87,6 +90,10 @@ class SparkServer(val initCallback: (String) -> List<Project>, val cleanUpCallba
|
||||||
}
|
}
|
||||||
|
|
||||||
class GetDependenciesChatHandler : WebSocketListener {
|
class GetDependenciesChatHandler : WebSocketListener {
|
||||||
|
// The SparkJava project refused to merge https://github.com/perwendel/spark/pull/383
|
||||||
|
// so I have to do dependency injections manually :-(
|
||||||
|
val projectFinder = Kobalt.INJECTOR.getInstance(ProjectFinder::class.java)
|
||||||
|
|
||||||
var session: Session? = null
|
var session: Session? = null
|
||||||
|
|
||||||
override fun onWebSocketClose(code: Int, reason: String?) {
|
override fun onWebSocketClose(code: Int, reason: String?) {
|
||||||
|
@ -129,6 +136,9 @@ class GetDependenciesChatHandler : WebSocketListener {
|
||||||
val dependencyData = getInstance(DependencyData::class.java)
|
val dependencyData = getInstance(DependencyData::class.java)
|
||||||
val args = getInstance(Args::class.java)
|
val args = getInstance(Args::class.java)
|
||||||
|
|
||||||
|
val allProjects = projectFinder.initForBuildFile(BuildFile(Paths.get(buildFile), buildFile),
|
||||||
|
args)
|
||||||
|
|
||||||
dependencyData.dependenciesDataFor(buildFile, args, object : IProgressListener {
|
dependencyData.dependenciesDataFor(buildFile, args, object : IProgressListener {
|
||||||
override fun onProgress(progress: Int?, message: String?) {
|
override fun onProgress(progress: Int?, message: String?) {
|
||||||
sendWebsocketCommand(s.remote, ProgressCommand.NAME, ProgressCommand(progress, message))
|
sendWebsocketCommand(s.remote, ProgressCommand.NAME, ProgressCommand(progress, message))
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue