Code cleanup, added config.resolve()

This commit is contained in:
Robinson 2021-04-12 23:44:31 +02:00
parent 2d6c2e1b5d
commit 500d6dce3e
2 changed files with 18 additions and 11 deletions

View File

@ -24,6 +24,11 @@ object DependencyScanner {
/** /**
* THIS MUST BE IN "afterEvaluate" or run from a specific task. * THIS MUST BE IN "afterEvaluate" or run from a specific task.
*
* how to resolve dependencies
* NOTE: it is possible, when we have a project DEPEND on an older version of that project (ie: bootstrapped from an older version)
* we can have infinite recursion.
* This is a problem, so we limit how much a dependency can show up the the tree
*/ */
fun scan( fun scan(
project: Project, project: Project,
@ -37,6 +42,8 @@ object DependencyScanner {
return return
} }
config.resolve()
config.resolvedConfiguration.lenientConfiguration.getFirstLevelModuleDependencies(org.gradle.api.specs.Specs.SATISFIES_ALL).forEach { dep -> config.resolvedConfiguration.lenientConfiguration.getFirstLevelModuleDependencies(org.gradle.api.specs.Specs.SATISFIES_ALL).forEach { dep ->
// we know the FIRST series will exist // we know the FIRST series will exist
val makeDepTree = makeDepTree(dep, existingNames) val makeDepTree = makeDepTree(dep, existingNames)
@ -60,16 +67,17 @@ object DependencyScanner {
val version = module.version val version = module.version
if (!existingNames.contains("$group:$name")) { if (!existingNames.contains("$group:$name")) {
existingNames.add("$group:$name")
// println("Searching: $group:$name:$version") // println("Searching: $group:$name:$version")
val artifacts: List<DependencyInfo> = dep.moduleArtifacts.map { artifact: ResolvedArtifact -> val artifacts: List<Artifact> = dep.moduleArtifacts.map { artifact: ResolvedArtifact ->
val artifactModule = artifact.moduleVersion.id val artifactModule = artifact.moduleVersion.id
DependencyInfo(artifactModule.group, artifactModule.name, artifactModule.version, artifact.file.absoluteFile) Artifact(artifactModule.group, artifactModule.name, artifactModule.version, artifact.file.absoluteFile)
} }
val children = mutableListOf<Dependency>() val children = mutableListOf<Dependency>()
dep.children.forEach { dep.children.forEach { child ->
existingNames.add("$group:$name") val makeDep = makeDepTree(child, existingNames)
val makeDep = makeDepTree(it, existingNames)
if (makeDep != null) { if (makeDep != null) {
children.add(makeDep) children.add(makeDep)
} }
@ -102,7 +110,7 @@ object DependencyScanner {
val group: String, val group: String,
val name: String, val name: String,
val version: String, val version: String,
val artifacts: List<DependencyInfo>, val artifacts: List<Artifact>,
val children: List<Dependency> val children: List<Dependency>
) { ) {
@ -115,14 +123,14 @@ object DependencyScanner {
} }
} }
data class DependencyInfo(val group: String, val name: String, val version: String, val file: File) { data class Artifact(val group: String, val name: String, val version: String, val file: File) {
val id: String val id: String
get() { get() {
return "$group:$name:$version" return "$group:$name:$version"
} }
} }
data class MavenData(val group: String, val name: String, val version: String) { data class Maven(val group: String, val name: String, val version: String) {
val id: String val id: String
get() { get() {
return "$group:$name:$version" return "$group:$name:$version"

View File

@ -180,7 +180,7 @@ open class StaticMethodsAndTools(private val project: Project) {
* *
* THIS MUST BE IN "afterEvaluate" or run from a specific task. * THIS MUST BE IN "afterEvaluate" or run from a specific task.
*/ */
fun resolveBuildScriptDependencies(project: Project = this.project): List<DependencyScanner.MavenData> { fun resolveBuildScriptDependencies(project: Project = this.project): List<DependencyScanner.Maven> {
val existingNames = mutableSetOf<String>() val existingNames = mutableSetOf<String>()
return project.buildscript.configurations.flatMap { config -> return project.buildscript.configurations.flatMap { config ->
@ -188,7 +188,6 @@ open class StaticMethodsAndTools(private val project: Project) {
.lenientConfiguration .lenientConfiguration
.getFirstLevelModuleDependencies(Specs.SATISFIES_ALL) .getFirstLevelModuleDependencies(Specs.SATISFIES_ALL)
.mapNotNull { dep -> .mapNotNull { dep ->
val module = dep.module.id val module = dep.module.id
val group = module.group val group = module.group
val name = module.name val name = module.name
@ -197,7 +196,7 @@ open class StaticMethodsAndTools(private val project: Project) {
if (!existingNames.contains(moduleName)) { if (!existingNames.contains(moduleName)) {
existingNames.add(moduleName) existingNames.add(moduleName)
DependencyScanner.MavenData(group, name, version) DependencyScanner.Maven(group, name, version)
} else { } else {
null null
} }