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