Last active
December 28, 2023 08:22
-
-
Save ulaserdegor/a85ac75a41a437e724aab5242708b183 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
tasks.register('featuresGamehubDependencyGraph') { | |
doLast { | |
def dot = new File(rootProject.buildDir, 'reports/dependency-graph/project.dot') | |
dot.parentFile.mkdirs() | |
dot.delete() | |
def rootProjectPath = ':features:gamehub' | |
dot << 'digraph {\n' | |
dot << " graph [label=\"${rootProjectPath}\\n \",labelloc=t,fontsize=30,ranksep=1.4];\n" | |
dot << ' node [style=filled, fillcolor="#8F21BB"];\n' | |
dot << ' rankdir=TR;\n' | |
def rootProject = project(rootProjectPath) | |
def projects = new LinkedHashSet<Project>() | |
def dependencies = new LinkedHashMap<Tuple2<Project, Project>, List<String>>() | |
def queue = [rootProject] | |
while (!queue.isEmpty()) { | |
def project = queue.remove(0) | |
queue.addAll(project.childProjects.values()) | |
project.configurations.configureEach { config -> | |
config.dependencies | |
.withType(ProjectDependency) | |
.collect { it.dependencyProject } | |
.each { dependency -> | |
if (project != dependency) { | |
projects.add(project) | |
projects.add(dependency) | |
def graphKey = new Tuple2<Project, Project>(project, dependency) | |
def traits = dependencies.computeIfAbsent(graphKey) { new ArrayList<String>() } | |
if (project.path == rootProjectPath || project == rootProject) { | |
traits.add('style=invis') | |
} else if (config.name.toLowerCase().endsWith('implementation')) { | |
traits.add('style=dotted') | |
} else if (config.name.toLowerCase().endsWith('api')) { | |
traits.add('color=green') | |
} else { | |
//traits.add('color=green') | |
} | |
} | |
} | |
} | |
} | |
projects = projects.sort { it.path } | |
dot << '\n # Projects\n\n' | |
for (project in projects) { | |
def traits = [] | |
if (project == rootProject) { | |
traits.add('shape=box') | |
} | |
if (!dependencies.keySet().findAll { it.first() == project }) { | |
traits.add('fillcolor="#FF0000"') // Bağımlılığı yok | |
} else { | |
traits.add('fillcolor="#FFD700"') // Bağımlılığı var | |
} | |
dot << " \"${project.path}\" [${traits.join(", ")}];\n" | |
} | |
dot << '\n {rank = same;' | |
for (project in projects) { | |
if (project == rootProject) { | |
dot << " \"${project.path}\";" | |
} | |
} | |
dot << '}\n' | |
dot << '\n # Dependencies\n\n' | |
dependencies.forEach { key, traits -> | |
dot << " \"${key.first().path}\" -> \"${key.get(1).path}\"" | |
if (!traits.isEmpty()) { | |
if (traits.contains('style=dotted')) { | |
dot << " [color=red, ${traits.join(", ")}]" | |
} else { | |
dot << " [${traits.join(", ")}]" | |
} | |
} | |
dot << '\n' | |
} | |
dot << '}\n' | |
def p = 'dot -Tpng -O project.dot'.execute([], dot.parentFile) | |
p.waitFor() | |
if (p.exitValue() != 0) { | |
throw new RuntimeException(p.errorStream.text) | |
} | |
println("Project module dependency graph created at ${dot.absolutePath}.png") | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment