diff --git a/Jenkinsfile b/Jenkinsfile index 5286167..12038d2 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -46,25 +46,12 @@ pipeline { 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']}" - } + report['downstream_modules']['L1'] = [:] + projects2artifacts[inputProject].each { a -> report = analyzeDependency(modules2deps, artifacts2projects, report, a, 1)} + println report + printReport(report) - // 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) + } } } } @@ -76,33 +63,43 @@ def findDownstreamDependencies(modules2deps, artifact) { 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 analyzeDependency(modules2deps, artifacts2projects, report, artifact,deep) { + def level = "L${deep}" + report['downstream_modules'][level][artifact] = [ 'dependencies':[], 'projects':[] ] + report['downstream_modules'][level][artifact]['dependencies'].addAll(findDownstreamDependencies(modules2deps, artifact)) + println "${artifact} is used by ${report['downstream_modules'][level][artifact]['dependencies']}" + + // then we look for the projects that build the downstream dependencies + report['downstream_modules'][level][artifact]['dependencies'].each { d -> + report['downstream_modules'][level][artifact]['projects'] << artifacts2projects[d] + report['downstream_projects'] << artifacts2projects[d] + } + report } def printReport(report) { def text = '' - def indent = '' + def indent = '\t' 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" - } - } + report['downstream_modules'].each { deep, artifacts -> + artifacts.each { name, data -> + text += "${indent}Module Name: ${name}\n" + text += "${indent}Dependency Level: ${deep}\n" + text += "${indent}\tDownstream Modules for ${name}\n" + data['dependencies'].each {d -> + text += "${indent}\t\t${d}" + text += "\n" + } + text += "${indent}\tDownstream Projects for ${name}\n" + data['projects'].each { p -> + text += "${indent}\t\t${p}" + text += "\n" + } + } + } + text += "\n\n" text += "All Downstream Projects\n" report['downstream_projects'].each { p -> @@ -111,11 +108,10 @@ def printReport(report) { } 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}")} - } - */ \ No newline at end of file +}