Skip to content

Commit

Permalink
Formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
avantgardnerio committed Oct 30, 2018
1 parent a8a7ece commit 94b5ae0
Showing 1 changed file with 14 additions and 12 deletions.
26 changes: 14 additions & 12 deletions src/main/kotlin/net/squarelabs/depends/Resolver.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,28 @@ import com.google.common.reflect.ClassPath
import net.squarelabs.depends.models.Artifact
import net.squarelabs.depends.models.Class
import org.jboss.shrinkwrap.resolver.api.maven.Maven
import java.io.File
import java.net.URLClassLoader

fun resolve(coordinate: String, cache: HashMap<String, Artifact> = HashMap()): Artifact {
return cache.computeIfAbsent(coordinate) { coordinate ->
return cache.computeIfAbsent(coordinate) {
val artifacts = Maven.resolver()
.resolve(coordinate)
.resolve(it)
.withoutTransitivity()
.asResolvedArtifact()
assert(artifacts.size == 1)
val artifact = artifacts[0]
val file = artifact.asFile()
val classes = URLClassLoader(arrayOf(file.toURL())).use { it ->
println("${cache.size} artifacts + ${file.absolutePath}")
val cp = ClassPath.from(it)
cp.topLevelClasses.map { Class(it.name) }
}
val dependencies: List<Artifact> = artifact.dependencies.map {
//println("resolving ${it.coordinate}")
resolve(it.coordinate.toCanonicalForm(), cache)
}
Artifact(coordinate, file, dependencies, classes)
println("${cache.size} artifacts + ${file.absolutePath}")
val classes = classesFromFile(file)
val dependencies = artifact.dependencies.map { resolve(it.coordinate.toCanonicalForm(), cache) }
Artifact(it, file, dependencies, classes)
}
}

fun classesFromFile(file: File): List<Class> {
return URLClassLoader(arrayOf(file.toURL())).use { it ->
val cp = ClassPath.from(it)
cp.topLevelClasses.map { Class(it.name) }
}
}

0 comments on commit 94b5ae0

Please sign in to comment.