DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Newsletter
Log In / Join
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Related

  • Building an AI-Powered Code Review Assistant in Java
  • Modernizing a Legacy Java Application With OpenRewrite: What We Automated and What We Didn't
  • From Database Changes to Real-Time Actions at Scale: Oracle GoldenGate and Java
  • Java 27 Makes G1 the Default Everywhere: How to Test Your Small Containers Before You Upgrade

Trending

  • Save To Bookmarks/Favorites
  • A Software Factory on Kubernetes: Gemini Builds, jev Decides (Genkit + senro in Go)
  • Introduction to Error Prone: How to Catch Bugs at Compile Time
  • DZone's Article Types

Draft This article hasn't been published, so readers can't see it.

In moderation This article is waiting for review, so readers can't see it yet.

Deleted This article has been deleted, so readers can't see it.

  1. DZone
  2. Coding
  3. Java
  4. Visualizing and Analyzing Java Dependency Graph with Gephi

Visualizing and Analyzing Java Dependency Graph with Gephi

Gephi comes with tools to analyse properties of a graph.

By 
Peter Huber
·
Sep. 23, 14 · Tutorial
Post on X (opens in a new tab) Share on LinkedIn (opens in a new tab)
32.2K Views

Join the DZone community Save articles, join the discussion, and download Refcards and Trend Reports with a free account.

Join for free Already a member? Log in

In my daily job I'm often involved in code/architecture review projects and thus always interested in the latest fancy tools for visualizing certain structural aspects of software. Then last year I did this marvelous Coursera MOOC called Social Network Analysis  which requires participants to do a little project to get the certificate. And so I thought, well, okay, let's try to use Gephi, a nice graph visualization platform which we were using throughout the MOOC, and apply it to java software namely JUnit...

What makes this approach interesting appart from being a nice leisure project? Gephi comes with tools to analyse properties of a graph, for instance you can compute certain metrics of nodes like Betweenness Centrality  and compare it to a random Erdős–Rényi model  of a graph

Astonishingly enough Gephi comes with an example of a full graph of package dependencies of some JDK but actually there's neither a built in function or plugin to read in package dependencies from a java project. This is why I wrote a little python script for the Gephi Scripting Console which allows me to process JDepends  XML output.

Following Picture shows Gephis "Overview" view with JUnit already loaded and the Nodes Partitioned (colored) by their Abstractness (Parameter "A") which was imported from JDepends XML output.


Okay... here's what I did - Check out my Github repository https://github.com/huberp/graph_sourcecode_analysis

The Workflow steps to produce a Package graph in Gephi is:

  1. Prerequisites: You have chosen your favorite Java(tm) IDE and installed the JDepend plugin. I use eclipse as my favorite IDE
  2. Run JDepend on your project.
  3. Export JDepend output as XML file, let's name it <jdepend.xml>. I have included an example for such an XML created from JUnit(tm). check out folder /examples
  4. Git Clone this repository to your local machine, let's say to folder <yourpath>
  5. Open the file jdepend-xml-to-nodes_and_edges.py
  6. Edit the line which starts with
    • cfg_yourJDependInputFile =. Point the value to your file <jdepend.xml> including the full path. Save it!
    • cfg_stripCommonBasePackage. Create a list of Package prefixes which will be stripped of in order to make the lables shorter. Note: The full qualified package name is still available in column package. In my JUnit example I've used ["org.junit.","junit."]
  7. Open Gephi and create a new Project
  8. In Gephi - Change to Datalaboratory View and open the Scripting Console (somewhere on the left side)
  9. Now type into the Scripting Console Window: execfile("<yourpath>\\jdepend-xml-to-nodes_and_edges.py") and press <Enter>. Note: Please use double backslash on Windows, e.g. execfile("D:\\temp\\jdepend-xml-to-nodes_and_edges.py")
  10. Hopefully the script runs without errors. Checkout both the Nodes and the Edges Tab of the Datalaboratory View. It should be populated with entries now.
  11. Now you're ready to switch to Gephis' Overview View and checkout the dependency graph.
  12. Finally it's time to figure out what Gephi can do:
    • Try out several Layout Algorithms.
    • Go and compute Graph Metrics like for instance Eccentrisity.
    • Colour your nodes by Partition Parameter

Some Experiments

I created the first Version of this script back in 2013 for the Peer Project of the Coursera MOOC Social Network Analysis. I have included my report in this repository which contains some analysis for JUnit showing that JUnit has, well, a Architecture that is close to a very random Erd?s–Rényi Graph...;-)

Here's some files for you:

  • As a shortcut I have included a .gephi graph file for Junit, ready for you to do some experiments. Check out <yourpath>/examples/junit/junit_as_graph.gephi
  • Here's my report for the Social Network Analysis MOOC: Report
    It describes the whole forkflow and does some analysis on JUnit. It shows that actually Junits Architecture has seen from a metrics perspective only resemblance to a random graph. One might conclude that the process of "designing an architecture" should provide a different picture...
  • And this is are visualisations of JUnit (2nd is the "Preview" View of the Abstractness-Ranking which has been shown above)

Dependency graph Gephi Java (programming language)

Opinions expressed by DZone contributors are their own.

Related

  • Building an AI-Powered Code Review Assistant in Java
  • Modernizing a Legacy Java Application With OpenRewrite: What We Automated and What We Didn't
  • From Database Changes to Real-Time Actions at Scale: Oracle GoldenGate and Java
  • Java 27 Makes G1 the Default Everywhere: How to Test Your Small Containers Before You Upgrade

Partner Resources

×

Comments

Loading comments

The comments didn't load

Please try again in a moment.

Likes

Loading

The next likes didn't load. Please try again.

The likes didn't load

Please try again in a moment.

See who liked this

Log in or join DZone for free to see who liked this article.

Log in Join for free
  • RSS
  • X
  • Facebook

ABOUT US

  • About DZone
  • Support and feedback
  • Community research

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 215
  • Nashville, TN 37211
  • [email protected]

Let's be friends:

  • RSS
  • X
  • Facebook