Sunday 28 December 2014

Static Code Analyzers - JArchitect - Why is it distinctive static code analysis tool for Java?

I hope, you have already read "Preface" of my static code analyzers series.

Regardless you are developer or manager or architect, how meticulous are you about the quality of the software architecture and code you deliver?

In this post, I explained - while there are already free / open-source static code analysis tools available (e.g.  Checkstyle, PMD, FindBugs, CodePro Analytix, SonarQube...), what differentiating features are offered by JArchitect being a commercial tool! How JArchitect is beneficial to all developers, managers and architects! Moreover, how it can facilitate architecture evaluation exercise of existing or legacy java software for refactoring / re-engineering / migration / modernization.

Straight from the horse's mouth

JArchitect manages complex code base and achieves high Code Quality. With JArchitect, software quality can be measured using Code Metrics, visualized using Graphs and Treemaps, and enforced using standard and custom Rules. In a nutshell, improve your Java Code quality with JArchitect 4
  • Customize your own rules through CQLinq
  • Powerful way to combine many Java tools
  • Meaningful reports about your code base

My Personal Feedback

  • When to use and key features?
    • Control Code Quality - Architects can setup JArchitect analysis as part of build and CI process, i.e. integrate with Maven, Gradle, Jenkins, etc. Managers and QAs can keep their eyes on code analysis reports (e.g. sample report) as well as customized trend monitoring views to ensure health of software code quality.
    • CQLinq - I didn't find this kind of awesome feature in any  other static code analysis tool. This enables developers and architects to write queries on java code dynamically (e.g. JArchitect can answer the queries like - what are top 5 complex methods?, is the code layered correctly?, which method has been refactored in last release?). If you know SQL, you can easily learn CQLinq. Otherwise don't worry, even you can use GUI and rich code search facility of JArchitect to form such CQLinq queries quickly. I have become a fan of CQLinq feature.
    • Explore existing architecture - The generated diagrams by JArchitect are immensely interactive. It is so easy to drill down the diagrams by few clicks or highlight areas of interest in the diagrams by changing CQLinq (e.g. highlight top 10 methods by cyclomatic complexity in matric view diagram; drill down dependency graphs or DSM to analyze layered code, high cohesion and low coupling, dependency cycles...).
    • Compare builds and code difference - Let JArchitect tell you that what was changed compare to previous analysis or between two code analysis. For example - methods added or changed, packages added or changed, added or removed third party libraries...
    • The above-mentioned features are extremely useful for activities such as code review, impact analysis for refactoring, etc. Refer more features of JArchitect.
  • Initial learning curve and ease-of-use?
    • It is easy to setup and get started. Depending on experience level, you should be able to adopt  it (e.g. interpret code analysis report/diagrams; play with its CQLinq to query java code, etc.) in less than a week by referring to documentation. I found that JArchitect  GUI is highly neat and interactive.
  • Setup requirements?
    • Download JArchitect compressed installation for supported OS (i.e. Windows, Linux, Mac), unzip it, put license file in root folder of JArchitect and just run the startup file (e.g. VisualJArchitect.exe for Windows). That's it. For further detail, refer system requirements.
  • Cost (Free or Commercial)?
    • Free fully 14-day trial is available, then need to purchase. Refer pricing.
    • Open source licenses are available free to non-commercial open source software development projects.
  • Limitations/ Challenges?
    • JArchitect does not have IDE plugin (e.g. Eclipse/Intellij). Alternatively, it provides the easy way of associating IDE workspace / project (Eclipse, NetBeans and Intellij) in standalone JArchitect GUI tool  for the code analysis and as a source files editor tool. I could accustom myself with this approach easily, but some developers may find it challenging to use two tools (IDE + JArchitect) simultaneously during development.
    • Code coverage analysis is not inherent while executing code analysis in JArchitect. That means, we need to firstly execute cobertura separately on project codebase and then import its resulting xml file into the JArchitect. This approach is not favorable from usability point of view. I would say that code coverage should be default integrated part of the code analysis process of JArchitect (may be with a configuration option of  enable or disable code coverage).

Practical Shot

For JArchitect practical demo, I used Spring Petclinicsample application. Let's assume, you need to deal with this existing unknown codebase for requirements such as assess architecture for migration or modernization, review code quality, impact analysis for refactoring, etc. Following are some highlights of being efficient by using JArchitect...

Note: To enlarge below screenshot images --- Right click the image - Open in New Window - Zoom it.

  • Perform code analysis in JArchitect - First of all, create new project in JArchitect and just associate appropriate folders of your java pplication codebase. You may customize report format too. Finally, run the analysis. The best part of the tool is that source files and byte code are not mandatory for the analysis, rather it supports inputs such as application build files (jar, war, ear), eclipse workspace, IDE projects (Intellij, NetBeans, Eclipse), Maven (pom.xml), etc. For more detail, refer getting started and analysis input.

  • Code quality status and accustom with CQLinq - The red circle (bottom-right side) tells that some critical rules are violated. Let's see the dashboard. Firstly review what rules are violated in "Queries and Rules Explorer" (below dashboard). On top of providing default rule groups, the tool gives you complete control to  customize existing or add new rules based on the project need in "Queries and Rules Explorer". Next explore associated code path for each type of rule in "Queries and Rules Edit" section (left side). Here, even you can update CQLinq query and see the updated result almost immediately. Even you can integrate custom plugin (i.e. other static code analysis tools) in JArchitect to use CQLinq on those. For more detail, refer CQLinq syntax and violating code rules. On a separate note, let me make you aware that you need to configure your choice of editor tool in JArchitect for navigating to java class source from JArchitect, because JArchitect is not an IDE.

  • Dependency analysis - Now understand code structure patterns of application using dependency graphs and DSM (dependency structure matrix). These diagrams offer to explore the codebase in interactive way and are highly useful to review design of application or to perform the impact analysis for code refactoring.

  • Code visualization metrics views - Another interactive diagram, which offers to highlight some areas of code for selected metric parameters. This is one of the distinctive feature of JArchitect. For example, it is so easy to see what are top 10 methods in petclinic application code by "Cyclomatic Complexity (CC)". Even you can hover to see more information of given rectangle (e.g. invoke method in below screenshot) or right click it to navigate to other related things (e.g. open source code in IDE, view on dependency matrix, etc.)… For more detail, refer visualizing code metrics with treemap and code metrics definitions.

  • Track code differences between two build analysis - With JArchitect, it is so easy to focus what things were changed in recent build. Just compare latest build analysis with the previous one, and with just few clicks realize the differences in the codebase. Firstly, I took few months old code from github and performed code analysis in JArchitect (refer older build on 21 Dec). Next, I took recent code from github and performed code analysis again (refer new build on 28 Dec). Then, I did build comparison between older and newer builds. Finally, I could see many code differences by just few clicks. For more detail, refer advance code difference in JArchitect.

My Final Thoughts
  • I endorse JArchitect for being a promising tool for Java architects and developers --- because it can greatly improve efficiency in terms of delivering high quality software components in less time. 
  • Should you try JArchitect? --- If you have an opportunity, I strongly suggest to try 14-day JArchitect trial. Certainly, you will be able to experience superior approach to work on java projects using its some unique features.
  • Should you buy JArchitect? --- Well, this is highly subjective to individual project need and budget. If project has longer lifespan goals and is evolving continuously, then you must consider static code analysis tool to control code quality (preferably as part of Continuous Integration). You can evaluate JArchitect and available open source static analysis tools (e.g. Checkstyle, PMD, FindBugs, CodePro Analytix, SonarQube, etc.) for your targeted criteria, and you can either procure JArchitect or go with open source static code analysis tools. According to my experience with various static code analysis tools, JArchitect offers excellent GUI and unique features like CQLinq, Metrics views, etc. Even on larger codebase, it performs code analysis very fast compare to few other tools I have tried. The tool is very  much stable, because it has never hung (I tried in Windows OS) or thrown weird errors while using it. Obviously, it has to offer special things being a commercial tool.  
  • In a nutshell, JArchitect is an distinctive static analysis tool for Java. Moreover, it also supports each language using the JVM and generating the byte code. So JArchitect can be also useful, if application is developed using polyglot programming* i.e. multiple JVM based languages like Java, Groovy, Clojure, Scala, etc. (* I have not tried it yet on other than Java language).

Disclaimer
I don't aim to exploit code of any open source project or sample application, while I share my evaluation feedback of given tool on selected publicly available code. Also I am not biased to particular free or commercial tools, rather my objective is about sharing my own experience on set of tools.

Also Refer

2 comments:

  1. Nice post... I am using open source static code analysis tools and this tool is beneficial to all developers, managers and architects. Thanks for sharing

    ReplyDelete