Wednesday, April 10, 2013

Detect Architectural Violations Using ConQAT

In the previous blog on how to divide code into component, I have outlined simple steps. One of them is to detect and count violations (invalid calls from one component to another).

The following are simple steps to detect such violations using ConQAT:
  1. Add a new Architecture Analysis. Go to Project>New>Other 
  2. Select ConQat>Architecture Specification: 
  3. A new architecture specification file is opened. Start adding components and assign classes, packages or namespaces to it: 
  4. Following the steps in the next screen shot to (1) Add component (2) Click on the component to open the properties window (3) Press the ‘New inclusion button’ (4) Write a pattern indicating the class or package name: 
  5. Now, we should run the architecture analyzer to verify the dependencies and catch any violations. To do that, we will create a Run configuration. Open “Project>New> Run Config": 
  6. Open “blocklib” you will find a long list of analysis blocks. Select the following: 
    • For .Net code: “ILArchitectureAnalysisChain” 
    • For java code: “JavaArchitectureAnalysis” 
  7. Add the required parameters as in the next screen shot: 
    1. There are some other useful properties like:
      • exclude-dependency: to exclude the specified namespace or class pattern from analysis
      • exclude-file: to exclude the specified file names from analysis
    1. Press the ‘Launch ConQAT analysis’ link 
    2. Go to the architecture specification file and press the ‘Switch Editor Mode’ button as in the screenshot below: 
    3. Browse for the ‘architecture-assessment.xml’ file under the output directory and select it. The result of the architecture analysis is displayed as in the following screenshot: 


    Some Tips and Tricks

    • The ‘orphans view’ lists all classes which are not assigned to any component. Review this list and make sure that it does not include any classes which may impact your analysis
    • You may use the ‘orphans view’ to incrementally build you architecture, as such:
      1. Create all you components and keep them empty
      2. Run the architecture analysis, you will find that all classes are orphans. 
      3. Drag and drop classes or complete packages on to the component
      4. If the package is not part of your code and need to be excluded, right click on the package and ‘Copy pattern’: 
      5. Then, you may exclude this pattern using the exclude-dependency property
    • You may right click the violations and take a decision to allow them, if appropriate:

      No comments: