diff --git a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/internal/DynamicGraph.kt b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/internal/DynamicGraph.kt index ec31422f..2b1f3c2f 100644 --- a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/internal/DynamicGraph.kt +++ b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/internal/DynamicGraph.kt @@ -65,15 +65,18 @@ class DynamicGraph { } } - fun transitiveClosureGraph(roots: List, childrenFor: (T) -> List) : List> - = roots.map { transitiveClosureGraph(it, childrenFor) } + fun transitiveClosureGraph(roots: List, childrenFor: (T) -> List, + filter: (T) -> Boolean): List> + = roots.map { transitiveClosureGraph(it, childrenFor, filter) } - fun transitiveClosureGraph(root: T, childrenFor: (T) -> List, seen: HashSet = hashSetOf()) : Node { + fun transitiveClosureGraph(root: T, childrenFor: (T) -> List, + filter: (T) -> Boolean = { t: T -> true }, + seen: HashSet = hashSetOf()) : Node { val children = arrayListOf>() - childrenFor(root).forEach { child -> + childrenFor(root).filter(filter).forEach { child -> if (! seen.contains(child)) { seen.add(child) - val c = transitiveClosureGraph(child, childrenFor, seen) + val c = transitiveClosureGraph(child, childrenFor, filter, seen) children.add(c) } } diff --git a/src/main/kotlin/com/beust/kobalt/app/remote/RemoteDependencyData.kt b/src/main/kotlin/com/beust/kobalt/app/remote/RemoteDependencyData.kt index 74beb0f5..667d79af 100644 --- a/src/main/kotlin/com/beust/kobalt/app/remote/RemoteDependencyData.kt +++ b/src/main/kotlin/com/beust/kobalt/app/remote/RemoteDependencyData.kt @@ -67,20 +67,21 @@ class RemoteDependencyData @Inject constructor(val executors: KobaltExecutors, v children = node.children.map { toDependencyData2(scope, it) }) } + val OPTIONAL_FILTER = { dep: IClasspathDependency -> ! dep.optional } + fun compileDependenciesGraph(project: Project, name: String): List { val depLambda = IClasspathDependency::directDependencies val result = - (DynamicGraph.Companion.transitiveClosureGraph(pluginDependencies, depLambda) + - DynamicGraph.Companion.transitiveClosureGraph(project.compileDependencies, depLambda) + - DynamicGraph.Companion.transitiveClosureGraph(project.compileProvidedDependencies, depLambda)) + (DynamicGraph.Companion.transitiveClosureGraph(pluginDependencies, depLambda, OPTIONAL_FILTER) + + DynamicGraph.Companion.transitiveClosureGraph(project.compileDependencies, depLambda, + OPTIONAL_FILTER) + + DynamicGraph.Companion.transitiveClosureGraph(project.compileProvidedDependencies, depLambda, + OPTIONAL_FILTER)) .map { toDependencyData2("compile", it)} fun mapOfLatestVersions(l: List) : Map { - fun p(l: List, latestVersions: HashMap) { + fun p(l: List, latestVersions: java.util.HashMap) { l.forEach { - if (it.id.contains("squareup:okio")) { - println("DONOTCOMMIT") - } val mid = MavenId.create(it.id) val shortId = mid.artifactId + ":" + mid.artifactId val currentLatest = latestVersions[shortId] @@ -114,7 +115,7 @@ class RemoteDependencyData @Inject constructor(val executors: KobaltExecutors, v fun testDependenciesGraph(project: Project, name: String): List { val depLambda = { dep : IClasspathDependency -> dep.directDependencies() } - return DynamicGraph.Companion.transitiveClosureGraph(project.testDependencies, depLambda) + return DynamicGraph.Companion.transitiveClosureGraph(project.testDependencies, depLambda, OPTIONAL_FILTER) .map { toDependencyData2("testCompile", it)} }