Skip to content

Instantly share code, notes, and snippets.

@adinauer
Last active December 21, 2015 00:29
Show Gist options
  • Save adinauer/6220911 to your computer and use it in GitHub Desktop.
Save adinauer/6220911 to your computer and use it in GitHub Desktop.
import groovy.io.FileType
def projectName = /.*topsecret.*/
def searchRegex = args[0]
Map<String,Set<String>> modulesWithDependencies = [:]
new File('/home/adinauer/repos/topsecret').eachFile(FileType.DIRECTORIES) { module ->
def pomFile = new File(module.absolutePath + '/pom.xml')
if (pomFile.exists()) {
def pom = new XmlSlurper().parse(pomFile)
modulesWithDependencies[pom.artifactId.toString()] = [] as Set
def dependencies = pom.dependencies.dependency
dependencies.findAll{it.artifactId ==~ projectName}.each { dependency ->
modulesWithDependencies[pom.artifactId.toString()] << dependency.artifactId.toString()
}
}
}
List<String> graphEntries = []
modulesWithDependencies.findAll { it.key ==~ searchRegex || it.value ==~ searchRegex }.each { module, dependencies ->
dependencies.each { dependency ->
if (module ==~ searchRegex || dependency ==~ searchRegex) {
graphEntries << "\"${module}\" -> \"${dependency}\""
}
}
}
File graphDotFile = new File("tmp.gv")
graphDotFile.withWriter { out ->
out.println 'digraph dependencies {'
out.println 'node [shape = rectangle];'
graphEntries.each {
out.println it
}
out.println '}'
}
// now run
// groovy dependencies.groovy '.*acquisition.*' && dot tmp.gv -Tsvg > tmp.svg
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment