mirror of
https://github.com/ethauvin/kobalt.git
synced 2025-04-26 16:28:12 -07:00
More moving classes around.
This commit is contained in:
parent
3592243bd8
commit
6b1b141943
22 changed files with 281 additions and 261 deletions
|
@ -5,15 +5,15 @@ 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.api.Project
|
||||||
import com.beust.kobalt.Args
|
import com.beust.kobalt.app.BuildFileCompiler
|
||||||
|
import com.beust.kobalt.app.MainModule
|
||||||
import com.beust.kobalt.app.ProjectGenerator
|
import com.beust.kobalt.app.ProjectGenerator
|
||||||
import com.beust.kobalt.app.UpdateKobalt
|
import com.beust.kobalt.app.UpdateKobalt
|
||||||
|
import com.beust.kobalt.app.remote.KobaltClient
|
||||||
|
import com.beust.kobalt.app.remote.KobaltServer
|
||||||
import com.beust.kobalt.internal.PluginInfo
|
import com.beust.kobalt.internal.PluginInfo
|
||||||
import com.beust.kobalt.internal.TaskManager
|
import com.beust.kobalt.internal.TaskManager
|
||||||
import com.beust.kobalt.internal.build.BuildFile
|
import com.beust.kobalt.internal.build.BuildFile
|
||||||
import com.beust.kobalt.internal.build.BuildFileCompiler
|
|
||||||
import com.beust.kobalt.internal.remote.KobaltClient
|
|
||||||
import com.beust.kobalt.internal.remote.KobaltServer
|
|
||||||
import com.beust.kobalt.maven.DepFactory
|
import com.beust.kobalt.maven.DepFactory
|
||||||
import com.beust.kobalt.maven.Http
|
import com.beust.kobalt.maven.Http
|
||||||
import com.beust.kobalt.maven.LocalRepo
|
import com.beust.kobalt.maven.LocalRepo
|
||||||
|
|
|
@ -1,11 +1,8 @@
|
||||||
package com.beust.kobalt.api
|
package com.beust.kobalt.api
|
||||||
|
|
||||||
import com.beust.kobalt.Args
|
|
||||||
import com.beust.kobalt.Constants
|
import com.beust.kobalt.Constants
|
||||||
import com.beust.kobalt.HostConfig
|
import com.beust.kobalt.HostConfig
|
||||||
import com.beust.kobalt.Plugins
|
import com.beust.kobalt.Plugins
|
||||||
import com.beust.kobalt.misc.MainModule
|
|
||||||
import com.google.inject.Guice
|
|
||||||
import com.google.inject.Injector
|
import com.google.inject.Injector
|
||||||
import java.io.InputStream
|
import java.io.InputStream
|
||||||
import java.util.*
|
import java.util.*
|
||||||
|
@ -15,7 +12,7 @@ public class Kobalt {
|
||||||
// This injector will eventually be replaced with a different injector initialized with the
|
// This injector will eventually be replaced with a different injector initialized with the
|
||||||
// correct arguments (or with a TestModule) but it's necessary to give it a default value
|
// correct arguments (or with a TestModule) but it's necessary to give it a default value
|
||||||
// here so the kobalt-plugin.xml file can be read since this is done very early
|
// here so the kobalt-plugin.xml file can be read since this is done very early
|
||||||
var INJECTOR : Injector = Guice.createInjector(MainModule(Args()))
|
lateinit var INJECTOR : Injector
|
||||||
|
|
||||||
var context: KobaltContext? = null
|
var context: KobaltContext? = null
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
package com.beust.kobalt.internal.build
|
package com.beust.kobalt.app
|
||||||
|
|
||||||
import com.beust.kobalt.Args
|
import com.beust.kobalt.Args
|
||||||
import com.beust.kobalt.Constants
|
import com.beust.kobalt.Constants
|
||||||
|
@ -9,6 +9,9 @@ import com.beust.kobalt.api.KobaltContext
|
||||||
import com.beust.kobalt.api.PluginProperties
|
import com.beust.kobalt.api.PluginProperties
|
||||||
import com.beust.kobalt.api.Project
|
import com.beust.kobalt.api.Project
|
||||||
import com.beust.kobalt.internal.PluginInfo
|
import com.beust.kobalt.internal.PluginInfo
|
||||||
|
import com.beust.kobalt.internal.build.BuildFile
|
||||||
|
import com.beust.kobalt.app.ParsedBuildFile
|
||||||
|
import com.beust.kobalt.internal.build.VersionFile
|
||||||
import com.beust.kobalt.kotlin.kotlinCompilePrivate
|
import com.beust.kobalt.kotlin.kotlinCompilePrivate
|
||||||
import com.beust.kobalt.maven.DependencyManager
|
import com.beust.kobalt.maven.DependencyManager
|
||||||
import com.beust.kobalt.misc.KFiles
|
import com.beust.kobalt.misc.KFiles
|
|
@ -1,6 +1,5 @@
|
||||||
package com.beust.kobalt.internal
|
package com.beust.kobalt.app
|
||||||
|
|
||||||
import com.beust.kobalt.app.ProjectGenerator
|
|
||||||
import com.beust.kobalt.api.IInitContributor
|
import com.beust.kobalt.api.IInitContributor
|
||||||
import com.beust.kobalt.maven.Pom
|
import com.beust.kobalt.maven.Pom
|
||||||
import com.beust.kobalt.misc.KFiles
|
import com.beust.kobalt.misc.KFiles
|
|
@ -1,4 +1,4 @@
|
||||||
package com.beust.kobalt.internal.build
|
package com.beust.kobalt.app
|
||||||
|
|
||||||
import com.beust.kobalt.KobaltException
|
import com.beust.kobalt.KobaltException
|
||||||
import com.beust.kobalt.Plugins
|
import com.beust.kobalt.Plugins
|
||||||
|
@ -7,6 +7,7 @@ import com.beust.kobalt.api.KobaltContext
|
||||||
import com.beust.kobalt.api.Project
|
import com.beust.kobalt.api.Project
|
||||||
import com.beust.kobalt.api.annotation.Task
|
import com.beust.kobalt.api.annotation.Task
|
||||||
import com.beust.kobalt.internal.TaskManager
|
import com.beust.kobalt.internal.TaskManager
|
||||||
|
import com.beust.kobalt.internal.build.BuildFile
|
||||||
import com.beust.kobalt.misc.KFiles
|
import com.beust.kobalt.misc.KFiles
|
||||||
import com.beust.kobalt.misc.Topological
|
import com.beust.kobalt.misc.Topological
|
||||||
import com.beust.kobalt.misc.log
|
import com.beust.kobalt.misc.log
|
65
src/main/kotlin/com/beust/kobalt/app/MainModule.kt
Normal file
65
src/main/kotlin/com/beust/kobalt/app/MainModule.kt
Normal file
|
@ -0,0 +1,65 @@
|
||||||
|
package com.beust.kobalt.app
|
||||||
|
|
||||||
|
import com.beust.kobalt.Args
|
||||||
|
import com.beust.kobalt.internal.PluginInfo
|
||||||
|
import com.beust.kobalt.maven.ArtifactFetcher
|
||||||
|
import com.beust.kobalt.maven.LocalRepo
|
||||||
|
import com.beust.kobalt.maven.Pom
|
||||||
|
import com.beust.kobalt.maven.PomGenerator
|
||||||
|
import com.beust.kobalt.misc.DependencyExecutor
|
||||||
|
import com.beust.kobalt.misc.KobaltExecutors
|
||||||
|
import com.beust.kobalt.plugin.publish.JCenterApi
|
||||||
|
import com.google.inject.AbstractModule
|
||||||
|
import com.google.inject.Provider
|
||||||
|
import com.google.inject.Singleton
|
||||||
|
import com.google.inject.TypeLiteral
|
||||||
|
import com.google.inject.assistedinject.FactoryModuleBuilder
|
||||||
|
import java.util.concurrent.ExecutorService
|
||||||
|
|
||||||
|
public open class MainModule(val args: Args) : AbstractModule() {
|
||||||
|
val executors = KobaltExecutors()
|
||||||
|
|
||||||
|
open fun configureTest() {
|
||||||
|
bind(LocalRepo::class.java)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun configure() {
|
||||||
|
configureTest()
|
||||||
|
val builder = FactoryModuleBuilder()
|
||||||
|
arrayListOf(
|
||||||
|
PomGenerator.IFactory::class.java,
|
||||||
|
JCenterApi.IFactory::class.java,
|
||||||
|
Pom.IFactory::class.java,
|
||||||
|
BuildFileCompiler.IFactory::class.java,
|
||||||
|
ArtifactFetcher.IFactory::class.java)
|
||||||
|
.forEach {
|
||||||
|
install(builder.build(it))
|
||||||
|
}
|
||||||
|
|
||||||
|
// bind(javaClass<TaskManager>()).toProvider(javaClass<TaskManagerProvider>())
|
||||||
|
// .`in`(Scopes.SINGLETON)
|
||||||
|
bind(object: TypeLiteral<KobaltExecutors>() {}).toInstance(executors)
|
||||||
|
bind(object: TypeLiteral<ExecutorService>() {}).annotatedWith(DependencyExecutor::class.java)
|
||||||
|
.toInstance(executors.dependencyExecutor)
|
||||||
|
bind(Args::class.java).toProvider(Provider<Args> {
|
||||||
|
args
|
||||||
|
})
|
||||||
|
bind(PluginInfo::class.java).toProvider(Provider<PluginInfo> {
|
||||||
|
PluginInfo.readKobaltPluginXml()
|
||||||
|
}).`in`(Singleton::class.java)
|
||||||
|
|
||||||
|
|
||||||
|
// bindListener(Matchers.any(), object: TypeListener {
|
||||||
|
// override fun <I> hear(typeLiteral: TypeLiteral<I>?, typeEncounter: TypeEncounter<I>?) {
|
||||||
|
// val bean = object: InjectionListener<I> {
|
||||||
|
// override public fun afterInjection(injectee: I) {
|
||||||
|
// if (Scopes.isCircularProxy(injectee)) {
|
||||||
|
// println("CYCLE: " + typeLiteral?.getRawType()?.getName());
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// typeEncounter?.register(bean)
|
||||||
|
// }
|
||||||
|
// })
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,13 +1,15 @@
|
||||||
package com.beust.kobalt.internal.build
|
package com.beust.kobalt.app
|
||||||
|
|
||||||
import com.beust.kobalt.Plugins
|
import com.beust.kobalt.Plugins
|
||||||
import com.beust.kobalt.api.KobaltContext
|
import com.beust.kobalt.api.KobaltContext
|
||||||
import com.beust.kobalt.api.Project
|
import com.beust.kobalt.api.Project
|
||||||
|
import com.beust.kobalt.internal.build.BuildFile
|
||||||
|
import com.beust.kobalt.internal.build.VersionFile
|
||||||
|
import com.beust.kobalt.kotlin.kotlinCompilePrivate
|
||||||
import com.beust.kobalt.maven.DependencyManager
|
import com.beust.kobalt.maven.DependencyManager
|
||||||
import com.beust.kobalt.misc.KFiles
|
import com.beust.kobalt.misc.KFiles
|
||||||
import com.beust.kobalt.misc.countChar
|
import com.beust.kobalt.misc.countChar
|
||||||
import com.beust.kobalt.misc.log
|
import com.beust.kobalt.misc.log
|
||||||
import com.beust.kobalt.kotlin.kotlinCompilePrivate
|
|
||||||
import java.io.File
|
import java.io.File
|
||||||
import java.net.URL
|
import java.net.URL
|
||||||
import java.nio.charset.Charset
|
import java.nio.charset.Charset
|
|
@ -0,0 +1,79 @@
|
||||||
|
package com.beust.kobalt.app.remote
|
||||||
|
|
||||||
|
import com.beust.kobalt.Args
|
||||||
|
import com.beust.kobalt.api.IClasspathDependency
|
||||||
|
import com.beust.kobalt.api.Project
|
||||||
|
import com.beust.kobalt.app.BuildFileCompiler
|
||||||
|
import com.beust.kobalt.internal.PluginInfo
|
||||||
|
import com.beust.kobalt.internal.build.BuildFile
|
||||||
|
import com.beust.kobalt.internal.remote.CommandData
|
||||||
|
import com.beust.kobalt.internal.remote.ICommand
|
||||||
|
import com.beust.kobalt.internal.remote.ICommandSender
|
||||||
|
import com.beust.kobalt.maven.DependencyManager
|
||||||
|
import com.beust.kobalt.maven.dependency.FileDependency
|
||||||
|
import com.beust.kobalt.maven.dependency.MavenDependency
|
||||||
|
import com.beust.kobalt.misc.KobaltExecutors
|
||||||
|
import com.beust.kobalt.misc.log
|
||||||
|
import com.google.gson.Gson
|
||||||
|
import com.google.gson.JsonObject
|
||||||
|
import java.io.File
|
||||||
|
import java.net.URL
|
||||||
|
import java.nio.file.Paths
|
||||||
|
import javax.inject.Inject
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This command returns the list of dependencies for the given buildFile.
|
||||||
|
* Payload:
|
||||||
|
* { "name" : "getDependencies", "buildFile": "/Users/beust/kotlin/kobalt/kobalt/src/Build.kt" }
|
||||||
|
* The response is a GetDependenciesData.
|
||||||
|
*/
|
||||||
|
class GetDependenciesCommand @Inject constructor(val executors: KobaltExecutors,
|
||||||
|
val buildFileCompilerFactory: BuildFileCompiler.IFactory, val args: Args,
|
||||||
|
val dependencyManager: DependencyManager, val pluginInfo: PluginInfo) : ICommand {
|
||||||
|
override val name = "getDependencies"
|
||||||
|
override fun run(sender: ICommandSender, received: JsonObject) {
|
||||||
|
val buildFile = BuildFile(Paths.get(received.get("buildFile").asString), "GetDependenciesCommand")
|
||||||
|
val buildFileCompiler = buildFileCompilerFactory.create(listOf(buildFile), pluginInfo)
|
||||||
|
val projects = buildFileCompiler.compileBuildFiles(args)
|
||||||
|
sender.sendData(toData(projects, buildFileCompiler.parsedBuildFiles.flatMap { it.pluginUrls }))
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun toData(projects: List<Project>, pluginUrls: List<URL>) : CommandData {
|
||||||
|
val projectDatas = arrayListOf<ProjectData>()
|
||||||
|
val executor = executors.miscExecutor
|
||||||
|
|
||||||
|
fun toDependencyData(d: IClasspathDependency, scope: String) : DependencyData {
|
||||||
|
val dep = MavenDependency.create(d.id, executor)
|
||||||
|
return DependencyData(d.id, scope, dep.jarFile.get().absolutePath)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun allDeps(l: List<IClasspathDependency>) = dependencyManager.transitiveClosure(l)
|
||||||
|
|
||||||
|
val pluginDependencies = pluginUrls.map { File(it.toURI()) }.map { FileDependency(it.absolutePath) }
|
||||||
|
projects.forEach { project ->
|
||||||
|
val allDependencies =
|
||||||
|
pluginDependencies.map { toDependencyData(it, "compile")} +
|
||||||
|
allDeps(project.compileDependencies).map { toDependencyData(it, "compile") } +
|
||||||
|
allDeps(project.compileProvidedDependencies).map { toDependencyData(it, "provided") } +
|
||||||
|
allDeps(project.compileRuntimeDependencies).map { toDependencyData(it, "runtime") } +
|
||||||
|
allDeps(project.testDependencies).map { toDependencyData(it, "testCompile") } +
|
||||||
|
allDeps(project.testProvidedDependencies).map { toDependencyData(it, "testProvided") }
|
||||||
|
|
||||||
|
projectDatas.add(ProjectData(project.name, allDependencies))
|
||||||
|
}
|
||||||
|
log(1, "Returning BuildScriptInfo")
|
||||||
|
val result = toCommandData(Gson().toJson(GetDependenciesData(projectDatas)))
|
||||||
|
log(2, " $result")
|
||||||
|
return result
|
||||||
|
}
|
||||||
|
|
||||||
|
/////
|
||||||
|
// The JSON payloads that this command uses
|
||||||
|
//
|
||||||
|
|
||||||
|
class DependencyData(val id: String, val scope: String, val path: String)
|
||||||
|
|
||||||
|
class ProjectData( val name: String, val dependencies: List<DependencyData>)
|
||||||
|
|
||||||
|
class GetDependenciesData(val projects: List<ProjectData>)
|
||||||
|
}
|
|
@ -1,4 +1,4 @@
|
||||||
package com.beust.kobalt.internal.remote
|
package com.beust.kobalt.app.remote
|
||||||
|
|
||||||
import com.beust.kobalt.SystemProperties
|
import com.beust.kobalt.SystemProperties
|
||||||
import com.beust.kobalt.misc.log
|
import com.beust.kobalt.misc.log
|
97
src/main/kotlin/com/beust/kobalt/app/remote/KobaltServer.kt
Normal file
97
src/main/kotlin/com/beust/kobalt/app/remote/KobaltServer.kt
Normal file
|
@ -0,0 +1,97 @@
|
||||||
|
package com.beust.kobalt.app.remote
|
||||||
|
|
||||||
|
import com.beust.kobalt.Args
|
||||||
|
import com.beust.kobalt.api.Kobalt
|
||||||
|
import com.beust.kobalt.internal.remote.CommandData
|
||||||
|
import com.beust.kobalt.internal.remote.ICommandSender
|
||||||
|
import com.beust.kobalt.internal.remote.PingCommand
|
||||||
|
import com.beust.kobalt.misc.log
|
||||||
|
import com.google.gson.Gson
|
||||||
|
import com.google.gson.JsonObject
|
||||||
|
import com.google.gson.JsonParser
|
||||||
|
import com.google.inject.Singleton
|
||||||
|
import java.io.BufferedReader
|
||||||
|
import java.io.InputStreamReader
|
||||||
|
import java.io.PrintWriter
|
||||||
|
import java.net.ServerSocket
|
||||||
|
import java.net.SocketException
|
||||||
|
import javax.inject.Inject
|
||||||
|
|
||||||
|
@Singleton
|
||||||
|
public class KobaltServer @Inject constructor(val args: Args) : Runnable, ICommandSender {
|
||||||
|
var outgoing: PrintWriter? = null
|
||||||
|
val pending = arrayListOf<CommandData>()
|
||||||
|
|
||||||
|
private val COMMAND_CLASSES = listOf(GetDependenciesCommand::class.java, PingCommand::class.java)
|
||||||
|
private val COMMANDS = COMMAND_CLASSES.map {
|
||||||
|
Kobalt.INJECTOR.getInstance(it).let { Pair(it.name, it) }
|
||||||
|
}.toMap()
|
||||||
|
|
||||||
|
override fun run() {
|
||||||
|
val portNumber = args.port
|
||||||
|
|
||||||
|
log(1, "Listening to port $portNumber")
|
||||||
|
var quit = false
|
||||||
|
val serverSocket = ServerSocket(portNumber)
|
||||||
|
var clientSocket = serverSocket.accept()
|
||||||
|
while (!quit) {
|
||||||
|
outgoing = PrintWriter(clientSocket.outputStream, true)
|
||||||
|
if (pending.size > 0) {
|
||||||
|
log(1, "Emptying the queue, size $pending.size()")
|
||||||
|
synchronized(pending) {
|
||||||
|
pending.forEach { sendData(it) }
|
||||||
|
pending.clear()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
val ins = BufferedReader(InputStreamReader(clientSocket.inputStream))
|
||||||
|
var commandName: String? = null
|
||||||
|
try {
|
||||||
|
var line = ins.readLine()
|
||||||
|
while (!quit && line != null) {
|
||||||
|
log(1, "Received from client $line")
|
||||||
|
val jo = JsonParser().parse(line) as JsonObject
|
||||||
|
commandName = jo.get("name").asString
|
||||||
|
if ("quit" == commandName) {
|
||||||
|
log(1, "Quitting")
|
||||||
|
quit = true
|
||||||
|
} else {
|
||||||
|
runCommand(jo)
|
||||||
|
|
||||||
|
// Done, send a quit to the client
|
||||||
|
sendData(CommandData("quit", ""))
|
||||||
|
|
||||||
|
line = ins.readLine()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch(ex: SocketException) {
|
||||||
|
log(1, "Client disconnected, resetting")
|
||||||
|
clientSocket = serverSocket.accept()
|
||||||
|
} catch(ex: Throwable) {
|
||||||
|
ex.printStackTrace()
|
||||||
|
sendData(CommandData(commandName!!, null, ex.message))
|
||||||
|
log(1, "Command failed: ${ex.message}")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun runCommand(jo: JsonObject) {
|
||||||
|
val command = jo.get("name").asString
|
||||||
|
if (command != null) {
|
||||||
|
COMMANDS.getOrElse(command, { COMMANDS.get("ping") })!!.run(this, jo)
|
||||||
|
} else {
|
||||||
|
error("Did not find a name in command: $jo")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun sendData(commandData: CommandData) {
|
||||||
|
val content = Gson().toJson(commandData)
|
||||||
|
if (outgoing != null) {
|
||||||
|
outgoing!!.println(content)
|
||||||
|
} else {
|
||||||
|
log(1, "Queuing $content")
|
||||||
|
synchronized(pending) {
|
||||||
|
pending.add(commandData)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,81 +1,8 @@
|
||||||
package com.beust.kobalt.internal.remote
|
package com.beust.kobalt.internal.remote
|
||||||
|
|
||||||
import com.beust.kobalt.Args
|
|
||||||
import com.beust.kobalt.Constants
|
import com.beust.kobalt.Constants
|
||||||
import com.beust.kobalt.api.IClasspathDependency
|
|
||||||
import com.beust.kobalt.api.Project
|
|
||||||
import com.beust.kobalt.internal.PluginInfo
|
|
||||||
import com.beust.kobalt.internal.build.BuildFile
|
|
||||||
import com.beust.kobalt.internal.build.BuildFileCompiler
|
|
||||||
import com.beust.kobalt.maven.DependencyManager
|
|
||||||
import com.beust.kobalt.maven.dependency.FileDependency
|
|
||||||
import com.beust.kobalt.maven.dependency.MavenDependency
|
|
||||||
import com.beust.kobalt.misc.KobaltExecutors
|
|
||||||
import com.beust.kobalt.misc.log
|
|
||||||
import com.google.gson.Gson
|
|
||||||
import com.google.gson.JsonObject
|
|
||||||
import java.io.PrintWriter
|
import java.io.PrintWriter
|
||||||
import java.net.Socket
|
import java.net.Socket
|
||||||
import java.net.URL
|
|
||||||
import java.nio.file.Paths
|
|
||||||
import javax.inject.Inject
|
|
||||||
|
|
||||||
/**
|
|
||||||
* This command returns the list of dependencies for the given buildFile.
|
|
||||||
* Payload:
|
|
||||||
* { "name" : "getDependencies", "buildFile": "/Users/beust/kotlin/kobalt/kobalt/src/Build.kt" }
|
|
||||||
* The response is a GetDependenciesData.
|
|
||||||
*/
|
|
||||||
class GetDependenciesCommand @Inject constructor(val executors: KobaltExecutors,
|
|
||||||
val buildFileCompilerFactory: BuildFileCompiler.IFactory, val args: Args,
|
|
||||||
val dependencyManager: DependencyManager, val pluginInfo: PluginInfo) : ICommand {
|
|
||||||
override val name = "getDependencies"
|
|
||||||
override fun run(sender: ICommandSender, received: JsonObject) {
|
|
||||||
val buildFile = BuildFile(Paths.get(received.get("buildFile").asString), "GetDependenciesCommand")
|
|
||||||
val buildFileCompiler = buildFileCompilerFactory.create(listOf(buildFile), pluginInfo)
|
|
||||||
val projects = buildFileCompiler.compileBuildFiles(args)
|
|
||||||
sender.sendData(toData(projects, buildFileCompiler.parsedBuildFiles.flatMap { it.pluginUrls }))
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun toData(projects: List<Project>, pluginUrls: List<URL>) : CommandData {
|
|
||||||
val projectDatas = arrayListOf<ProjectData>()
|
|
||||||
val executor = executors.miscExecutor
|
|
||||||
|
|
||||||
fun toDependencyData(d: IClasspathDependency, scope: String) : DependencyData {
|
|
||||||
val dep = MavenDependency.create(d.id, executor)
|
|
||||||
return DependencyData(d.id, scope, dep.jarFile.get().absolutePath)
|
|
||||||
}
|
|
||||||
|
|
||||||
fun allDeps(l: List<IClasspathDependency>) = dependencyManager.transitiveClosure(l)
|
|
||||||
|
|
||||||
val pluginDependencies = pluginUrls.map { java.io.File(it.toURI()) }.map { FileDependency(it.absolutePath) }
|
|
||||||
projects.forEach { project ->
|
|
||||||
val allDependencies =
|
|
||||||
pluginDependencies.map { toDependencyData(it, "compile")} +
|
|
||||||
allDeps(project.compileDependencies).map { toDependencyData(it, "compile") } +
|
|
||||||
allDeps(project.compileProvidedDependencies).map { toDependencyData(it, "provided") } +
|
|
||||||
allDeps(project.compileRuntimeDependencies).map { toDependencyData(it, "runtime") } +
|
|
||||||
allDeps(project.testDependencies).map { toDependencyData(it, "testCompile") } +
|
|
||||||
allDeps(project.testProvidedDependencies).map { toDependencyData(it, "testProvided") }
|
|
||||||
|
|
||||||
projectDatas.add(ProjectData(project.name, allDependencies))
|
|
||||||
}
|
|
||||||
log(1, "Returning BuildScriptInfo")
|
|
||||||
val result = toCommandData(Gson().toJson(GetDependenciesData(projectDatas)))
|
|
||||||
log(2, " $result")
|
|
||||||
return result
|
|
||||||
}
|
|
||||||
|
|
||||||
/////
|
|
||||||
// The JSON payloads that this command uses
|
|
||||||
//
|
|
||||||
|
|
||||||
class DependencyData(val id: String, val scope: String, val path: String)
|
|
||||||
|
|
||||||
class ProjectData( val name: String, val dependencies: List<DependencyData>)
|
|
||||||
|
|
||||||
class GetDependenciesData(val projects: List<ProjectData>)
|
|
||||||
}
|
|
||||||
|
|
||||||
fun main(argv: Array<String>) {
|
fun main(argv: Array<String>) {
|
||||||
val socket = Socket("localhost", 1234)
|
val socket = Socket("localhost", 1234)
|
||||||
|
|
|
@ -1,18 +1,6 @@
|
||||||
package com.beust.kobalt.internal.remote
|
package com.beust.kobalt.internal.remote
|
||||||
|
|
||||||
import com.beust.kobalt.Args
|
|
||||||
import com.beust.kobalt.api.Kobalt
|
|
||||||
import com.beust.kobalt.misc.log
|
|
||||||
import com.google.gson.Gson
|
|
||||||
import com.google.gson.JsonObject
|
import com.google.gson.JsonObject
|
||||||
import com.google.gson.JsonParser
|
|
||||||
import com.google.inject.Singleton
|
|
||||||
import java.io.BufferedReader
|
|
||||||
import java.io.InputStreamReader
|
|
||||||
import java.io.PrintWriter
|
|
||||||
import java.net.ServerSocket
|
|
||||||
import java.net.SocketException
|
|
||||||
import javax.inject.Inject
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* All commands implement this interface.
|
* All commands implement this interface.
|
||||||
|
@ -53,83 +41,4 @@ interface ICommandSender {
|
||||||
*/
|
*/
|
||||||
class CommandData(val name: String, val data: String?, val error: String? = null)
|
class CommandData(val name: String, val data: String?, val error: String? = null)
|
||||||
|
|
||||||
@Singleton
|
|
||||||
public class KobaltServer @Inject constructor(val args: Args) : Runnable, ICommandSender {
|
|
||||||
var outgoing: PrintWriter? = null
|
|
||||||
val pending = arrayListOf<CommandData>()
|
|
||||||
|
|
||||||
private val COMMAND_CLASSES = listOf(GetDependenciesCommand::class.java, PingCommand::class.java)
|
|
||||||
private val COMMANDS = COMMAND_CLASSES.map {
|
|
||||||
Kobalt.INJECTOR.getInstance(it).let { Pair(it.name, it) }
|
|
||||||
}.toMap()
|
|
||||||
|
|
||||||
override fun run() {
|
|
||||||
val portNumber = args.port
|
|
||||||
|
|
||||||
log(1, "Listening to port $portNumber")
|
|
||||||
var quit = false
|
|
||||||
val serverSocket = ServerSocket(portNumber)
|
|
||||||
var clientSocket = serverSocket.accept()
|
|
||||||
while (!quit) {
|
|
||||||
outgoing = PrintWriter(clientSocket.outputStream, true)
|
|
||||||
if (pending.size > 0) {
|
|
||||||
log(1, "Emptying the queue, size $pending.size()")
|
|
||||||
synchronized(pending) {
|
|
||||||
pending.forEach { sendData(it) }
|
|
||||||
pending.clear()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
val ins = BufferedReader(InputStreamReader(clientSocket.inputStream))
|
|
||||||
var commandName: String? = null
|
|
||||||
try {
|
|
||||||
var line = ins.readLine()
|
|
||||||
while (!quit && line != null) {
|
|
||||||
log(1, "Received from client $line")
|
|
||||||
val jo = JsonParser().parse(line) as JsonObject
|
|
||||||
commandName = jo.get("name").asString
|
|
||||||
if ("quit" == commandName) {
|
|
||||||
log(1, "Quitting")
|
|
||||||
quit = true
|
|
||||||
} else {
|
|
||||||
runCommand(jo)
|
|
||||||
|
|
||||||
// Done, send a quit to the client
|
|
||||||
sendData(CommandData("quit", ""))
|
|
||||||
|
|
||||||
line = ins.readLine()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} catch(ex: SocketException) {
|
|
||||||
log(1, "Client disconnected, resetting")
|
|
||||||
clientSocket = serverSocket.accept()
|
|
||||||
} catch(ex: Throwable) {
|
|
||||||
ex.printStackTrace()
|
|
||||||
sendData(CommandData(commandName!!, null, ex.message))
|
|
||||||
log(1, "Command failed: ${ex.message}")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun runCommand(jo: JsonObject) {
|
|
||||||
val command = jo.get("name").asString
|
|
||||||
if (command != null) {
|
|
||||||
COMMANDS.getOrElse(command, { COMMANDS.get("ping") })!!.run(this, jo)
|
|
||||||
} else {
|
|
||||||
error("Did not find a name in command: $jo")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun sendData(commandData: CommandData) {
|
|
||||||
val content = Gson().toJson(commandData)
|
|
||||||
if (outgoing != null) {
|
|
||||||
outgoing!!.println(content)
|
|
||||||
} else {
|
|
||||||
log(1, "Queuing $content")
|
|
||||||
synchronized(pending) {
|
|
||||||
pending.add(commandData)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -2,7 +2,7 @@ package com.beust.kobalt.kotlin
|
||||||
|
|
||||||
import com.beust.kobalt.TaskResult
|
import com.beust.kobalt.TaskResult
|
||||||
import com.beust.kobalt.api.*
|
import com.beust.kobalt.api.*
|
||||||
import com.beust.kobalt.app.ParentLastClassLoader
|
import com.beust.kobalt.kotlin.ParentLastClassLoader
|
||||||
import com.beust.kobalt.internal.ICompilerAction
|
import com.beust.kobalt.internal.ICompilerAction
|
||||||
import com.beust.kobalt.internal.JvmCompiler
|
import com.beust.kobalt.internal.JvmCompiler
|
||||||
import com.beust.kobalt.maven.DepFactory
|
import com.beust.kobalt.maven.DepFactory
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
package com.beust.kobalt.app
|
package com.beust.kobalt.kotlin
|
||||||
|
|
||||||
import java.net.URL
|
import java.net.URL
|
||||||
import java.net.URLClassLoader
|
import java.net.URLClassLoader
|
|
@ -1,8 +1,6 @@
|
||||||
package com.beust.kobalt.misc
|
package com.beust.kobalt.misc
|
||||||
|
|
||||||
import com.beust.kobalt.IFileSpec
|
import com.beust.kobalt.IFileSpec
|
||||||
import com.beust.kobalt.plugin.packaging.Direction
|
|
||||||
import com.beust.kobalt.plugin.packaging.IncludedFile
|
|
||||||
import com.google.common.io.CharStreams
|
import com.google.common.io.CharStreams
|
||||||
import java.io.*
|
import java.io.*
|
||||||
import java.util.jar.JarEntry
|
import java.util.jar.JarEntry
|
||||||
|
@ -142,6 +140,21 @@ public class JarUtils {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
open class Direction(open val p: String) {
|
||||||
|
override public fun toString() = path
|
||||||
|
public val path: String get() = if (p.isEmpty() or p.endsWith("/")) p else p + "/"
|
||||||
|
}
|
||||||
|
|
||||||
|
class IncludedFile(val fromOriginal: From, val toOriginal: To, val specs: List<IFileSpec>) {
|
||||||
|
constructor(specs: List<IFileSpec>) : this(From(""), To(""), specs)
|
||||||
|
public val from: String get() = fromOriginal.path.replace("\\", "/")
|
||||||
|
public val to: String get() = toOriginal.path.replace("\\", "/")
|
||||||
|
override public fun toString() = toString("IncludedFile",
|
||||||
|
"files", specs.map { it.toString() }.joinToString(", "),
|
||||||
|
"from", from,
|
||||||
|
"to", to)
|
||||||
|
}
|
||||||
|
|
||||||
class From(override val p: String) : Direction(p)
|
class From(override val p: String) : Direction(p)
|
||||||
|
|
||||||
class To(override val p: String) : Direction(p)
|
class To(override val p: String) : Direction(p)
|
||||||
|
|
|
@ -1,16 +1,6 @@
|
||||||
package com.beust.kobalt.misc
|
package com.beust.kobalt.misc
|
||||||
|
|
||||||
import com.beust.kobalt.Args
|
import com.google.inject.BindingAnnotation
|
||||||
import com.beust.kobalt.internal.PluginInfo
|
|
||||||
import com.beust.kobalt.internal.build.BuildFileCompiler
|
|
||||||
import com.beust.kobalt.maven.ArtifactFetcher
|
|
||||||
import com.beust.kobalt.maven.LocalRepo
|
|
||||||
import com.beust.kobalt.maven.Pom
|
|
||||||
import com.beust.kobalt.maven.PomGenerator
|
|
||||||
import com.beust.kobalt.plugin.publish.JCenterApi
|
|
||||||
import com.google.inject.*
|
|
||||||
import com.google.inject.assistedinject.FactoryModuleBuilder
|
|
||||||
import java.util.concurrent.ExecutorService
|
|
||||||
|
|
||||||
//@Singleton
|
//@Singleton
|
||||||
//class TaskManagerProvider @Inject constructor(val plugins: Plugins) : Provider<TaskManager> {
|
//class TaskManagerProvider @Inject constructor(val plugins: Plugins) : Provider<TaskManager> {
|
||||||
|
@ -23,50 +13,3 @@ import java.util.concurrent.ExecutorService
|
||||||
@Retention(AnnotationRetention.RUNTIME)
|
@Retention(AnnotationRetention.RUNTIME)
|
||||||
annotation class DependencyExecutor
|
annotation class DependencyExecutor
|
||||||
|
|
||||||
public open class MainModule(val args: Args) : AbstractModule() {
|
|
||||||
val executors = KobaltExecutors()
|
|
||||||
|
|
||||||
open fun configureTest() {
|
|
||||||
bind(LocalRepo::class.java)
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun configure() {
|
|
||||||
configureTest()
|
|
||||||
val builder = FactoryModuleBuilder()
|
|
||||||
arrayListOf(
|
|
||||||
PomGenerator.IFactory::class.java,
|
|
||||||
JCenterApi.IFactory::class.java,
|
|
||||||
Pom.IFactory::class.java,
|
|
||||||
BuildFileCompiler.IFactory::class.java,
|
|
||||||
ArtifactFetcher.IFactory::class.java)
|
|
||||||
.forEach {
|
|
||||||
install(builder.build(it))
|
|
||||||
}
|
|
||||||
|
|
||||||
// bind(javaClass<TaskManager>()).toProvider(javaClass<TaskManagerProvider>())
|
|
||||||
// .`in`(Scopes.SINGLETON)
|
|
||||||
bind(object: TypeLiteral<KobaltExecutors>() {}).toInstance(executors)
|
|
||||||
bind(object: TypeLiteral<ExecutorService>() {}).annotatedWith(DependencyExecutor::class.java)
|
|
||||||
.toInstance(executors.dependencyExecutor)
|
|
||||||
bind(Args::class.java).toProvider(Provider<Args> {
|
|
||||||
args
|
|
||||||
})
|
|
||||||
bind(PluginInfo::class.java).toProvider(Provider<PluginInfo> {
|
|
||||||
PluginInfo.readKobaltPluginXml()
|
|
||||||
}).`in`(Singleton::class.java)
|
|
||||||
|
|
||||||
|
|
||||||
// bindListener(Matchers.any(), object: TypeListener {
|
|
||||||
// override fun <I> hear(typeLiteral: TypeLiteral<I>?, typeEncounter: TypeEncounter<I>?) {
|
|
||||||
// val bean = object: InjectionListener<I> {
|
|
||||||
// override public fun afterInjection(injectee: I) {
|
|
||||||
// if (Scopes.isCircularProxy(injectee)) {
|
|
||||||
// println("CYCLE: " + typeLiteral?.getRawType()?.getName());
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// typeEncounter?.register(bean)
|
|
||||||
// }
|
|
||||||
// })
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
package com.beust.kobalt.plugin.java
|
package com.beust.kobalt.plugin.java
|
||||||
|
|
||||||
import com.beust.kobalt.internal.BuildGenerator
|
import com.beust.kobalt.app.BuildGenerator
|
||||||
import com.google.inject.Inject
|
import com.google.inject.Inject
|
||||||
|
|
||||||
public class JavaBuildGenerator @Inject constructor (val projectInfo: JavaProjectInfo) : BuildGenerator() {
|
public class JavaBuildGenerator @Inject constructor (val projectInfo: JavaProjectInfo) : BuildGenerator() {
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
package com.beust.kobalt.plugin.kotlin
|
package com.beust.kobalt.plugin.kotlin
|
||||||
|
|
||||||
import com.beust.kobalt.internal.BuildGenerator
|
import com.beust.kobalt.app.BuildGenerator
|
||||||
import com.google.inject.Inject
|
import com.google.inject.Inject
|
||||||
|
|
||||||
public class KotlinBuildGenerator @Inject constructor (val projectInfo: KotlinProjectInfo) : BuildGenerator() {
|
public class KotlinBuildGenerator @Inject constructor (val projectInfo: KotlinProjectInfo) : BuildGenerator() {
|
||||||
|
|
|
@ -410,21 +410,6 @@ open class Zip(open var name: String? = null) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
open class Direction(open val p: String) {
|
|
||||||
override public fun toString() = path
|
|
||||||
public val path: String get() = if (p.isEmpty() or p.endsWith("/")) p else p + "/"
|
|
||||||
}
|
|
||||||
|
|
||||||
class IncludedFile(val fromOriginal: From, val toOriginal: To, val specs: List<IFileSpec>) {
|
|
||||||
constructor(specs: List<IFileSpec>) : this(From(""), To(""), specs)
|
|
||||||
public val from: String get() = fromOriginal.path.replace("\\", "/")
|
|
||||||
public val to: String get() = toOriginal.path.replace("\\", "/")
|
|
||||||
override public fun toString() = toString("IncludedFile",
|
|
||||||
"files", specs.map { it.toString() }.joinToString(", "),
|
|
||||||
"from", from,
|
|
||||||
"to", to)
|
|
||||||
}
|
|
||||||
|
|
||||||
interface AttributeHolder {
|
interface AttributeHolder {
|
||||||
fun addAttribute(k: String, v: String)
|
fun addAttribute(k: String, v: String)
|
||||||
}
|
}
|
||||||
|
|
|
@ -1 +1 @@
|
||||||
kobalt.version=0.338
|
kobalt.version=0.339
|
||||||
|
|
|
@ -2,7 +2,7 @@ package com.beust.kobalt
|
||||||
|
|
||||||
import com.beust.kobalt.Args
|
import com.beust.kobalt.Args
|
||||||
import com.beust.kobalt.maven.LocalRepo
|
import com.beust.kobalt.maven.LocalRepo
|
||||||
import com.beust.kobalt.misc.MainModule
|
import com.beust.kobalt.app.MainModule
|
||||||
import com.google.inject.Scopes
|
import com.google.inject.Scopes
|
||||||
import java.io.File
|
import java.io.File
|
||||||
|
|
||||||
|
|
|
@ -4,7 +4,7 @@ import com.beust.kobalt.Args
|
||||||
import com.beust.kobalt.TestModule
|
import com.beust.kobalt.TestModule
|
||||||
import com.beust.kobalt.maven.dependency.MavenDependency
|
import com.beust.kobalt.maven.dependency.MavenDependency
|
||||||
import com.beust.kobalt.misc.DependencyExecutor
|
import com.beust.kobalt.misc.DependencyExecutor
|
||||||
import com.beust.kobalt.misc.MainModule
|
import com.beust.kobalt.app.MainModule
|
||||||
import com.google.inject.Guice
|
import com.google.inject.Guice
|
||||||
import org.testng.Assert
|
import org.testng.Assert
|
||||||
import org.testng.annotations.Test
|
import org.testng.annotations.Test
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue