Last active
December 12, 2015 09:09
-
-
Save jarek-przygodzki/4749487 to your computer and use it in GitHub Desktop.
Visualize the output of JarAnalyzer as directed graph
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
@Grapes([ | |
@Grab(group='net.sf.jung', module='jung2', version='2.0.1'), | |
@Grab(group='net.sf.jung', module='jung-algorithms', version='2.0.1'), | |
@Grab(group='net.sf.jung', module='jung-visualization', version='2.0.1'), | |
@Grab(group='net.sf.jung', module='jung-graph-impl', version='2.0.1')]) | |
import java.awt.* | |
import javax.swing.* | |
import edu.uci.ics.jung.graph.* | |
import edu.uci.ics.jung.algorithms.layout.* | |
import edu.uci.ics.jung.visualization.* | |
import edu.uci.ics.jung.visualization.decorators.* | |
import edu.uci.ics.jung.visualization.control.* | |
import edu.uci.ics.jung.visualization.renderers.Renderer as JungRenderer | |
def rootNode = new XmlSlurper().parse(new File('/tmp/hibernate-release-4.1.9.Final.xml')) | |
def jars = rootNode.Jars.Jar.collect() | |
def g = new DirectedSparseGraph() | |
int edgeIndex = 0 | |
jars.each { | |
def name = it.@name.text() | |
def incomingDependencies = it.Summary.IncomingDependencies.Jar.collect { it.text() } | |
def outgoingDependencies = it.Summary.OutgoingDependencies.Jar.collect { it.text() } | |
if(!g.containsVertex(name)) { | |
g.addVertex(name) | |
} | |
for(outd in outgoingDependencies) { | |
if(!g.findEdge(name, outd)) { | |
g.addEdge(edgeIndex++, name, outd) | |
} | |
} | |
} | |
vs = new VisualizationViewer(new ISOMLayout(g), new Dimension(1280, 800)) | |
def graphMouse = new DefaultModalGraphMouse() | |
vs.setGraphMouse(graphMouse) | |
graphMouse.setMode(ModalGraphMouse.Mode.PICKING) | |
vs.getRenderContext().setVertexLabelTransformer(new ToStringLabeller()) | |
vs.getRenderContext().setLabelOffset(20) | |
//vs.getRenderer().getVertexLabelRenderer().setPosition(JungRenderer.VertexLabel.Position.CNTR) | |
def frame = new JFrame() | |
frame.with { | |
getContentPane().add(vs) | |
setDefaultCloseOperation(EXIT_ON_CLOSE) | |
pack() | |
setVisible(true) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment