Polish and reformat the code.
This commit is contained in:
parent
4af8c62144
commit
de2fba08b8
|
@ -1,5 +1,3 @@
|
||||||
|
|
||||||
def counts = 0
|
|
||||||
def projects2artifacts = [:]
|
def projects2artifacts = [:]
|
||||||
def artifacts2projects = [:]
|
def artifacts2projects = [:]
|
||||||
def modules2deps = [:]
|
def modules2deps = [:]
|
||||||
|
@ -49,12 +47,12 @@ pipeline {
|
||||||
steps {
|
steps {
|
||||||
script {
|
script {
|
||||||
// println "PROJECT ${inputProject} BUILDS ${projects2artifacts[inputProject]} artifacts"
|
// println "PROJECT ${inputProject} BUILDS ${projects2artifacts[inputProject]} artifacts"
|
||||||
// first, let's find out what components depends on the project's artifacts (i.e. downstream dependencies)
|
// first, let's find out what components depend on the project's artifacts (i.e. downstream dependencies)
|
||||||
def downstreamdeps = [:]
|
def downstreamdeps = [:]
|
||||||
report['downstream_modules'] = [:]
|
report['downstream_modules'] = [:]
|
||||||
report['downstream_projects'] = []
|
report['downstream_projects'] = []
|
||||||
report['downstream_modules']['L1'] = [:]
|
report['downstream_modules']['L1'] = [:]
|
||||||
projects2artifacts[inputProject].each { a -> report = analyzeDependency(modules2deps, artifacts2projects, report, a, 1)}
|
projects2artifacts[inputProject].each { a -> report = analyzeDependency(modules2deps, artifacts2projects, report, a, 1) }
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -74,14 +72,14 @@ pipeline {
|
||||||
def findDownstreamDependencies(modules2deps, artifact) {
|
def findDownstreamDependencies(modules2deps, artifact) {
|
||||||
def downdeps = []
|
def downdeps = []
|
||||||
//println "Looking for users of ${artifact}"
|
//println "Looking for users of ${artifact}"
|
||||||
modules2deps.each { k,v -> if (v.contains("${artifact}")) downdeps << k }
|
modules2deps.each { k, v -> if (v.contains("${artifact}")) downdeps << k }
|
||||||
downdeps
|
downdeps
|
||||||
}
|
}
|
||||||
|
|
||||||
//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, deep) {
|
def analyzeDependency(modules2deps, artifacts2projects, report, artifact, depth) {
|
||||||
def level = "L${deep}"
|
GString level = "L${depth}"
|
||||||
report['downstream_modules'][level][artifact] = [ 'dependencies':[], 'projects':[] ]
|
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(findDownstreamDependencies(modules2deps, artifact))
|
||||||
|
@ -93,13 +91,13 @@ def analyzeDependency(modules2deps, artifacts2projects, report, artifact, deep)
|
||||||
|
|
||||||
// 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 (report['downstream_modules'][level][artifact]['dependencies']) {
|
||||||
def nextDeep = ++deep
|
def nextDepth = ++depth
|
||||||
report['downstream_modules']["L${nextDeep}"] = [:]
|
report['downstream_modules']["L${nextDeep}"] = [:]
|
||||||
report['downstream_modules'][level][artifact]['dependencies'].each { d ->
|
report['downstream_modules'][level][artifact]['dependencies'].each { d ->
|
||||||
report['downstream_modules'][level][artifact]['projects'] << artifacts2projects[d]
|
report['downstream_modules'][level][artifact]['projects'] << artifacts2projects[d]
|
||||||
report['downstream_projects'] << artifacts2projects[d]
|
report['downstream_projects'] << artifacts2projects[d]
|
||||||
// go recursive
|
// go recursive
|
||||||
analyzeDependency(modules2deps, artifacts2projects, report, d, nextDeep)
|
analyzeDependency(modules2deps, artifacts2projects, report, d, nextDepth)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
report
|
report
|
||||||
|
@ -107,23 +105,23 @@ def analyzeDependency(modules2deps, artifacts2projects, report, artifact, deep)
|
||||||
|
|
||||||
// print the final report
|
// print the final report
|
||||||
def printReport(report) {
|
def printReport(report) {
|
||||||
def text = ''
|
GString text = ''
|
||||||
def indent = '\t'
|
String indent = '\t'
|
||||||
text += "Dependency Report for ${report['project']} (jenkins project)"
|
text += "Dependency Report for ${report['project']} (jenkins project)"
|
||||||
text += "\n\n"
|
text += "\n\n"
|
||||||
text += "|--Project Maven Modules\n"
|
text += "|--Project Maven Modules\n"
|
||||||
report['downstream_modules'].each { deep, artifacts ->
|
report['downstream_modules'].each { depth, artifacts ->
|
||||||
artifacts.each { name, data ->
|
artifacts.each { name, data ->
|
||||||
text += "${indent}|--Module: ${name}\n"
|
text += "${indent}|--Module: ${name}\n"
|
||||||
text += "${indent*2}|--Dependency Level: ${deep}\n"
|
text += "${indent * 2}|--Dependency Level: ${depth}\n"
|
||||||
text += "${indent*2}|--Used by (Maven Modules)\n"
|
text += "${indent * 2}|--Used by (Maven Modules)\n"
|
||||||
data['dependencies'].each {d ->
|
data['dependencies'].each { d ->
|
||||||
text += "${indent*3}|--${d}"
|
text += "${indent * 3}|--${d}"
|
||||||
text += "\n"
|
text += "\n"
|
||||||
}
|
}
|
||||||
text += "${indent*2}|--Referred by (Jenkins Projects)\n"
|
text += "${indent * 2}|--Referred by (Jenkins Projects)\n"
|
||||||
data['projects'].each { p ->
|
data['projects'].each { p ->
|
||||||
text += "${indent*3}|--${p}"
|
text += "${indent * 3}|--${p}"
|
||||||
text += "\n"
|
text += "\n"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -143,5 +141,5 @@ def printJob(job) {
|
||||||
println("fullname ${job.fullName}")
|
println("fullname ${job.fullName}")
|
||||||
println("name ${job.name}")
|
println("name ${job.name}")
|
||||||
println("display name ${job.displayName}")
|
println("display name ${job.displayName}")
|
||||||
job.getAllJobs().each {j -> println ("dep: ${j.name}")}
|
job.getAllJobs().each { j -> println("dep: ${j.name}") }
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue