121 lines
4.6 KiB
Groovy
121 lines
4.6 KiB
Groovy
|
|
def counts = 0
|
|
def projects2artifacts = [:]
|
|
def artifacts2projects = [:]
|
|
def modules2deps = [:]
|
|
def inputProject = 'storagehub-client-library'
|
|
def report = [:]
|
|
report['project'] = inputProject
|
|
|
|
pipeline {
|
|
agent {
|
|
label 'CD'
|
|
}
|
|
stages {
|
|
stage('walking projects') {
|
|
steps {
|
|
script {
|
|
Jenkins.getInstance().getAllItems(TopLevelItem.class).each { p ->
|
|
projects2artifacts[p.name] = []
|
|
p.getAllJobs().each { j -> projects2artifacts[p.name] << j.name; artifacts2projects[j.name] = p.name }
|
|
}
|
|
println "FOUND ${projects2artifacts.size()} projects"
|
|
projects2artifacts.each { k,v -> println ("PROJECT ${k} BUILDS ${v}") }
|
|
}
|
|
}
|
|
}
|
|
stage('walking maven modules') {
|
|
steps {
|
|
script {
|
|
// get all the maven modules and their dependencies
|
|
Jenkins.getInstance().getAllItems(hudson.maven.MavenModule.class).each { m ->
|
|
modules2deps[m.name] = []
|
|
m.getDependencies().each { d -> modules2deps[m.name] << "${d.groupId}:${d.artifactId}" }
|
|
}
|
|
println "FOUND ${modules2deps.size()} modules"
|
|
//modules2deps.each { k,v -> println ("MODULE ${k} DEPENDS on ${v}") }
|
|
}
|
|
}
|
|
}
|
|
|
|
stage('find downstream projects') {
|
|
steps {
|
|
script {
|
|
println "PROJECT ${inputProject} BUILDS ${projects2artifacts[inputProject]} artifacts"
|
|
// first, let's find out what components depends on the project's artifacts (i.e. downstream dependencies)
|
|
def downstreamdeps = [:]
|
|
report['downstream_modules'] = [:]
|
|
report['downstream_projects'] = []
|
|
projects2artifacts[inputProject].each { 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
|
|
report['downstream_modules'].each { module, deps ->
|
|
deps['dependencies'].each { d ->
|
|
report['downstream_modules'][module]['projects'] << artifacts2projects[d]
|
|
report['downstream_projects'] << artifacts2projects[d]
|
|
}
|
|
}
|
|
}
|
|
printReport(report)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
def findDownstreamDependencies(modules2deps, artifact) {
|
|
def downdeps = []
|
|
println "Looking for users of ${artifact}"
|
|
modules2deps.each { k,v -> if (v.contains("${artifact}")) downdeps << k }
|
|
downdeps
|
|
}
|
|
|
|
def findProject(projects2artifacts, artifact) {
|
|
println "Looking for project that builds ${artifact}"
|
|
def name = ""
|
|
projects2artifacts.each { k,v -> if (v.contains("${artifact}")) name = k }
|
|
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) {
|
|
println("fullname ${job.fullName}")
|
|
println("name ${job.name}")
|
|
println("display name ${job.displayName}")
|
|
job.getAllJobs().each {j -> println ("dep: ${j.name}")}
|
|
}
|
|
*/ |