<commit_before>package com.beust.kobalt

import com.beust.kobalt.api.IClasspathDependency
import com.beust.kobalt.maven.LocalRepo
import com.beust.kobalt.maven.MavenId
import com.beust.kobalt.maven.aether.AetherDependency
import com.beust.kobalt.maven.aether.Filters
import com.beust.kobalt.maven.aether.KobaltMavenResolver
import com.beust.kobalt.misc.KobaltExecutors
import com.beust.kobalt.misc.Node
import com.beust.kobalt.misc.kobaltLog
import com.google.inject.Inject
import org.eclipse.aether.artifact.DefaultArtifact
import org.eclipse.aether.graph.DependencyNode
import java.util.*

/**
 * Display information about a Maven id.
 */
class ResolveDependency @Inject constructor(
        val localRepo: LocalRepo,
        val aether: KobaltMavenResolver,
        val executors: KobaltExecutors) {
    val increment = 8
    val leftFirst = "\u2558"
    val leftMiddle = "\u255f"
    val leftLast = "\u2559"
    val vertical = "\u2551"

    class Dep(val dep: IClasspathDependency, val level: Int)

    fun run(id: String) = displayDependenciesFor(id)

    private fun latestMavenArtifact(group: String, artifactId: String, extension: String = "jar"): DependencyNode {
        val artifact = DefaultArtifact(group, artifactId, extension, "(0,]")
        val resolved = aether.resolveVersion(artifact)
        if (resolved != null) {
            val newArtifact = DefaultArtifact(artifact.groupId, artifact.artifactId, artifact.extension,
                    resolved.highestVersion.toString())
            val artifactResult = aether.resolve(KobaltMavenResolver.artifactToId(newArtifact), null)
            return artifactResult.root
        } else {
            throw KobaltException("Couldn't find latest artifact for $group:$artifactId")
        }
    }

    class PairResult(val dependency: IClasspathDependency, val repoUrl: String)

    fun latestArtifact(group: String, artifactId: String, extension: String = "jar"): PairResult
            = latestMavenArtifact(group, artifactId, extension).let {
        PairResult(AetherDependency(it.artifact), "(TBD repo)")
    }

    private fun displayDependenciesFor(id: String) {
        val mavenId = MavenId.create(id)
        val resolved : PairResult =
            if (mavenId.hasVersion) {
                val node = aether.resolve(id, filter = Filters.EXCLUDE_OPTIONAL_FILTER)
                PairResult(AetherDependency(node.root.artifact), node.artifactResults[0].repository.id)
            } else {
                latestArtifact(mavenId.groupId, mavenId.artifactId)
            }

        displayDependencies(resolved.dependency, resolved.repoUrl)
    }

    private fun displayDependencies(dep: IClasspathDependency, url: String) {
        val indent = -1
        val root = Node(Dep(dep, indent))
        val seen = hashSetOf(dep.id)
        root.addChildren(findChildren(root, seen))

        kobaltLog(1, AsciiArt.logBox(listOf(dep.id, url, dep.jarFile.get()).map { "          $it" }))

        display(root.children)
        println("")
    }

    private fun display(nodes: List<Node<Dep>>) {
        nodes.withIndex().forEach { indexNode ->
            val node = indexNode.value
            with(node.value) {
                val left =
                        if (indexNode.index == nodes.size - 1) leftLast
                        else leftMiddle
                val indent = level * increment
                for(i in 0..indent - 2) {<commit_msg>Fix URL.<commit_after>package com.beust.kobalt

import com.beust.kobalt.api.IClasspathDependency
import com.beust.kobalt.maven.LocalRepo
import com.beust.kobalt.maven.MavenId
import com.beust.kobalt.maven.aether.AetherDependency
import com.beust.kobalt.maven.aether.Filters
import com.beust.kobalt.maven.aether.KobaltMavenResolver
import com.beust.kobalt.misc.KobaltExecutors
import com.beust.kobalt.misc.Node
import com.beust.kobalt.misc.kobaltLog
import com.google.inject.Inject
import org.eclipse.aether.artifact.DefaultArtifact
import org.eclipse.aether.graph.DependencyNode
import java.util.*

/**
 * Display information about a Maven id.
 */
class ResolveDependency @Inject constructor(
        val localRepo: LocalRepo,
        val aether: KobaltMavenResolver,
        val executors: KobaltExecutors) {
    val increment = 8
    val leftFirst = "\u2558"
    val leftMiddle = "\u255f"
    val leftLast = "\u2559"
    val vertical = "\u2551"

    class Dep(val dep: IClasspathDependency, val level: Int)

    fun run(id: String) = displayDependenciesFor(id)

    private fun latestMavenArtifact(group: String, artifactId: String, extension: String = "jar"): DependencyNode {
        val artifact = DefaultArtifact(group, artifactId, extension, "(0,]")
        val resolved = aether.resolveVersion(artifact)
        if (resolved != null) {
            val newArtifact = DefaultArtifact(artifact.groupId, artifact.artifactId, artifact.extension,
                    resolved.highestVersion.toString())
            val artifactResult = aether.resolve(KobaltMavenResolver.artifactToId(newArtifact), null)
            return artifactResult.root
        } else {
            throw KobaltException("Couldn't find latest artifact for $group:$artifactId")
        }
    }

    class PairResult(val dependency: IClasspathDependency, val repoUrl: String)

    fun latestArtifact(group: String, artifactId: String, extension: String = "jar"): PairResult
            = latestMavenArtifact(group, artifactId, extension).let {
        PairResult(AetherDependency(it.artifact), "(TBD repo)")
    }

    private fun displayDependenciesFor(id: String) {
        val mavenId = MavenId.create(id)
        val resolved : PairResult =
            if (mavenId.hasVersion) {
                val node = aether.resolve(id, filter = Filters.EXCLUDE_OPTIONAL_FILTER)
                PairResult(AetherDependency(node.root.artifact), node.artifactResults[0].repository.toString())
            } else {
                latestArtifact(mavenId.groupId, mavenId.artifactId)
            }

        displayDependencies(resolved.dependency, resolved.repoUrl)
    }

    private fun displayDependencies(dep: IClasspathDependency, url: String) {
        val indent = -1
        val root = Node(Dep(dep, indent))
        val seen = hashSetOf(dep.id)
        root.addChildren(findChildren(root, seen))

        kobaltLog(1, AsciiArt.logBox(listOf(dep.id, url, dep.jarFile.get()).map { "          $it" }))

        display(root.children)
        println("")
    }

    private fun display(nodes: List<Node<Dep>>) {
        nodes.withIndex().forEach { indexNode ->
            val node = indexNode.value
            with(node.value) {
                val left =
                        if (indexNode.index == nodes.size - 1) leftLast
                        else leftMiddle
                val indent = level * increment
                for(i in 0..indent - 2) {
{'fraction_non_alphanumeric': 0.09948867786705624, 'fraction_numerical': 0.006720233747260774, 'mean_word_length': 2.755348326933626, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 9, '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': '2373699', 'n_tokens_mistral': 2114, 'n_tokens_neox': 1953, 'n_words': 427}