11.1.1. Using other criteria to assign components to artifacts

Sometimes the information needed to properly assign a component to an artifact is not part of its architecture filter name. Imagine for example a code generator that generates classes for different functional modules. If all those classes end up in the same package it becomes very hard to assign the generated classes to the right functional modules unless the class name contains some clue. If those generated classes could be properly assigned based on an annotation that would be a far more effective method of assignment.

The following class shows a practical example:

package com.company.generated;

import com.company.FunctionalModule;

@FunctionalModule(name = "Customer")
class E5173
{
    // ....
}
    	

Neither the class name nor the package name contain a clue that this class is associated with the functional module "Customer". Only the annotation gives that information away.

Since Sonargraph 9.7 it is possible to use what we call "attribute retrievers" in name patterns. In our example we would do the assignment as shown below:

artifact Customer
{
    include "JavaHasAnnotationValue: com.company.FunctionalModule: name: Customer"
}
    	

If a search pattern contains colons it is split up into the parts separated by the colons. The first part must be the name of an existing attribute retriever, in our example "JavaHasAnnotationValue". The last part is always a pattern describing what we would like to match and can make use of the wildcards "**", "*" and "?". Everything in between the first part and the last part are parameters for the retriever. Here we tell the retriever that we want to match with the "name" attribute of the annotation "com.company.FunctionalModule". Most retrievers don't need parameters, the example above is therefore already a pretty sophisticated use of attribute retrievers.