Advanced Code Diff with JArchitect

Advanced Code Diff.


This document explains how to use the JArchitect build comparison features, in the context of the interactive UI.
The document Reporting Code Diff explains how to use the JArchitect build comparison features, in the context of reporting.


Introduction

Code evolution and code maintenance are some of the most prominent characteristics of software engineering.
JArchitect comes with some advanced code evolution and code diff features since mid 2009. One of the coolest results of JArchitect is that now, developer benefit from several fine-grained code diff features, one click away from their natural developing environment. Let‘s expose 3 typical code diff scenarios.

Code Diff from within VisualJArchitect

So for example one can right-click a project in the Code Browser and ask for Select Methods (of the project) where Code was Changed.



This will result in a CQLinq query generated that Select Methods (of the project) where Code was Changed. Naturally, for each method listed, one can jump straight to source code declaration or ask for diff.




Go to top


Code Change Review through Search Panel

The Search Change Panel is actually just a CQLinq query generator related to Code change. For example, in the screenshot below, we can see that asking for Method + Change + Code was Changed or was Added generates the CQLinq query:

from m in Application.Methods 
where m.CodeWasChanged() || m.WasAdded() 
select new { m, m.NbLinesOfCode }


The result shown is ideal to do efficient Code Change Review: not only all code changes are nicely organized at a glance, but for each methods refactored, the developer is just one click away to observe diff in source files.



The Search Change Panel’s options offers various possibilities to explore diff, including searching for code elements where code and only code (not comment) was changed or where comment and only comment was changed, where visibility was changed, where was added or removed etc….

A bonus option is to search diff in tier code, like asking for which library types is not used anymore for example.

Typically, developers like to write tests for testing automatically refactored and new code. Another cool bonus option is to search for diff coupled with code coverage by tests ratio, like asking for methods where code was changed (i.e refactored methods) and where it is not actually properly covered by tests.

Go to top


Defining the Baseline for Comparison

Earlier in the post we introduced the concept of Baseline for Comparison. This represents the previous snapshot version of the code base against which, the comparison is done. Typically, the Baseline for Comparison represents the latest version of the code in production.

The Baseline for Comparison can be specified through the menu: Diff > Define The Two Snapshots to Diff > Define the project’s Baseline for Comparison. The dialog below appears and let chooses through different options to define the baseline. The Baseline for Comparison option is then persisted in the JArchitect project file.



Finally, any diff tools can be plugged through the menu Diff > Source Files Compare Tools.

Go to top