Skip the artifact if already in the report.
This commit is contained in:
parent
a4adba12b4
commit
f2c0881f7d
|
@ -1,6 +1,7 @@
|
|||
def projects2artifacts = [:]
|
||||
def artifacts2projects = [:]
|
||||
def modules2deps = [:]
|
||||
def alreadyInTheTree = []
|
||||
def inputProject = params.jenkins_project
|
||||
def report = [:]
|
||||
report['project'] = inputProject
|
||||
|
@ -54,7 +55,7 @@ pipeline {
|
|||
report['downstream_modules']['L1'] = [:]
|
||||
projects2artifacts[inputProject].each { a ->
|
||||
if (a.split(':').length > 1) { //skip the parent (only groupId)
|
||||
report = analyzeDependency(modules2deps, artifacts2projects, report, a, 1) }
|
||||
report = analyzeDependency(modules2deps, alreadyInTheTree, artifacts2projects, report, a, 1) }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -79,27 +80,34 @@ def findDownstreamDependencies(modules2deps, artifact) {
|
|||
}
|
||||
|
||||
//build the report of the given dependency, go recursive on its dependencies
|
||||
def analyzeDependency(modules2deps, artifacts2projects, report, artifact, depth) {
|
||||
def analyzeDependency(modules2deps, alreadyInTheTree, artifacts2projects, report, artifact, depth) {
|
||||
def level = "L${depth}"
|
||||
report['downstream_modules'][level][artifact] = ['dependencies': [], 'projects': []]
|
||||
def downdeps = findDownstreamDependencies(modules2deps, artifact)
|
||||
def skipTree = !alreadyInTheTree.contains(artifact)
|
||||
if (!skipTree) {
|
||||
report['downstream_modules'][level][artifact] = ['dependencies': [], 'projects': []]
|
||||
|
||||
// get all downstream dependencies
|
||||
report['downstream_modules'][level][artifact]['dependencies'].addAll(findDownstreamDependencies(modules2deps, artifact))
|
||||
//println "${artifact} is used by ${report['downstream_modules'][level][artifact]['dependencies']}"
|
||||
// get all downstream dependencies
|
||||
report['downstream_modules'][level][artifact]['dependencies'].addAll(downdeps)
|
||||
//println "${artifact} is used by ${report['downstream_modules'][level][artifact]['dependencies']}"
|
||||
|
||||
// add the project that builds the artifact
|
||||
report['downstream_modules'][level][artifact]['projects'] << artifacts2projects[artifact]
|
||||
report['downstream_projects'] << artifacts2projects[artifact]
|
||||
// add the project that builds the artifact
|
||||
report['downstream_modules'][level][artifact]['projects'] << artifacts2projects[artifact]
|
||||
report['downstream_projects'] << artifacts2projects[artifact]
|
||||
alreadyInTheTree << artifact
|
||||
}
|
||||
|
||||
// then we look for the projects that build the downstream dependencies and finally we go recursive
|
||||
if (report['downstream_modules'][level][artifact]['dependencies']) {
|
||||
if (downdeps) {
|
||||
def nextDepth = ++depth
|
||||
report['downstream_modules']["L${nextDepth}"] = [:]
|
||||
report['downstream_modules'][level][artifact]['dependencies'].each { d ->
|
||||
report['downstream_modules'][level][artifact]['projects'] << artifacts2projects[d]
|
||||
report['downstream_projects'] << artifacts2projects[d]
|
||||
downdeps.each { d ->
|
||||
if (!skipTree) {
|
||||
report['downstream_modules'][level][artifact]['projects'] << artifacts2projects[d]
|
||||
report['downstream_projects'] << artifacts2projects[d]
|
||||
}
|
||||
// go recursive
|
||||
analyzeDependency(modules2deps, artifacts2projects, report, d, nextDepth)
|
||||
analyzeDependency(modules2deps, alreadyInTheTree, artifacts2projects, report, d, nextDepth)
|
||||
}
|
||||
}
|
||||
report
|
||||
|
|
Loading…
Reference in New Issue