Skip to content

How to Detect Cross Component Clones

Teamscale's clone detection allows detecting so-called cross component clones. A component in this context refers to a component as per Teamscale's architecture conformance model and can essentially be an arbitrary subset of the code within a Teamscale project. This feature enables distinguishing between clones with clone relationships across the boundaries of certain code areas (cross component clones) and those that only have clone relationships within a code area (intra component clones). An example would be a situation where the code of a component (or project) was forked from another one, and you are interested in the commonalities between the two components.

TIP

A clone is a cross component clones as soon as any of its siblings is located in another component as per the cross component clone detection architecture. A clone is an intra component clone if all of its siblings are located in the same component as per the cross component clone architecture.

For cross component clone detection, Teamscale provides two dedicated finding types: Cross Component Clones and Intra Component Clones. In addition the dedicated metrics Cross Component Clone Coverage and Intra Component Clone Coverage are provided. To enable cross component clone detection, activate any of these options in the Cloning analysis group of the project's analysis profile:

Analysis Profile Options

Here, you can also specify the name of the architecture file which specifies the components to use for cross component clone detection, or you can keep the provided default. Please note that providing an architecture model is mandatory for cross component clone detection, i.e. an architecture model with the name configured in the cross component clone detection section of the analysis profile must exist in the project.

TIP

When using cross component clone detection, the normal clone detection cannot be used at the same time. Thus, when enabling any of the cross component options, the Clones finding option has to be disabled. The Clone Coverage metric can still be used and will refer to the clone coverage of all clones (both cross and intra component clones).

Cross Component Clone FindingsCross Component Clone Coverage

TIP

The architecture used for cross component clone detection has to be a file-based architecture. It is recommended to set the Finding Creation option to None for this architecture and thus exclusively use it for cross component clone detection.

Cross component clones will be detected as soon as the configured architecture model exists in the project history. If you want to analyse cross component clones for the history of a project, the architecture model has to be added in time-travel model to the project's commit history in Teamscale.

Please note that both the cross component findings, and the cross component clone coverage are sensitive regarding changes to the architecture model used for the detection. Thus, changing the architecture model may result in findings being removed from one finding type (Clones or Cross Component Clones) and added to the other. Similarly, both metrics can change. Note again that this will only affect the findings/metrics from the point in time on when the change to the architecture takes place. If you want to alter the component definition in the project history, the architecture needs to be edited in time-travel mode.