diff --git a/src/main/kotlin/com/beust/kobalt/Main.kt b/src/main/kotlin/com/beust/kobalt/Main.kt index f5eec45e..44ff5c02 100644 --- a/src/main/kotlin/com/beust/kobalt/Main.kt +++ b/src/main/kotlin/com/beust/kobalt/Main.kt @@ -5,15 +5,15 @@ import com.beust.kobalt.api.IClasspathDependency import com.beust.kobalt.api.Kobalt import com.beust.kobalt.api.PluginTask 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.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.TaskManager 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.Http import com.beust.kobalt.maven.LocalRepo diff --git a/src/main/kotlin/com/beust/kobalt/api/Kobalt.kt b/src/main/kotlin/com/beust/kobalt/api/Kobalt.kt index a84fe52d..930f5d8a 100644 --- a/src/main/kotlin/com/beust/kobalt/api/Kobalt.kt +++ b/src/main/kotlin/com/beust/kobalt/api/Kobalt.kt @@ -1,11 +1,8 @@ package com.beust.kobalt.api -import com.beust.kobalt.Args import com.beust.kobalt.Constants import com.beust.kobalt.HostConfig import com.beust.kobalt.Plugins -import com.beust.kobalt.misc.MainModule -import com.google.inject.Guice import com.google.inject.Injector import java.io.InputStream import java.util.* @@ -15,7 +12,7 @@ public class Kobalt { // 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 // 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 diff --git a/src/main/kotlin/com/beust/kobalt/internal/build/BuildFileCompiler.kt b/src/main/kotlin/com/beust/kobalt/app/BuildFileCompiler.kt similarity index 96% rename from src/main/kotlin/com/beust/kobalt/internal/build/BuildFileCompiler.kt rename to src/main/kotlin/com/beust/kobalt/app/BuildFileCompiler.kt index d6d493d7..d7a9afe2 100644 --- a/src/main/kotlin/com/beust/kobalt/internal/build/BuildFileCompiler.kt +++ b/src/main/kotlin/com/beust/kobalt/app/BuildFileCompiler.kt @@ -1,4 +1,4 @@ -package com.beust.kobalt.internal.build +package com.beust.kobalt.app import com.beust.kobalt.Args 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.Project 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.maven.DependencyManager import com.beust.kobalt.misc.KFiles diff --git a/src/main/kotlin/com/beust/kobalt/internal/BuildGenerator.kt b/src/main/kotlin/com/beust/kobalt/app/BuildGenerator.kt similarity index 97% rename from src/main/kotlin/com/beust/kobalt/internal/BuildGenerator.kt rename to src/main/kotlin/com/beust/kobalt/app/BuildGenerator.kt index a8dc7743..c4fe2806 100644 --- a/src/main/kotlin/com/beust/kobalt/internal/BuildGenerator.kt +++ b/src/main/kotlin/com/beust/kobalt/app/BuildGenerator.kt @@ -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.maven.Pom import com.beust.kobalt.misc.KFiles diff --git a/src/main/kotlin/com/beust/kobalt/internal/build/BuildScriptUtil.kt b/src/main/kotlin/com/beust/kobalt/app/BuildScriptUtil.kt similarity index 98% rename from src/main/kotlin/com/beust/kobalt/internal/build/BuildScriptUtil.kt rename to src/main/kotlin/com/beust/kobalt/app/BuildScriptUtil.kt index 7a6d0f4a..6f21bb3b 100644 --- a/src/main/kotlin/com/beust/kobalt/internal/build/BuildScriptUtil.kt +++ b/src/main/kotlin/com/beust/kobalt/app/BuildScriptUtil.kt @@ -1,4 +1,4 @@ -package com.beust.kobalt.internal.build +package com.beust.kobalt.app import com.beust.kobalt.KobaltException 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.annotation.Task import com.beust.kobalt.internal.TaskManager +import com.beust.kobalt.internal.build.BuildFile import com.beust.kobalt.misc.KFiles import com.beust.kobalt.misc.Topological import com.beust.kobalt.misc.log diff --git a/src/main/kotlin/com/beust/kobalt/app/MainModule.kt b/src/main/kotlin/com/beust/kobalt/app/MainModule.kt new file mode 100644 index 00000000..eb8d4d3d --- /dev/null +++ b/src/main/kotlin/com/beust/kobalt/app/MainModule.kt @@ -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()).toProvider(javaClass()) +// .`in`(Scopes.SINGLETON) + bind(object: TypeLiteral() {}).toInstance(executors) + bind(object: TypeLiteral() {}).annotatedWith(DependencyExecutor::class.java) + .toInstance(executors.dependencyExecutor) + bind(Args::class.java).toProvider(Provider { + args + }) + bind(PluginInfo::class.java).toProvider(Provider { + PluginInfo.readKobaltPluginXml() + }).`in`(Singleton::class.java) + + +// bindListener(Matchers.any(), object: TypeListener { +// override fun hear(typeLiteral: TypeLiteral?, typeEncounter: TypeEncounter?) { +// val bean = object: InjectionListener { +// override public fun afterInjection(injectee: I) { +// if (Scopes.isCircularProxy(injectee)) { +// println("CYCLE: " + typeLiteral?.getRawType()?.getName()); +// } +// } +// } +// typeEncounter?.register(bean) +// } +// }) + } +} \ No newline at end of file diff --git a/src/main/kotlin/com/beust/kobalt/internal/build/ParsedBuildFile.kt b/src/main/kotlin/com/beust/kobalt/app/ParsedBuildFile.kt similarity index 97% rename from src/main/kotlin/com/beust/kobalt/internal/build/ParsedBuildFile.kt rename to src/main/kotlin/com/beust/kobalt/app/ParsedBuildFile.kt index cdb99a20..0f32797b 100644 --- a/src/main/kotlin/com/beust/kobalt/internal/build/ParsedBuildFile.kt +++ b/src/main/kotlin/com/beust/kobalt/app/ParsedBuildFile.kt @@ -1,13 +1,15 @@ -package com.beust.kobalt.internal.build +package com.beust.kobalt.app import com.beust.kobalt.Plugins import com.beust.kobalt.api.KobaltContext 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.misc.KFiles import com.beust.kobalt.misc.countChar import com.beust.kobalt.misc.log -import com.beust.kobalt.kotlin.kotlinCompilePrivate import java.io.File import java.net.URL import java.nio.charset.Charset diff --git a/src/main/kotlin/com/beust/kobalt/app/remote/GetDependenciesCommand.kt b/src/main/kotlin/com/beust/kobalt/app/remote/GetDependenciesCommand.kt new file mode 100644 index 00000000..b766b336 --- /dev/null +++ b/src/main/kotlin/com/beust/kobalt/app/remote/GetDependenciesCommand.kt @@ -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, pluginUrls: List) : CommandData { + val projectDatas = arrayListOf() + 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) = 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) + + class GetDependenciesData(val projects: List) +} \ No newline at end of file diff --git a/src/main/kotlin/com/beust/kobalt/internal/remote/KobaltClient.kt b/src/main/kotlin/com/beust/kobalt/app/remote/KobaltClient.kt similarity index 98% rename from src/main/kotlin/com/beust/kobalt/internal/remote/KobaltClient.kt rename to src/main/kotlin/com/beust/kobalt/app/remote/KobaltClient.kt index 01cefe59..433c312c 100644 --- a/src/main/kotlin/com/beust/kobalt/internal/remote/KobaltClient.kt +++ b/src/main/kotlin/com/beust/kobalt/app/remote/KobaltClient.kt @@ -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.misc.log diff --git a/src/main/kotlin/com/beust/kobalt/app/remote/KobaltServer.kt b/src/main/kotlin/com/beust/kobalt/app/remote/KobaltServer.kt new file mode 100644 index 00000000..793a7a5a --- /dev/null +++ b/src/main/kotlin/com/beust/kobalt/app/remote/KobaltServer.kt @@ -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() + + 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) + } + } + } +} \ No newline at end of file diff --git a/src/main/kotlin/com/beust/kobalt/internal/remote/GetDependenciesCommand.kt b/src/main/kotlin/com/beust/kobalt/internal/remote/GetDependenciesCommand.kt index 4e5f7ae0..88b22fd1 100644 --- a/src/main/kotlin/com/beust/kobalt/internal/remote/GetDependenciesCommand.kt +++ b/src/main/kotlin/com/beust/kobalt/internal/remote/GetDependenciesCommand.kt @@ -1,81 +1,8 @@ package com.beust.kobalt.internal.remote -import com.beust.kobalt.Args 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.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, pluginUrls: List) : CommandData { - val projectDatas = arrayListOf() - 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) = 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) - - class GetDependenciesData(val projects: List) -} fun main(argv: Array) { val socket = Socket("localhost", 1234) diff --git a/src/main/kotlin/com/beust/kobalt/internal/remote/KobaltServer.kt b/src/main/kotlin/com/beust/kobalt/internal/remote/KobaltServer.kt index fb215ea5..9704cd0b 100644 --- a/src/main/kotlin/com/beust/kobalt/internal/remote/KobaltServer.kt +++ b/src/main/kotlin/com/beust/kobalt/internal/remote/KobaltServer.kt @@ -1,18 +1,6 @@ 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.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. @@ -53,83 +41,4 @@ interface ICommandSender { */ 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() - - 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) - } - } - } -} - diff --git a/src/main/kotlin/com/beust/kobalt/kotlin/KotlinCompiler.kt b/src/main/kotlin/com/beust/kobalt/kotlin/KotlinCompiler.kt index 9cd359b5..3cc13a3a 100644 --- a/src/main/kotlin/com/beust/kobalt/kotlin/KotlinCompiler.kt +++ b/src/main/kotlin/com/beust/kobalt/kotlin/KotlinCompiler.kt @@ -2,7 +2,7 @@ package com.beust.kobalt.kotlin import com.beust.kobalt.TaskResult 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.JvmCompiler import com.beust.kobalt.maven.DepFactory diff --git a/src/main/kotlin/com/beust/kobalt/app/ParentLastClassLoader.kt b/src/main/kotlin/com/beust/kobalt/kotlin/ParentLastClassLoader.kt similarity index 98% rename from src/main/kotlin/com/beust/kobalt/app/ParentLastClassLoader.kt rename to src/main/kotlin/com/beust/kobalt/kotlin/ParentLastClassLoader.kt index 22bed44b..10269d52 100644 --- a/src/main/kotlin/com/beust/kobalt/app/ParentLastClassLoader.kt +++ b/src/main/kotlin/com/beust/kobalt/kotlin/ParentLastClassLoader.kt @@ -1,4 +1,4 @@ -package com.beust.kobalt.app +package com.beust.kobalt.kotlin import java.net.URL import java.net.URLClassLoader diff --git a/src/main/kotlin/com/beust/kobalt/misc/JarUtils.kt b/src/main/kotlin/com/beust/kobalt/misc/JarUtils.kt index ab255581..910bf73e 100644 --- a/src/main/kotlin/com/beust/kobalt/misc/JarUtils.kt +++ b/src/main/kotlin/com/beust/kobalt/misc/JarUtils.kt @@ -1,8 +1,6 @@ package com.beust.kobalt.misc 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 java.io.* 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) { + constructor(specs: List) : 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 To(override val p: String) : Direction(p) diff --git a/src/main/kotlin/com/beust/kobalt/misc/MainModule.kt b/src/main/kotlin/com/beust/kobalt/misc/MainModule.kt index 02bdea1e..fcd316d9 100644 --- a/src/main/kotlin/com/beust/kobalt/misc/MainModule.kt +++ b/src/main/kotlin/com/beust/kobalt/misc/MainModule.kt @@ -1,16 +1,6 @@ package com.beust.kobalt.misc -import com.beust.kobalt.Args -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 +import com.google.inject.BindingAnnotation //@Singleton //class TaskManagerProvider @Inject constructor(val plugins: Plugins) : Provider { @@ -23,50 +13,3 @@ import java.util.concurrent.ExecutorService @Retention(AnnotationRetention.RUNTIME) 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()).toProvider(javaClass()) -// .`in`(Scopes.SINGLETON) - bind(object: TypeLiteral() {}).toInstance(executors) - bind(object: TypeLiteral() {}).annotatedWith(DependencyExecutor::class.java) - .toInstance(executors.dependencyExecutor) - bind(Args::class.java).toProvider(Provider { - args - }) - bind(PluginInfo::class.java).toProvider(Provider { - PluginInfo.readKobaltPluginXml() - }).`in`(Singleton::class.java) - - -// bindListener(Matchers.any(), object: TypeListener { -// override fun hear(typeLiteral: TypeLiteral?, typeEncounter: TypeEncounter?) { -// val bean = object: InjectionListener { -// override public fun afterInjection(injectee: I) { -// if (Scopes.isCircularProxy(injectee)) { -// println("CYCLE: " + typeLiteral?.getRawType()?.getName()); -// } -// } -// } -// typeEncounter?.register(bean) -// } -// }) - } -} diff --git a/src/main/kotlin/com/beust/kobalt/plugin/java/JavaBuildGenerator.kt b/src/main/kotlin/com/beust/kobalt/plugin/java/JavaBuildGenerator.kt index 848429b8..604c03c5 100644 --- a/src/main/kotlin/com/beust/kobalt/plugin/java/JavaBuildGenerator.kt +++ b/src/main/kotlin/com/beust/kobalt/plugin/java/JavaBuildGenerator.kt @@ -1,6 +1,6 @@ package com.beust.kobalt.plugin.java -import com.beust.kobalt.internal.BuildGenerator +import com.beust.kobalt.app.BuildGenerator import com.google.inject.Inject public class JavaBuildGenerator @Inject constructor (val projectInfo: JavaProjectInfo) : BuildGenerator() { diff --git a/src/main/kotlin/com/beust/kobalt/plugin/kotlin/KotlinBuildGenerator.kt b/src/main/kotlin/com/beust/kobalt/plugin/kotlin/KotlinBuildGenerator.kt index 82c9e9de..8983a8b2 100644 --- a/src/main/kotlin/com/beust/kobalt/plugin/kotlin/KotlinBuildGenerator.kt +++ b/src/main/kotlin/com/beust/kobalt/plugin/kotlin/KotlinBuildGenerator.kt @@ -1,6 +1,6 @@ package com.beust.kobalt.plugin.kotlin -import com.beust.kobalt.internal.BuildGenerator +import com.beust.kobalt.app.BuildGenerator import com.google.inject.Inject public class KotlinBuildGenerator @Inject constructor (val projectInfo: KotlinProjectInfo) : BuildGenerator() { diff --git a/src/main/kotlin/com/beust/kobalt/plugin/packaging/PackagingPlugin.kt b/src/main/kotlin/com/beust/kobalt/plugin/packaging/PackagingPlugin.kt index ffa0d582..5ffc7cda 100644 --- a/src/main/kotlin/com/beust/kobalt/plugin/packaging/PackagingPlugin.kt +++ b/src/main/kotlin/com/beust/kobalt/plugin/packaging/PackagingPlugin.kt @@ -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) { - constructor(specs: List) : 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 { fun addAttribute(k: String, v: String) } diff --git a/src/main/resources/kobalt.properties b/src/main/resources/kobalt.properties index 9daedc8b..abc6cf93 100644 --- a/src/main/resources/kobalt.properties +++ b/src/main/resources/kobalt.properties @@ -1 +1 @@ -kobalt.version=0.338 +kobalt.version=0.339 diff --git a/src/test/kotlin/com/beust/kobalt/TestModule.kt b/src/test/kotlin/com/beust/kobalt/TestModule.kt index b5775d27..37324664 100644 --- a/src/test/kotlin/com/beust/kobalt/TestModule.kt +++ b/src/test/kotlin/com/beust/kobalt/TestModule.kt @@ -2,7 +2,7 @@ package com.beust.kobalt import com.beust.kobalt.Args import com.beust.kobalt.maven.LocalRepo -import com.beust.kobalt.misc.MainModule +import com.beust.kobalt.app.MainModule import com.google.inject.Scopes import java.io.File diff --git a/src/test/kotlin/com/beust/kobalt/maven/RemoteRepoTest.kt b/src/test/kotlin/com/beust/kobalt/maven/RemoteRepoTest.kt index 72948d08..723b7a65 100644 --- a/src/test/kotlin/com/beust/kobalt/maven/RemoteRepoTest.kt +++ b/src/test/kotlin/com/beust/kobalt/maven/RemoteRepoTest.kt @@ -4,7 +4,7 @@ import com.beust.kobalt.Args import com.beust.kobalt.TestModule import com.beust.kobalt.maven.dependency.MavenDependency import com.beust.kobalt.misc.DependencyExecutor -import com.beust.kobalt.misc.MainModule +import com.beust.kobalt.app.MainModule import com.google.inject.Guice import org.testng.Assert import org.testng.annotations.Test