diff --git a/src/main/kotlin/com/beust/kobalt/app/UpdateKobalt.kt b/src/main/kotlin/com/beust/kobalt/app/UpdateKobalt.kt index b2ad82e1..dbcaa86c 100644 --- a/src/main/kotlin/com/beust/kobalt/app/UpdateKobalt.kt +++ b/src/main/kotlin/com/beust/kobalt/app/UpdateKobalt.kt @@ -14,7 +14,7 @@ import javax.inject.Inject /** * Update Kobalt to the latest version. */ -public class UpdateKobalt @Inject constructor(val github: GithubApi, val wrapperProperties: KobaltWrapperProperties) { +class UpdateKobalt @Inject constructor(val github: GithubApi, val wrapperProperties: KobaltWrapperProperties) { fun updateKobalt() { val newVersion = github.latestKobaltVersion wrapperProperties.create(newVersion.get()) diff --git a/src/main/kotlin/com/beust/kobalt/app/remote/DependencyData.kt b/src/main/kotlin/com/beust/kobalt/app/remote/DependencyData.kt new file mode 100644 index 00000000..b087226c --- /dev/null +++ b/src/main/kotlin/com/beust/kobalt/app/remote/DependencyData.kt @@ -0,0 +1,73 @@ +package com.beust.kobalt.app.remote + +import com.beust.kobalt.Args +import com.beust.kobalt.api.IClasspathDependency +import com.beust.kobalt.api.ProjectDescription +import com.beust.kobalt.app.BuildFileCompiler +import com.beust.kobalt.internal.JvmCompilerPlugin +import com.beust.kobalt.internal.PluginInfo +import com.beust.kobalt.internal.build.BuildFile +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.inject.Inject +import java.io.File +import java.nio.file.Paths + +class DependencyData @Inject constructor(val executors: KobaltExecutors, val dependencyManager: DependencyManager, + val buildFileCompilerFactory: BuildFileCompiler.IFactory, val pluginInfo: PluginInfo) { + fun dependenciesDataFor(buildFilePath: String, args: Args) : GetDependenciesData { + val projectDatas = arrayListOf() + val executor = executors.miscExecutor + + fun toDependencyData(d: IClasspathDependency, scope: String): DependencyData { + val dep = MavenDependency.create(d.id, executor = executor) + return DependencyData(d.id, scope, dep.jarFile.get().absolutePath) + } + + fun allDeps(l: List) = dependencyManager.transitiveClosure(l) + + val buildFile = BuildFile(Paths.get(buildFilePath), "GetDependenciesCommand") + val buildFileCompiler = buildFileCompilerFactory.create(listOf(buildFile), pluginInfo) + val projects = buildFileCompiler.compileBuildFiles(args) + val pluginUrls = buildFileCompiler.parsedBuildFiles.flatMap { it.pluginUrls } + + val pluginDependencies = pluginUrls.map { File(it.toURI()) }.map { FileDependency(it.absolutePath) } + projects.forEach { project -> + val compileDependencies = pluginDependencies.map { toDependencyData(it, "compile") } + + allDeps(project.compileDependencies).map { toDependencyData(it, "compile") } + + allDeps(project.compileProvidedDependencies).map { toDependencyData(it, "compile") } + val testDependencies = allDeps(project.testDependencies).map { toDependencyData(it, "testCompile") } + + @Suppress("UNCHECKED_CAST") + val pd = (project.projectProperties.get(JvmCompilerPlugin.DEPENDENT_PROJECTS) + as List) + val dependentProjects = pd.filter { it.project.name == project.name }.flatMap { + it.dependsOn.map { + it + .name + } + } + projectDatas.add(ProjectData(project.name, project.directory, dependentProjects, + compileDependencies, testDependencies, + project.sourceDirectories, project.sourceDirectoriesTest)) + } + log(1, "Returning BuildScriptInfo") + return GetDependenciesData(projectDatas) + } + + ///// + // The JSON payloads that this command uses + // + + class DependencyData(val id: String, val scope: String, val path: String) + + class ProjectData(val name: String, val directory: String, + val dependentProjects: List, + val compileDependencies: List, + val testDependencies: List, val sourceDirs: Set, val testDirs: Set) + + class GetDependenciesData(val projects: List) +} \ No newline at end of file diff --git a/src/main/kotlin/com/beust/kobalt/app/remote/GetDependenciesCommand.kt b/src/main/kotlin/com/beust/kobalt/app/remote/GetDependenciesCommand.kt index 8f06577b..014c77ba 100644 --- a/src/main/kotlin/com/beust/kobalt/app/remote/GetDependenciesCommand.kt +++ b/src/main/kotlin/com/beust/kobalt/app/remote/GetDependenciesCommand.kt @@ -1,26 +1,10 @@ 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.api.ProjectDescription -import com.beust.kobalt.app.BuildFileCompiler -import com.beust.kobalt.internal.JvmCompilerPlugin -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 /** @@ -29,62 +13,13 @@ import javax.inject.Inject * { "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 { +class GetDependenciesCommand @Inject constructor(val args: Args, val dependencyData: DependencyData) : 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 })) + val buildFile = received.get("buildFile").asString + val data = toCommandData(Gson().toJson(dependencyData.dependenciesDataFor(buildFile, args))) + sender.sendData(data) } - - 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 = 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 compileDependencies = pluginDependencies.map { toDependencyData(it, "compile")} + - allDeps(project.compileDependencies).map { toDependencyData(it, "compile") } + - allDeps(project.compileProvidedDependencies).map { toDependencyData(it, "compile") } - val testDependencies = allDeps(project.testDependencies).map { toDependencyData(it, "testCompile") } - - @Suppress("UNCHECKED_CAST") - val pd = (project.projectProperties.get(JvmCompilerPlugin.DEPENDENT_PROJECTS) - as List) - val dependentProjects = pd.filter { it.project.name == project.name }.flatMap { - it.dependsOn.map { it - .name - }} - projectDatas.add(ProjectData(project.name, project.directory, dependentProjects, - compileDependencies, testDependencies, - project.sourceDirectories, project.sourceDirectoriesTest)) - } - 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 directory: String, - val dependentProjects: List, - val compileDependencies: List, - val testDependencies: List, val sourceDirs: Set, val testDirs: Set) - - class GetDependenciesData(val projects: List) } \ No newline at end of file diff --git a/src/main/kotlin/com/beust/kobalt/app/remote/KobaltClient.kt b/src/main/kotlin/com/beust/kobalt/app/remote/KobaltClient.kt index 2b972e0f..b2ab98cb 100644 --- a/src/main/kotlin/com/beust/kobalt/app/remote/KobaltClient.kt +++ b/src/main/kotlin/com/beust/kobalt/app/remote/KobaltClient.kt @@ -40,7 +40,7 @@ public class KobaltClient @Inject constructor() : Runnable { done = true } else { val data = jo.get("data").asString - val dd = Gson().fromJson(data, GetDependenciesCommand.GetDependenciesData::class.java) + val dd = Gson().fromJson(data, DependencyData.GetDependenciesData::class.java) println("Read GetDependencyData, project count: ${dd.projects.size}") line = ins.readLine() }