Generate and print the dependency report.

This commit is contained in:
Manuele Simi 2020-03-11 00:21:44 -04:00
parent c36f5e3713
commit 307510c896
1 changed files with 53 additions and 14 deletions

67
Jenkinsfile vendored
View File

@ -4,6 +4,8 @@ def projects2artifacts = [:]
def artifacts2projects = [:] def artifacts2projects = [:]
def modules2deps = [:] def modules2deps = [:]
def inputProject = 'storagehub-client-library' def inputProject = 'storagehub-client-library'
def report = [:]
report['project'] = inputProject
pipeline { pipeline {
agent { agent {
@ -39,20 +41,30 @@ pipeline {
stage('find downstream projects') { stage('find downstream projects') {
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 depends on the project's artifacts (i.e. downstream dependencies)
def downstreamdeps = [:] def downstreamdeps = [:]
projects2artifacts[inputProject].each { a -> report['downstream_modules'] = [:]
downstreamdeps[a] = [] report['downstream_projects'] = []
downstreamdeps[a].addAll(findDownstreamDependencies(modules2deps, a)) projects2artifacts[inputProject].each { a ->
println "${a} is used by ${downstreamdeps[a]}" report['downstream_modules'][a] = [:]
report['downstream_modules'][a]['dependencies'] = []
report['downstream_modules'][a]['projects'] = []
}
projects2artifacts[inputProject].each { a ->
report['downstream_modules'][a]['dependencies'].addAll(findDownstreamDependencies(modules2deps, a))
println "${a} is used by ${report['downstream_modules'][a]['dependencies']}"
}
} // then we look for the projects that build the downstream dependencies
// then we look for the projects that build the downstream dependencies report['downstream_modules'].each { module, deps ->
downstreamdeps.each { k, v -> deps['dependencies'].each { d ->
for (d in v) { println "${d} is build by ${artifacts2projects[d]}" } report['downstream_modules'][module]['projects'] << artifacts2projects[d]
} report['downstream_projects'] << artifacts2projects[d]
} }
}
}
printReport(report)
} }
} }
} }
@ -71,7 +83,34 @@ def findProject(projects2artifacts, artifact) {
name name
} }
def printReport(report) {
def text = ''
def indent = ''
text += "Dependency Report for ${report['project']} (jenkins project)"
text += "\n\n"
text += "Project Modules\n"
indent += '\t'
report['downstream_modules'].each { module, deps ->
text += "${indent}Module Name: ${module}\n"
text += "${indent}\tDownstream Modules for ${module}\n"
deps['dependencies'].each { d ->
text += "${indent}\t\t${d}"
text += "\n"
}
text += "${indent}\tDownstream Projects for ${module}\n"
deps['projects'].each { p ->
text += "${indent}\t\t${p}"
text += "\n"
}
}
text += "\n\n"
text += "All Downstream Projects\n"
report['downstream_projects'].each { p ->
text += "${indent}${p}"
text += "\n"
}
println text
}
/* /*
def printJob(job) { def printJob(job) {
println("fullname ${job.fullName}") println("fullname ${job.fullName}")