com.github.ferstl.depgraph.dependency.ReactorGraphFactory Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of depgraph-maven-plugin Show documentation
Show all versions of depgraph-maven-plugin Show documentation
This Maven plugin generates dependency graphs on single modules or in an aggregated form
on multi-module projects. The graphs are represented by .dot files. In case that Graphviz
is installed on the machine where this plugin is run, the .dot file can be directly converted
into all supported image files.
package com.github.ferstl.depgraph.dependency;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import org.apache.maven.execution.ProjectDependencyGraph;
import org.apache.maven.project.MavenProject;
import com.github.ferstl.depgraph.graph.GraphBuilder;
public class ReactorGraphFactory implements GraphFactory {
private final ProjectDependencyGraph projectDependencyGraph;
private final GraphBuilder graphBuilder;
private final DependencyNodeIdRenderer nodeIdRenderer;
public ReactorGraphFactory(ProjectDependencyGraph projectDependencyGraph, GraphBuilder graphBuilder, DependencyNodeIdRenderer nodeIdRenderer) {
this.projectDependencyGraph = projectDependencyGraph;
this.graphBuilder = graphBuilder;
this.nodeIdRenderer = nodeIdRenderer;
}
@Override
public String createGraph(MavenProject project) {
// Start at the end of the reactor
List sortedProjects = this.projectDependencyGraph.getSortedProjects();
Collections.reverse(sortedProjects);
Set processedProjects = new HashSet<>();
for (MavenProject parentProject : sortedProjects) {
DependencyNode parentNode = new DependencyNode(parentProject.getArtifact());
for (MavenProject downstreamProject : this.projectDependencyGraph.getDownstreamProjects(parentProject, false)) {
DependencyNode childNode = new DependencyNode(downstreamProject.getArtifact());
String nodeString = this.nodeIdRenderer.render(childNode);
if (!processedProjects.contains(nodeString)) {
this.graphBuilder.addEdge(parentNode, childNode);
}
processedProjects.add(nodeString);
}
}
return this.graphBuilder.toString();
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy