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
Please enter at least three characters to search
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Zones

Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks

Because the DevOps movement has redefined engineering responsibilities, SREs now have to become stewards of observability strategy.

Apache Cassandra combines the benefits of major NoSQL databases to support data management needs not covered by traditional RDBMS vendors.

The software you build is only as secure as the code that powers it. Learn how malicious code creeps into your software supply chain.

Generative AI has transformed nearly every industry. How can you leverage GenAI to improve your productivity and efficiency?

Related

  • Introducing Graph Concepts in Java With Eclipse JNoSQL, Part 3: Understanding Janus
  • Introducing Graph Concepts in Java With Eclipse JNoSQL, Part 2: Understanding Neo4j
  • How to Introduce a New API Quickly Using Micronaut
  • Introducing Graph Concepts in Java With Eclipse JNoSQL

Trending

  • Implementing API Design First in .NET for Efficient Development, Testing, and CI/CD
  • Understanding the Shift: Why Companies Are Migrating From MongoDB to Aerospike Database?
  • Software Delivery at Scale: Centralized Jenkins Pipeline for Optimal Efficiency
  • The Perfection Trap: Rethinking Parkinson's Law for Modern Engineering Teams
  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.1K 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

  • Introducing Graph Concepts in Java With Eclipse JNoSQL, Part 3: Understanding Janus
  • Introducing Graph Concepts in Java With Eclipse JNoSQL, Part 2: Understanding Neo4j
  • How to Introduce a New API Quickly Using Micronaut
  • Introducing Graph Concepts in Java With Eclipse JNoSQL

Partner Resources

×

Comments
Oops! Something Went Wrong

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

ABOUT US

  • About DZone
  • Support and feedback
  • Community research
  • Sitemap

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 100
  • Nashville, TN 37211
  • support@dzone.com

Let's be friends:

Likes
There are no likes...yet! 👀
Be the first to like this post!
It looks like you're not logged in.
Sign in to see who liked this post!