<commit_before>package com.beust.kobalt.internal.remote

import com.beust.kobalt.Args
import com.beust.kobalt.kotlin.BuildFile
import com.beust.kobalt.kotlin.BuildFileCompiler
import com.beust.kobalt.maven.IClasspathDependency
import com.beust.kobalt.maven.MavenDependency
import com.beust.kobalt.misc.KobaltExecutors
import com.beust.kobalt.misc.log
import com.google.gson.Gson
import com.google.gson.JsonObject
import com.google.inject.Inject
import java.nio.file.Paths

/**
 * This command returns the list of dependencies for the given buildFile.
 * Payload:
 * {
 *   "name" : "getDependencies"
 *   "buildFile": "Build.kt"
 * }
 * The response is a GetDependenciesData.
 */
class GetDependenciesCommand @Inject constructor(val executors: KobaltExecutors,
        val buildFileCompilerFactory: BuildFileCompiler.IFactory, val args: Args) : ICommand {
    override val name = "getDependencies"
    override fun run(sender: ICommandSender, received: JsonObject) {
        val buildFile = BuildFile(Paths.get(received.get("buildFile").asString), "GetDependenciesCommand")
        val scriptCompiler = buildFileCompilerFactory.create(listOf(buildFile))
        scriptCompiler.observable.subscribe {
            buildScriptInfo -> if (buildScriptInfo.projects.size() > 0) {
                sender.sendData(toJson(buildScriptInfo))
            }
        }
        scriptCompiler.compileBuildFiles(args)
    }

    private fun toJson(info: BuildFileCompiler.BuildScriptInfo) : CommandData {
        val executor = executors.miscExecutor
        val projects = arrayListOf<ProjectData>()

        fun toDependencyData(d: IClasspathDependency, scope: String) : DependencyData {
            val dep = MavenDependency.create(d.id, executor)
            return DependencyData(d.id, scope, dep.jarFile.get().absolutePath)
        }

        info.projects.forEach { project ->
            val allDependencies =<commit_msg>Rename<commit_after>package com.beust.kobalt.internal.remote

import com.beust.kobalt.Args
import com.beust.kobalt.kotlin.BuildFile
import com.beust.kobalt.kotlin.BuildFileCompiler
import com.beust.kobalt.maven.IClasspathDependency
import com.beust.kobalt.maven.MavenDependency
import com.beust.kobalt.misc.KobaltExecutors
import com.beust.kobalt.misc.log
import com.google.gson.Gson
import com.google.gson.JsonObject
import com.google.inject.Inject
import java.nio.file.Paths

/**
 * This command returns the list of dependencies for the given buildFile.
 * Payload:
 * {
 *   "name" : "getDependencies"
 *   "buildFile": "Build.kt"
 * }
 * The response is a GetDependenciesData.
 */
class GetDependenciesCommand @Inject constructor(val executors: KobaltExecutors,
        val buildFileCompilerFactory: BuildFileCompiler.IFactory, val args: Args) : ICommand {
    override val name = "getDependencies"
    override fun run(sender: ICommandSender, received: JsonObject) {
        val buildFile = BuildFile(Paths.get(received.get("buildFile").asString), "GetDependenciesCommand")
        val scriptCompiler = buildFileCompilerFactory.create(listOf(buildFile))
        scriptCompiler.observable.subscribe {
            buildScriptInfo -> if (buildScriptInfo.projects.size() > 0) {
                sender.sendData(toData(buildScriptInfo))
            }
        }
        scriptCompiler.compileBuildFiles(args)
    }

    private fun toData(info: BuildFileCompiler.BuildScriptInfo) : CommandData {
        val executor = executors.miscExecutor
        val projects = arrayListOf<ProjectData>()

        fun toDependencyData(d: IClasspathDependency, scope: String) : DependencyData {
            val dep = MavenDependency.create(d.id, executor)
            return DependencyData(d.id, scope, dep.jarFile.get().absolutePath)
        }

        info.projects.forEach { project ->
            val allDependencies =
{'fraction_non_alphanumeric': 0.09531290913851793, 'fraction_numerical': 0.0005236973029588898, 'mean_word_length': 3.6079613992762365, 'pattern_counts': {'":': 2, '<': 5, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4557671', 'n_tokens_mistral': 1134, 'n_tokens_neox': 1095, 'n_words': 222}