Checking out JArchitect


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 for

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 there for Linux and Windows. Guess it all looks better on the other platforms.

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

JArchitect Impression

When I looked into the interactive graph (image above) I was not able to click on the source code. 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 which 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 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.

JArchitect CQL

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 which 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 to small. I looked into something bigger, like Apache Struts 2. The report looked much better and much more useful. In my opinion JArchitect aims on 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 (87260, 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 how to improve the framework.

However there are other tools out there which do similar things. If you don’t have a problem with a dated UI and some tricky configurations, you can surely get out more of JArchitect than I did. Personally I have a feeling as this tool would not grow much in me. Mostly because I am not dealing with that 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 options of customization.

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

Tags: #Java #Tools