Performance Zone is brought to you in partnership with:

Christian is a dedicated Open Source developer and Entrepreneur. Currently he works a lot for the Apache Software Foundation. Besides he loves efficient working and regularly shares his thoughts on his blog, mostly tagged with "Zen Programming". Christian is a DZone MVB and is not an employee of DZone and has posted 13 posts at DZone. You can read more from them at their website. View Full User Profile

Checking out JArchitect

08.06.2013
| 5567 views |
  • submit to reddit

Recently I got a free license (Thanks!) from Dane for JArchitect. It’s a tool for analyzing your Java code. It also helps for improving your code quality. I was curious when I got the offer.

First impression? Wow, it looks dated. On my Mac it’s starting X11. I definitely miss my Mac experience.

Please note: JArchitect is not only available for Mac: it’s also for Linux and Windows. Guess it all looks better on the other platforms.

I got the idea to analyze Apache log4j 2 with it. It took me a few minutes to find out how to include source code into the JArchitect project.

Jarchitect Interactive Graph

When I looked into the interactive graph (image above) I was not able to click on the source code. I don’t know why, because I started my analysis on base of my source code. Also the interactive graph is not very readable and I had to play a lot with zoom.

The HTML output was better. I recognized some information, like dependencies, wasn’t available. Chances are I configured something wrong.

You can download the full report here.

I am not sure if I like all the tips that were like “don’t use singleton” or “avoid empty interfaces” (Marker interfaces?).

In my report were a lot of these cryptic outputs:

Don't assign static fields from instance methods
// Don't assign static fields from instance methods
// Assigning static fields from instance methods leads to
// poorly maintainable and non thread-safe code.
// It is advised to assign static fields inline or from class constructor.
warnif count > 0
from f in Application.Fields where
f.IsStatic &&
!f.IsLiteral &&
!f.IsInitOnly &&
!f.IsGeneratedByCompiler &&
// Contract API define such a insideContractEvaluation static field
f.Name != "insideContractEvaluation"
let assignedBy = f.MethodsAssigningMe.Where(m => !m.IsStatic)
where assignedBy .Count() > 0
select new { f, assignedBy }
No fields matched

I soon realized these are the rules which were applied to my report. JArchitect gives you a lot of flexibility to work with such rules because you are able to highly customize the tool. The rule above is something JArchitect provides under the name “Code Query Linq“, CQLinq in short. You can create your own CQLinq which reminds me very much on SQL. You could say, it’s SQL for your code. In combination with JArchitect’s editor you have a powerful tool to select specific parts of your applications.

CQL JArchitect

You could for example select the 10 most complex methods or the most complex methods with lack of documentation. Actually this is really powerful and an impressive feature which can help you to analyze your code from a perspective which you will not get from the most maven based tools out there. In fact this is one of the killer features of JArchitect that I almost missed.

Anyway I could not find huge value for analyzing log4j2 with JArchitect. Most likely this is due to misconfiguration, but the project is also too small. I looked into something bigger, like Apache Struts 2. The report looked much better and much more useful. In my opinion JArchitect aims for big projects (as the name suggests).

Here is the output for Struts 2.

To be honest, even the HTML output looks a bit dated. On the other hand it is possible to get out some useful information. This information could be retrieved with other, Maven-based tools too. Except if you want to include your own CQLinq rules, of course.

If you use a tool like JArchitect you definitely need to invest a certain amount of time to learn it properly. It is made for analyzing big software projects and offers a lot with CQLinq, but this power needs its time to explore.

The JArchitect tips I found for Struts 2 are more useful. Besides usual metrics like lines of code (87,260, yay!) and dependency analysis I got tons of alerts. Like, for example, “Methods are too complex” or that we have 481 “potentially dead fields” in Struts 2.

I am going to work a bit more with JArchitect in conjunction with Struts 2. I am not sure if I understand Struts 2 better with this tool, but it gave me some inspiration for how to improve the framework.

However, there are other tools out there that do similar things. If you don’t have a problem with a dated UI and some tricky configurations, you can surely get more out from JArchitect than I did. Personally I have the feeling that this tool will not grown on me very much--mostly because I am not dealing with huge architectures these days. If you have to oversee big software projects with a lot of dependencies you might benefit from the advanced dependency matrix or the customization options.

JArchitect has a trial version available on its website. If you can invest some time into actually learn about it and work on big Java architectures you might find a helpful (but ugly) companion.

Published at DZone with permission of Christian Grobmeier, author and DZone MVB. (source)

(Note: Opinions expressed in this article and its replies are the opinions of their respective authors and not those of DZone, Inc.)