Skip to content

How to use the Architecture Evaluation Tool for Java Code

Reiner Jung edited this page Mar 21, 2020 · 3 revisions

The architecture evaluation tool (AET) was created to measure the complexity, coupling and cohesion of Java code especially of code generators written in Java. As in such applications libraries, frameworks and glue code is used which may temper with the result, we added the ability to define which classes belong to the code to be measured, defining all else as API. Furthermore, in Java classes are used to express behavior, data or both. The AET allows to mark classes as data classes which are then ignored while computing all metrics.

To better understand how to use the AET, we describe its use with a simple application, the single service JPetStore. Please note JPetStore has almost no cohesion as it is a very simple Web application utilizing struts.

Prerequisites

Installing AET from the Repository

  • Start Eclipse
  • Select Help > *Install New Software ...
  • The install dialog opens
  • Press the Add... button and enter
  • Press Add
  • Select all features you need, for Java these are
    • Core Framework and Metrics
    • Java Project Support
  • Press Next >
  • Follow the instructions and install the extension

Using AET

In this section, we use JPetStore-6 as an example application. In case you want to use this application too, you can find our version at https://github.com/research-iobserve/jpetstore-6.git

Importing JPetStore

  • Clone the example application git clone https://github.com/research-iobserve/jpetstore-6.git
  • Go into the jpetstore-6 directory and switch to the single-jpetstore branch
  • Open Eclipse
  • Select File > Import...*
  • Choose Existing Maven Project from the options
  • Press Next >
  • Specify the correct path to the jpetstore directory
  • Press Finish

Eclipse will now import the project. In case some Eclipse Maven extensions are missing, it will ask to install them. You may choose to do so or might skip this step. Either way some features used in the maven pom.xml will produce errors, as Eclipse does not understand them. In that case you have to select the issue in the ```pom.xml`` file and choose the ignore option in the editor. After that you might have to:

  • Select the jpetstore-6 project, right click on its name and select Maven > Update Project

If everything is setup fine continue with the tutorial.

Setup the AET

We need to define which classes belong to the system and which classes are data classes. Data Classes Create a file in the root directory of the project and call it data-type-pattern.cfg to identify the data classes. The file content contains one pattern per line. For the JPetStore example we enter the pattern org.mybatis.jpetstore.domain.* This is sufficient for this project. However, the AET uses Java regex patterns. Therefore, the correct pattern would be org\.mybatis\.jpetstore\.domain\..*

The given pattern selects all classes in org.mybatis.jpetstore.domain.* to be data classes. They are ignored when calculating the complexity.

System Classes Create a file in the root directory of the project and call it observed-system.cfg to identify system classes. The file content contains one pattern per line. For the JPetStore example we enter the pattern org.mybatis.jpetstore.*

The given pattern selects all classes in org.mybatis.jpetstore.* to be part of the observed system, except classes marked as data classes.

Run AET

  • Right click the jpetstore-6 project and choose Java Analysis. This triggers the analysis.
  • Two views will pop up.
    • The Analysis Log View shows all activities and list all Modules (classes, interfaces), Nodes (methods) and potential warning which may indicate unused code or Java code which is not compatible with the supported versions.
    • The Analysis Result View shows results from the measurements taken by the tool. The first column identifies the project, the second the value identifier and the last the value. The following values are returned
      • size of the observed system (that is the number of classes) 19
      • lines of code 1014
      • cyclomatic complexity X : this line can appear multiple times. The X indicates the cyclomatic complexity and the value in behind it the number of occurances of methods with that complexity.
      • number of modules (includes system classes and API classes) 52
      • number of nodes (for Java this are methods) 189
      • number of edges (these are method calls) 203
      • hypergraph size 1206.05
      • hypergraph complexity 827.73
      • inter module coupling 642.16 (complexity of the hypergraph only including inter module edges)
      • graph cohesion 0.0022 (where 1 would indicate a fully interconnected graph)
    • The Analysis Result View provides three additional functions in the upper right corner of the view
      • Data export allows to export the table as CSV
      • Graph export allows to export the graph as xmi
      • Clear result view

There is also a graph view option, but that seems to be missing from the repository at the moment.