mirror of
https://github.com/ethauvin/kobalt.git
synced 2025-04-26 08:27:12 -07:00
--resolve.
This commit is contained in:
parent
46eb67f668
commit
11c16b0ed1
4 changed files with 84 additions and 4 deletions
|
@ -39,6 +39,9 @@ class Args {
|
|||
@Parameter(names = arrayOf("--port"), description = "Port, if --server was specified")
|
||||
var port: Int = DEFAULT_SERVER_PORT
|
||||
|
||||
@Parameter(names = arrayOf("--resolve"), description = "Resolve the given dependency and display its tree")
|
||||
var dependency: String? = null
|
||||
|
||||
@Parameter(names = arrayOf("--server"), description = "Run in server mode")
|
||||
var serverMode: Boolean = false
|
||||
|
||||
|
|
|
@ -43,9 +43,10 @@ class AsciiArt {
|
|||
bl + r(s.length + 2, h) + br)
|
||||
}
|
||||
|
||||
fun logBox(s: String) {
|
||||
val defaultLog : (s: String) -> Unit = { log(1, " $it") }
|
||||
fun logBox(s: String, print: (String) -> Unit = defaultLog) {
|
||||
box(s).forEach {
|
||||
log(1, " $it")
|
||||
print(it)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -57,7 +57,8 @@ private class Main @Inject constructor(
|
|||
val client: KobaltClient,
|
||||
val server: KobaltServer,
|
||||
val pluginInfo: PluginInfo,
|
||||
val projectGenerator: ProjectGenerator) {
|
||||
val projectGenerator: ProjectGenerator,
|
||||
val resolveDependency: ResolveDependency) {
|
||||
|
||||
data class RunInfo(val jc: JCommander, val args: Args)
|
||||
|
||||
|
@ -140,6 +141,9 @@ private class Main @Inject constructor(
|
|||
jc.usage()
|
||||
} else if (args.serverMode) {
|
||||
server.run()
|
||||
} else if (args.dependency != null) {
|
||||
// --resolve
|
||||
resolveDependency.run(args.dependency as String)
|
||||
} else {
|
||||
if (! buildFile.exists()) {
|
||||
error(buildFile.path.toFile().path + " does not exist")
|
||||
|
@ -199,4 +203,3 @@ private class Main @Inject constructor(
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
73
src/main/kotlin/com/beust/kobalt/ResolveDependency.kt
Normal file
73
src/main/kotlin/com/beust/kobalt/ResolveDependency.kt
Normal file
|
@ -0,0 +1,73 @@
|
|||
package com.beust.kobalt
|
||||
|
||||
import com.beust.kobalt.maven.*
|
||||
import com.beust.kobalt.misc.Node
|
||||
import com.beust.kobalt.misc.log
|
||||
import com.google.inject.Inject
|
||||
import java.util.*
|
||||
|
||||
/**
|
||||
* Display information about a Maven id.
|
||||
*/
|
||||
class ResolveDependency @Inject constructor(val repoFinder: RepoFinder) {
|
||||
val increment = 4
|
||||
val leftFirst = "\u2558"
|
||||
val leftMiddle = "\u255f"
|
||||
val leftLast = "\u2559"
|
||||
val vertical = "\u2551"
|
||||
|
||||
class Dep(val dep: IClasspathDependency, val indent: Int)
|
||||
|
||||
fun run(id: String) {
|
||||
val indent = 0
|
||||
val dep = MavenDependency.create(id)
|
||||
val root = Node(Dep(dep, indent))
|
||||
val seen = hashSetOf<String>(id)
|
||||
root.addChildren(findChildren(root, seen))
|
||||
val repoResult = repoFinder.findCorrectRepo(id)
|
||||
AsciiArt.logBox(id, {s -> println(s) })
|
||||
val simpleDep = SimpleDep(MavenId(id))
|
||||
|
||||
println("Full URL: " + repoResult.repoUrl + simpleDep.toJarFile(repoResult))
|
||||
display(listOf(root))
|
||||
}
|
||||
|
||||
private fun fill(n: Int) = StringBuffer().apply { repeat(n, { append(" ")})}.toString()
|
||||
|
||||
private fun display(nodes: List<Node<Dep>>) {
|
||||
nodes.withIndex().forEach { indexNode ->
|
||||
val node = indexNode.value
|
||||
println(fill(node.value.indent) + node.value.dep.id)
|
||||
display(node.children)
|
||||
// with(node.value) {
|
||||
// val left =
|
||||
// if (indexNode.index == nodes.size - 1) leftLast
|
||||
// else leftMiddle
|
||||
// for(i in 0..indent - increment) {
|
||||
// if (i % increment == 0) print(vertical)
|
||||
// else print(" ")
|
||||
// }
|
||||
// println(left + " " + dep.id)
|
||||
// display(node.children)
|
||||
// }
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private fun findChildren(root: Node<Dep>, seen: HashSet<String>): List<Node<Dep>> {
|
||||
val result = arrayListOf<Node<Dep>>()
|
||||
root.value.dep.directDependencies().forEach {
|
||||
if (! seen.contains(it.id)) {
|
||||
val dep = Dep(it, root.value.indent + increment)
|
||||
val node = Node(dep)
|
||||
log(2, "Found dependency ${dep.dep.id} indent: ${dep.indent}")
|
||||
result.add(node)
|
||||
seen.add(it.id)
|
||||
node.addChildren(findChildren(node, seen))
|
||||
}
|
||||
}
|
||||
log(2, "Children for ${root.value.dep.id}: ${result.size}")
|
||||
return result
|
||||
}
|
||||
}
|
||||
|
Loading…
Add table
Add a link
Reference in a new issue