Measures

The Measure element defines the semantics of a single measure. From a technical standpoint, a measure is merely a mapping between the information provided by the Data Provider and known Squore elements.

Base Measures only define the measure name and identifier, whereas Derived Measures define how they are computed from other measures. A Measure without computation is a base measure. The following two examples show how the SLOC (Source Lines Of Code) base measure and the COMR (Comment Rate) derived measure are defined:

<Measure 
measureId="SLOC" 
targetArtefactTypes="APPLICATION;FILE" 
defaultValue="1" />
      
<Measure measureId="COMR" defaultValue="0">
<Computation stored="true" 
    targetArtefactTypes=
       "APPLICATION;FOLDER;FILE;FUNCTION;CLASS;PROGRAM" 
    result="(CLOC+MLOC)*100/(SLOC+CLOC)" />
</Measure>

The attributes allowed for the Measure element are as follows:

The attributes allowed for the Computation element are as follows:

The measure defined is then used with its identifier, prefixed with B. for base measures, or prefixed with D. for derived measures. The following example shows the use of a derived measure for a computation:

<Computation 
    targetArtefactTypes="APPLICATION;FOLDER;FILE;CLASS;FUNCTION" 
    result="(D.MET_OKR+D.RULE_OKR)/2" />

Tip: Inheritance

Analysis models support inheritance and overriding of metrics according to the following rules:

  • If a metric is defined twice for a type, the first definition takes priority for this artefact type. An INFO message is displayed in the Validator to inform you that a definition is overriden by another one.

  • A metric definition for a specific type overrides a metric definition for a more generic type (typically an alias).

As a result, the following definitions are allowed in your Bundle.xml:

  • Specifying a different computation for one sub-type

    <ArtefactType id="MODULES" heirs="FUNCTION" />
    <ArtefactType id="FUNCTION" heirs="C_MODULES;PHP_MODULES;JAVA_MODULES" />
    <Measure measureId="VG" defaultValue="1">
      <Computation targetArtefactTypes="MODULES" result="CCN+TERN+OREL+ANTH+CABL-(CASE+DEF)" />
      <Computation targetArtefactTypes="PHP_MODULES" result="CCN+TERN+OREL+ANTH" />
    </Measure>
  • Overriding a computation imported from another file by specifying it before the file import

    <?xml version="1.0" encoding="UTF-8"?>
    <Bundle xmlns:xi="http://www.w3.org/2001/XInclude">
    (...)
    <Measure measureId="COMR" defaultValue="0">
      <Computation targetArtefactTypes="CODE" result="IF(ELOC+CLOC=0,-1,(CLOC+MLOC)/(ELOC+CLOC))" />
    </Measure>
    <xi:include href="../../Shared/basic_definitions/comr.xml" />


[1] See the section called “Descriptions” for more information about unique identifiers.