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
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Related

  • Detecting Bugs and Vulnerabilities in Java With SonarQube
  • Introduction to Tactical DDD With Java: Steps to Build Semantic Code
  • AI Agents in Java: Architecting Intelligent Health Data Systems
  • OpenAPI From Code With Spring and Java: A Recipe for Your CI

Trending

  • From APIs to Actions: Rethinking Back-End Design for Agents
  • OpenAPI From Code With Spring and Java: A Recipe for Your CI
  • Key Takeaways From Integrating a RAG Application With LangSmith
  • Why Good Models Fail After Deployment
  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 user avatar
Peter Huber
·
Sep. 23, 14 · Tutorial
Likes (2)
Comment
Save
Tweet
Share
31.8K Views

Join the DZone community and get the full member experience.

Join For Free

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

  • Detecting Bugs and Vulnerabilities in Java With SonarQube
  • Introduction to Tactical DDD With Java: Steps to Build Semantic Code
  • AI Agents in Java: Architecting Intelligent Health Data Systems
  • OpenAPI From Code With Spring and Java: A Recipe for Your CI

Partner Resources

×

Comments

The likes didn't load as expected. Please refresh the page and try again.

  • 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