<commit_before>package com.beust.kobalt.internal

import com.beust.kobalt.api.KobaltContext
import com.beust.kobalt.api.Project
import com.beust.kobalt.maven.DependencyManager
import com.beust.kobalt.maven.IClasspathDependency
import com.beust.kobalt.maven.KobaltException
import com.google.inject.Inject
import java.io.File

/**
 * Abstract the compilation process by running an ICompilerAction parameterized  by a CompilerActionInfo.
 * Also validates the classpath and run all the classpath contributors.
 */
class JvmCompiler @Inject constructor(val dependencyManager: DependencyManager) {
    fun doCompile(project: Project?, context: KobaltContext?, action: ICompilerAction, info: CompilerActionInfo)
            : TaskResult {
        File(info.outputDir).mkdirs()

        val allDependencies = arrayListOf<IClasspathDependency>()
        allDependencies.addAll(info.dependencies)
        allDependencies.addAll(calculateDependencies(project, context, info.dependencies))
        validateClasspath(allDependencies.map { it.jarFile.get().absolutePath })
        return action.compile(info.copy(dependencies = allDependencies))
    }

    private fun validateClasspath(cp: List<String>) {
        cp.forEach {
            if (! File(it).exists()) {
                throw KobaltException("Couldn't find $it")
            }
        }
    }

    /**
     * @return the classpath for this project, including the IClasspathContributors.
     */
    fun calculateDependencies(project: Project?, context: KobaltContext?,
            vararg allDependencies: List<IClasspathDependency>): List<IClasspathDependency> {
        var result = arrayListOf<IClasspathDependency>()
        allDependencies.forEach { dependencies ->
            result.addAll(dependencyManager.transitiveClosure(dependencies))
        }
        if (project != null) {
            result.addAll(runClasspathContributors(context, project))
        }

        return result
    }

    private fun runClasspathContributors(context: KobaltContext?, project: Project) :
            Collection<IClasspathDependency> {
        val result = arrayListOf<IClasspathDependency>()
        context?.classpathContributors?.forEach {
            result.addAll(it.entriesFor(project))
        }
        return result
    }

}

data class CompilerActionInfo(val dependencies: List<IClasspathDependency>,
        val sourceFiles: List<String>, val outputDir: String, val compilerArgs: List<String>)

interface ICompilerAction {
    fun compile(info: CompilerActionInfo): TaskResult
}<commit_msg>Comment.<commit_after>package com.beust.kobalt.internal

import com.beust.kobalt.api.KobaltContext
import com.beust.kobalt.api.Project
import com.beust.kobalt.maven.DependencyManager
import com.beust.kobalt.maven.IClasspathDependency
import com.beust.kobalt.maven.KobaltException
import com.google.inject.Inject
import java.io.File

/**
 * Abstract the compilation process by running an ICompilerAction parameterized  by a CompilerActionInfo.
 * Also validates the classpath and run all the contributors.
 */
class JvmCompiler @Inject constructor(val dependencyManager: DependencyManager) {
    fun doCompile(project: Project?, context: KobaltContext?, action: ICompilerAction, info: CompilerActionInfo)
            : TaskResult {
        File(info.outputDir).mkdirs()

        val allDependencies = arrayListOf<IClasspathDependency>()
        allDependencies.addAll(info.dependencies)
        allDependencies.addAll(calculateDependencies(project, context, info.dependencies))
        validateClasspath(allDependencies.map { it.jarFile.get().absolutePath })
        return action.compile(info.copy(dependencies = allDependencies))
    }

    private fun validateClasspath(cp: List<String>) {
        cp.forEach {
            if (! File(it).exists()) {
                throw KobaltException("Couldn't find $it")
            }
        }
    }

    /**
     * @return the classpath for this project, including the IClasspathContributors.
     */
    fun calculateDependencies(project: Project?, context: KobaltContext?,
            vararg allDependencies: List<IClasspathDependency>): List<IClasspathDependency> {
        var result = arrayListOf<IClasspathDependency>()
        allDependencies.forEach { dependencies ->
            result.addAll(dependencyManager.transitiveClosure(dependencies))
        }
        if (project != null) {
            result.addAll(runClasspathContributors(context, project))
        }

        return result
    }

    private fun runClasspathContributors(context: KobaltContext?, project: Project) :
            Collection<IClasspathDependency> {
        val result = arrayListOf<IClasspathDependency>()
        context?.classpathContributors?.forEach {
            result.addAll(it.entriesFor(project))
        }
        return result
    }

}

data class CompilerActionInfo(val dependencies: List<IClasspathDependency>,
        val sourceFiles: List<String>, val outputDir: String, val compilerArgs: List<String>)

interface ICompilerAction {
    fun compile(info: CompilerActionInfo): TaskResult
}
{'fraction_non_alphanumeric': 0.08997834219334515, 'fraction_numerical': 0.0, 'mean_word_length': 3.4678979771328056, 'pattern_counts': {'":': 0, '<': 23, '<?xml version=': 0, '>': 25, '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': '6957577', 'n_tokens_mistral': 1389, 'n_tokens_neox': 1319, 'n_words': 285}